forked from Simnation/Main
ed
This commit is contained in:
parent
2834b543f4
commit
6c5c142a0d
3 changed files with 393 additions and 146 deletions
|
@ -1,9 +1,13 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- List of prop models that should be targetable as shredders
|
||||
-- List of prop models that should be targetable as immediate shredders
|
||||
local shredderPropModels = {
|
||||
'p_secret_weapon_02',
|
||||
'prop_bin_08a',
|
||||
'prop_bin_08a'
|
||||
}
|
||||
|
||||
-- List of prop models that should be targetable as trash bins with delayed deletion
|
||||
local trashBinPropModels = {
|
||||
'prop_bin_01a',
|
||||
'prop_bin_03a',
|
||||
'prop_bin_04a',
|
||||
|
@ -15,112 +19,147 @@ local shredderPropModels = {
|
|||
}
|
||||
|
||||
-- Variable to store the current entity being interacted with
|
||||
local currentShredderEntity = nil
|
||||
local currentEntity = nil
|
||||
local currentType = nil
|
||||
|
||||
-- Add QB-Target to all matching props in the world
|
||||
Citizen.CreateThread(function()
|
||||
-- Add target to all existing props
|
||||
for _, model in ipairs(shredderPropModels) do
|
||||
-- Add QB-Target to this model
|
||||
exports['qb-target']:AddTargetModel(model, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "shredder:openInventory",
|
||||
icon = "fas fa-dumpster",
|
||||
label = "Müllschredder öffnen",
|
||||
action = function(entity)
|
||||
currentShredderEntity = entity
|
||||
TriggerEvent('shredder:openInventory')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
},
|
||||
{
|
||||
type = "client",
|
||||
event = "shredder:openMenu",
|
||||
icon = "fas fa-fire",
|
||||
label = "Items vernichten",
|
||||
action = function(entity)
|
||||
currentShredderEntity = entity
|
||||
TriggerEvent('shredder:openMenu')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
-- Add target to shredder props
|
||||
exports['qb-target']:AddTargetModel(shredderPropModels, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "disposal:openInventory",
|
||||
icon = "fas fa-dumpster",
|
||||
label = "Müllschredder öffnen",
|
||||
action = function(entity)
|
||||
currentEntity = entity
|
||||
currentType = "shredder"
|
||||
TriggerEvent('disposal:openInventory')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
end
|
||||
{
|
||||
type = "client",
|
||||
event = "disposal:openMenu",
|
||||
icon = "fas fa-fire",
|
||||
label = "Items vernichten",
|
||||
action = function(entity)
|
||||
currentEntity = entity
|
||||
currentType = "shredder"
|
||||
TriggerEvent('disposal:openMenu')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
|
||||
print("^2[SHREDDER]^7 Added QB-Target to " .. #shredderPropModels .. " shredder prop models")
|
||||
-- Add target to trash bin props
|
||||
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "disposal:openInventory",
|
||||
icon = "fas fa-trash",
|
||||
label = "Mülltonne öffnen",
|
||||
action = function(entity)
|
||||
currentEntity = entity
|
||||
currentType = "trash"
|
||||
TriggerEvent('disposal:openInventory')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
},
|
||||
{
|
||||
type = "client",
|
||||
event = "disposal:openMenu",
|
||||
icon = "fas fa-clock",
|
||||
label = "Müll entsorgen",
|
||||
action = function(entity)
|
||||
currentEntity = entity
|
||||
currentType = "trash"
|
||||
TriggerEvent('disposal:openMenu')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
|
||||
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models")
|
||||
end)
|
||||
|
||||
-- Function to get shredder ID from entity
|
||||
function GetShredderIDFromEntity(entity)
|
||||
-- Function to get container ID from entity
|
||||
function GetContainerIDFromEntity(entity, type)
|
||||
if not entity or not DoesEntityExist(entity) then return nil end
|
||||
|
||||
local model = GetEntityModel(entity)
|
||||
local entityCoords = GetEntityCoords(entity)
|
||||
return "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
||||
return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
||||
end
|
||||
|
||||
-- Schredder Inventar öffnen
|
||||
RegisterNetEvent('shredder:openInventory', function()
|
||||
-- Open container inventory
|
||||
RegisterNetEvent('disposal:openInventory', function()
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
if not currentShredderEntity or not DoesEntityExist(currentShredderEntity) then
|
||||
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||
lib.notify({
|
||||
title = 'Müllschredder',
|
||||
description = 'Kein Schredder gefunden!',
|
||||
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
||||
type = 'error'
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
-- Get shredder ID
|
||||
local shredderID = GetShredderIDFromEntity(currentShredderEntity)
|
||||
if not shredderID then return end
|
||||
-- Get container ID
|
||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
||||
if not containerID then return end
|
||||
|
||||
-- Open inventory with this unique ID
|
||||
TriggerServerEvent('shredder:server:openInventory', shredderID)
|
||||
TriggerServerEvent('disposal:server:openInventory', containerID, currentType)
|
||||
end)
|
||||
|
||||
-- Vernichtungsmenü öffnen
|
||||
RegisterNetEvent('shredder:openMenu', function()
|
||||
-- Open disposal menu
|
||||
RegisterNetEvent('disposal:openMenu', function()
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
if not currentShredderEntity or not DoesEntityExist(currentShredderEntity) then
|
||||
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||
lib.notify({
|
||||
title = 'Müllschredder',
|
||||
description = 'Kein Schredder gefunden!',
|
||||
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
||||
type = 'error'
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
-- Get shredder ID
|
||||
local shredderID = GetShredderIDFromEntity(currentShredderEntity)
|
||||
if not shredderID then return end
|
||||
-- Get container ID
|
||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
||||
if not containerID then return end
|
||||
|
||||
-- Get items in this shredder
|
||||
TriggerServerEvent('shredder:server:getItems', shredderID)
|
||||
-- Get items in this container
|
||||
TriggerServerEvent('disposal:server:getItems', containerID, currentType)
|
||||
end)
|
||||
|
||||
-- Menü mit Items anzeigen
|
||||
RegisterNetEvent('shredder:client:showMenu', function(items, shredderID)
|
||||
-- Show menu with items
|
||||
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining)
|
||||
-- Make sure items is a table
|
||||
items = items or {}
|
||||
|
||||
-- Check if items is empty
|
||||
if next(items) == nil then
|
||||
lib.notify({
|
||||
title = 'Müllschredder',
|
||||
description = 'Der Schredder ist leer!',
|
||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
||||
type = 'error'
|
||||
})
|
||||
return
|
||||
|
@ -128,23 +167,40 @@ RegisterNetEvent('shredder:client:showMenu', function(items, shredderID)
|
|||
|
||||
local menuOptions = {}
|
||||
|
||||
-- Alle Items vernichten Option
|
||||
-- All items action option
|
||||
local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN"
|
||||
local actionDesc = type == "shredder"
|
||||
and 'Vernichtet alle Items im Schredder permanent!'
|
||||
or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!'
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '🔥 ALLE ITEMS VERNICHTEN',
|
||||
description = 'Vernichtet alle Items im Schredder permanent!',
|
||||
icon = 'fire',
|
||||
title = '🔥 ' .. actionText,
|
||||
description = actionDesc,
|
||||
icon = type == "shredder" and 'fire' or 'trash',
|
||||
onSelect = function()
|
||||
confirmDestroyAll(shredderID)
|
||||
confirmDestroyAll(containerID, type)
|
||||
end
|
||||
})
|
||||
|
||||
-- If it's a trash bin with scheduled deletion, show the time remaining
|
||||
if type == "trash" and timeRemaining then
|
||||
local minutes = math.floor(timeRemaining / 60)
|
||||
local seconds = timeRemaining % 60
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '⏱️ Automatische Leerung',
|
||||
description = string.format('In %d Minuten und %d Sekunden', minutes, seconds),
|
||||
disabled = true
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '─────────────────',
|
||||
description = 'Einzelne Items:',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
-- Einzelne Items zum Menü hinzufügen
|
||||
-- Add individual items to menu
|
||||
local hasItems = false
|
||||
for slot, item in pairs(items) do
|
||||
if item and item.amount and item.amount > 0 then
|
||||
|
@ -154,7 +210,7 @@ RegisterNetEvent('shredder:client:showMenu', function(items, shredderID)
|
|||
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
|
||||
icon = 'trash',
|
||||
onSelect = function()
|
||||
confirmDestroySingle(item.name, item.amount, slot, shredderID)
|
||||
confirmDestroySingle(item.name, item.amount, slot, containerID, type)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
@ -162,34 +218,39 @@ RegisterNetEvent('shredder:client:showMenu', function(items, shredderID)
|
|||
|
||||
if not hasItems then
|
||||
lib.notify({
|
||||
title = 'Müllschredder',
|
||||
description = 'Der Schredder ist leer!',
|
||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
||||
type = 'error'
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
lib.registerContext({
|
||||
id = 'shredder_menu',
|
||||
title = '🗑️ Müllschredder Verwaltung',
|
||||
id = 'disposal_menu',
|
||||
title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung',
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('shredder_menu')
|
||||
lib.showContext('disposal_menu')
|
||||
end)
|
||||
|
||||
-- Einzelnes Item vernichten bestätigen
|
||||
function confirmDestroySingle(itemName, amount, slot, shredderID)
|
||||
-- Confirm single item disposal
|
||||
function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
||||
local actionText = type == "shredder" and "vernichten" or "entsorgen"
|
||||
local actionDesc = type == "shredder"
|
||||
and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!')
|
||||
or (itemName .. ' (' .. amount .. 'x) wird entsorgt und nach Zeit gelöscht!')
|
||||
|
||||
lib.registerContext({
|
||||
id = 'shred_single_confirm',
|
||||
title = '⚠️ Item vernichten?',
|
||||
id = 'dispose_single_confirm',
|
||||
title = '⚠️ Item ' .. actionText .. '?',
|
||||
options = {
|
||||
{
|
||||
title = '🔥 Ja, vernichten',
|
||||
description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
|
||||
title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen',
|
||||
description = actionDesc,
|
||||
icon = 'check',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('shredder:server:destroySingle', itemName, amount, slot, shredderID)
|
||||
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -197,27 +258,32 @@ function confirmDestroySingle(itemName, amount, slot, shredderID)
|
|||
description = 'Zurück zum Hauptmenü',
|
||||
icon = 'times',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('shredder:server:getItems', shredderID)
|
||||
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
lib.showContext('shred_single_confirm')
|
||||
lib.showContext('dispose_single_confirm')
|
||||
end
|
||||
|
||||
-- Alle Items vernichten bestätigen
|
||||
function confirmDestroyAll(shredderID)
|
||||
-- Confirm all items disposal
|
||||
function confirmDestroyAll(containerID, type)
|
||||
local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN"
|
||||
local actionDesc = type == "shredder"
|
||||
and 'ALLE Items im Schredder werden permanent gelöscht!'
|
||||
or 'ALLE Items in der Mülltonne werden nach Zeit automatisch gelöscht!'
|
||||
|
||||
lib.registerContext({
|
||||
id = 'shred_all_confirm',
|
||||
id = 'dispose_all_confirm',
|
||||
title = '⚠️ WARNUNG ⚠️',
|
||||
options = {
|
||||
{
|
||||
title = '🔥 JA, ALLES VERNICHTEN',
|
||||
description = 'ALLE Items im Schredder werden permanent gelöscht!',
|
||||
icon = 'fire',
|
||||
title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN',
|
||||
description = actionDesc,
|
||||
icon = type == "shredder" and 'fire' or 'trash',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('shredder:server:destroyAll', shredderID)
|
||||
TriggerServerEvent('disposal:server:disposeAll', containerID, type)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -225,25 +291,25 @@ function confirmDestroyAll(shredderID)
|
|||
description = 'Zurück zum Hauptmenü',
|
||||
icon = 'times',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('shredder:server:getItems', shredderID)
|
||||
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
||||
end
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
lib.showContext('shred_all_confirm')
|
||||
lib.showContext('dispose_all_confirm')
|
||||
end
|
||||
|
||||
-- Erfolgs-Notification mit Effekt
|
||||
RegisterNetEvent('shredder:client:itemDestroyed', function(message)
|
||||
-- Success notification with effect
|
||||
RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||
lib.notify({
|
||||
title = 'Müllschredder',
|
||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||
description = message,
|
||||
type = 'success',
|
||||
duration = 4000
|
||||
})
|
||||
|
||||
-- Partikel-Effekt
|
||||
-- Particle effect
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
|
@ -253,8 +319,15 @@ RegisterNetEvent('shredder:client:itemDestroyed', function(message)
|
|||
end
|
||||
|
||||
UseParticleFxAssetNextCall("core")
|
||||
StartParticleFxNonLoopedAtCoord("ent_sht_steam", coords.x, coords.y, coords.z + 1.0, 0.0, 0.0, 0.0, 2.0, false, false, false)
|
||||
|
||||
-- Sound Effect
|
||||
PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
|
||||
-- Different effects for shredder vs trash
|
||||
if type == "shredder" then
|
||||
-- More intense effect for shredder
|
||||
StartParticleFxNonLoopedAtCoord("ent_sht_flame", coords.x, coords.y, coords.z + 1.0, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
||||
PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
|
||||
else
|
||||
-- Subtle effect for trash
|
||||
StartParticleFxNonLoopedAtCoord("ent_sht_dust", coords.x, coords.y, coords.z + 0.5, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
||||
PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue