diff --git a/resources/[inventory]/nordi_schredder/client.lua b/resources/[inventory]/nordi_schredder/client.lua index ee4025ce8..bae907225 100644 --- a/resources/[inventory]/nordi_schredder/client.lua +++ b/resources/[inventory]/nordi_schredder/client.lua @@ -25,292 +25,58 @@ local currentType = nil -- QB-Target zu allen passenden Props in der Welt hinzufügen Citizen.CreateThread(function() -- Für sofortige Schredder - 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, + for _, model in ipairs(shredderPropModels) do + exports['qb-target']:AddTargetModel(model, { + options = { + { + num = 1, + type = "client", + event = "disposal:openInventory", + icon = "fas fa-dumpster", + label = "Müllschredder öffnen", + action = function(entity) + currentEntity = entity + currentType = "shredder" + TriggerEvent('disposal:openInventory') + end, + }, + { + num = 2, + type = "client", + event = "disposal:openMenu", + icon = "fas fa-fire", + label = "Items vernichten", + action = function(entity) + currentEntity = entity + currentType = "shredder" + TriggerEvent('disposal:openMenu') + 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 - }) + distance = 2.0 + }) + end -- Für zeitverzögerte Mülltonnen - nur eine Option zum Öffnen - 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, - } - }, - distance = 2.0 - }) + for _, model in ipairs(trashBinPropModels) do + exports['qb-target']:AddTargetModel(model, { + options = { + { + num = 1, + type = "client", + event = "disposal:openInventory", + icon = "fas fa-trash", + label = "Mülltonne öffnen", + action = function(entity) + currentEntity = entity + currentType = "trash" + TriggerEvent('disposal:openInventory') + end, + } + }, + distance = 2.0 + }) + end print("^2[DISPOSAL]^7 QB-Target zu " .. #shredderPropModels .. " Schredder-Modellen und " .. #trashBinPropModels .. " Mülltonnen-Modellen hinzugefügt") end) - --- Funktion zum Abrufen der Container-ID aus der Entität -function GetContainerIDFromEntity(entity, type) - if not entity or not DoesEntityExist(entity) then return nil end - - local model = GetEntityModel(entity) - local entityCoords = GetEntityCoords(entity) - return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z) -end - --- Container-Inventar öffnen -RegisterNetEvent('disposal:openInventory', function() - local playerPed = PlayerPedId() - local coords = GetEntityCoords(playerPed) - - if not currentEntity or not DoesEntityExist(currentEntity) then - lib.notify({ - 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 - - -- Container-ID abrufen - local containerID = GetContainerIDFromEntity(currentEntity, currentType) - if not containerID then return end - - -- Inventar mit dieser eindeutigen ID öffnen - TriggerServerEvent('disposal:server:openInventory', containerID, currentType) -end) - --- Vernichtungsmenü öffnen (nur für Schredder) -RegisterNetEvent('disposal:openMenu', function() - local playerPed = PlayerPedId() - local coords = GetEntityCoords(playerPed) - - if not currentEntity or not DoesEntityExist(currentEntity) or currentType ~= "shredder" then - lib.notify({ - title = 'Müllschredder', - description = 'Kein Schredder gefunden!', - type = 'error' - }) - return - end - - -- Container-ID abrufen - local containerID = GetContainerIDFromEntity(currentEntity, currentType) - if not containerID then return end - - -- Items in diesem Container abrufen - TriggerServerEvent('disposal:server:getItems', containerID, currentType) -end) - --- Menü mit Items anzeigen (nur für Schredder) -RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining) - -- Nur für Schredder fortfahren - if type ~= "shredder" then return end - - -- Sicherstellen, dass items eine Tabelle ist - items = items or {} - - -- Prüfen, ob items leer ist - if next(items) == nil then - lib.notify({ - title = 'Müllschredder', - description = 'Der Schredder ist leer!', - type = 'error' - }) - return - end - - local menuOptions = {} - - -- Alle Items vernichten Option - table.insert(menuOptions, { - title = '🔥 ALLE ITEMS VERNICHTEN', - description = 'Vernichtet alle Items im Schredder permanent!', - icon = 'fire', - onSelect = function() - confirmDestroyAll(containerID) - end - }) - - table.insert(menuOptions, { - title = '─────────────────', - description = 'Einzelne Items:', - disabled = true - }) - - -- Einzelne Items zum Menü hinzufügen - local hasItems = false - for slot, item in pairs(items) do - if item and item.amount and item.amount > 0 then - hasItems = true - table.insert(menuOptions, { - title = (item.label or item.name), - description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot, - icon = 'trash', - onSelect = function() - confirmDestroySingle(item.name, item.amount, slot, containerID) - end - }) - end - end - - if not hasItems then - lib.notify({ - title = 'Müllschredder', - description = 'Der Schredder ist leer!', - type = 'error' - }) - return - end - - lib.registerContext({ - id = 'disposal_menu', - title = '🗑️ Müllschredder Verwaltung', - options = menuOptions - }) - - lib.showContext('disposal_menu') -end) - --- Einzelnes Item vernichten bestätigen (nur für Schredder) -function confirmDestroySingle(itemName, amount, slot, containerID) - lib.registerContext({ - id = 'dispose_single_confirm', - title = '⚠️ Item vernichten?', - options = { - { - title = '🔥 Ja, vernichten', - description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!', - icon = 'fire', - onSelect = function() - TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, "shredder") - end - }, - { - title = '❌ Abbrechen', - description = 'Zurück zum Hauptmenü', - icon = 'times', - onSelect = function() - TriggerServerEvent('disposal:server:getItems', containerID, "shredder") - end - } - } - }) - - lib.showContext('dispose_single_confirm') -end - --- Alle Items vernichten bestätigen (nur für Schredder) -function confirmDestroyAll(containerID) - lib.registerContext({ - id = 'dispose_all_confirm', - title = '⚠️ WARNUNG ⚠️', - options = { - { - title = '🔥 JA, ALLES VERNICHTEN', - description = 'ALLE Items im Schredder werden permanent gelöscht!', - icon = 'fire', - onSelect = function() - TriggerServerEvent('disposal:server:disposeAll', containerID, "shredder") - end - }, - { - title = '❌ Abbrechen', - description = 'Zurück zum Hauptmenü', - icon = 'times', - onSelect = function() - TriggerServerEvent('disposal:server:getItems', containerID, "shredder") - end - } - } - }) - - lib.showContext('dispose_all_confirm') -end - --- Erfolgs-Notification mit Effekt -RegisterNetEvent('disposal:client:itemDisposed', function(message, type) - lib.notify({ - title = type == "shredder" and 'Müllschredder' or 'Mülltonne', - description = message, - type = 'success', - duration = 4000 - }) - - -- Partikel-Effekt - local playerPed = PlayerPedId() - local coords = GetEntityCoords(playerPed) - - RequestNamedPtfxAsset("core") - while not HasNamedPtfxAssetLoaded("core") do - Wait(1) - end - - UseParticleFxAssetNextCall("core") - - -- Unterschiedliche Effekte je nach Typ - if type == "shredder" then - -- Intensiverer Effekt für Schredder - 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 - -- Subtiler Effekt für Mülltonnen - 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) - --- Informationen über zeitverzögerte Löschung anzeigen -RegisterNetEvent('disposal:client:showTrashInfo', function(deleteTime) - local days = math.floor(deleteTime / 86400) - local hours = math.floor((deleteTime % 86400) / 3600) - local minutes = math.floor((deleteTime % 3600) / 60) - - local timeString = "" - if days > 0 then - timeString = days .. " Tag" .. (days > 1 and "e" or "") .. ", " - end - timeString = timeString .. hours .. " Stunde" .. (hours > 1 and "n" or "") .. ", " - timeString = timeString .. minutes .. " Minute" .. (minutes > 1 and "n" or "") - - lib.notify({ - title = 'Mülltonne', - description = 'Items werden in ' .. timeString .. ' automatisch gelöscht!', - type = 'info', - duration = 6000 - }) -end)