diff --git a/resources/[inventory]/nordi_schredder/client.lua b/resources/[inventory]/nordi_schredder/client.lua index 6f0fb0fb5..1a61e4c23 100644 --- a/resources/[inventory]/nordi_schredder/client.lua +++ b/resources/[inventory]/nordi_schredder/client.lua @@ -6,7 +6,7 @@ local shredderPropModels = { 'prop_bin_08a' } --- List of prop models that should be targetable as trash bins with delayed deletion +-- List of prop models that should be targetable as storage containers (formerly trash bins) local trashBinPropModels = { 'prop_bin_01a', 'prop_bin_03a', @@ -59,14 +59,14 @@ Citizen.CreateThread(function() distance = 2.0 }) - -- Add target to trash bin props + -- Add target to storage container props (formerly trash bins) exports['qb-target']:AddTargetModel(trashBinPropModels, { options = { { type = "client", event = "disposal:openInventory", - icon = "fas fa-trash", - label = "Mülltonne öffnen", + icon = "fas fa-box-open", + label = "Lager öffnen", action = function(entity) currentEntity = entity currentType = "trash" @@ -79,8 +79,8 @@ Citizen.CreateThread(function() { type = "client", event = "disposal:openMenu", - icon = "fas fa-clock", - label = "Müll entsorgen", + icon = "fas fa-archive", + label = "Items lagern", action = function(entity) currentEntity = entity currentType = "trash" @@ -94,7 +94,7 @@ Citizen.CreateThread(function() distance = 2.0 }) - print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models") + print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " storage container models") end) -- Function to get container ID from entity @@ -113,8 +113,8 @@ RegisterNetEvent('disposal:openInventory', function() 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!', + title = currentType == "shredder" and 'Müllschredder' or 'Lager', + description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!', type = 'error' }) return @@ -135,8 +135,8 @@ RegisterNetEvent('disposal:openMenu', function() 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!', + title = currentType == "shredder" and 'Müllschredder' or 'Lager', + description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!', type = 'error' }) return @@ -151,15 +151,15 @@ RegisterNetEvent('disposal:openMenu', function() end) -- Show menu with items -RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining) +RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) -- Make sure items is a table items = items or {} -- Check if items is empty if next(items) == nil then lib.notify({ - title = type == "shredder" and 'Müllschredder' or 'Mülltonne', - description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!', + title = type == "shredder" and 'Müllschredder' or 'Lager', + description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!', type = 'error' }) return @@ -168,32 +168,20 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, local menuOptions = {} -- All items action option - local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN" + local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS LAGERN" local actionDesc = type == "shredder" and 'Vernichtet alle Items im Schredder permanent!' - or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!' + or 'Lagert alle Items im Container!' table.insert(menuOptions, { - title = '🔥 ' .. actionText, + title = type == "shredder" and '🔥 ' .. actionText or '📦 ' .. actionText, description = actionDesc, - icon = type == "shredder" and 'fire' or 'trash', + icon = type == "shredder" and 'fire' or 'archive', onSelect = function() 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:', @@ -208,7 +196,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, table.insert(menuOptions, { title = (item.label or item.name), description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot, - icon = 'trash', + icon = type == "shredder" and 'trash' or 'box', onSelect = function() confirmDestroySingle(item.name, item.amount, slot, containerID, type) end @@ -218,8 +206,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, if not hasItems then lib.notify({ - title = type == "shredder" and 'Müllschredder' or 'Mülltonne', - description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!', + title = type == "shredder" and 'Müllschredder' or 'Lager', + description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!', type = 'error' }) return @@ -227,7 +215,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, lib.registerContext({ id = 'disposal_menu', - title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung', + title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '📦 Lager Verwaltung', options = menuOptions }) @@ -236,19 +224,19 @@ end) -- Confirm single item disposal function confirmDestroySingle(itemName, amount, slot, containerID, type) - local actionText = type == "shredder" and "vernichten" or "entsorgen" + local actionText = type == "shredder" and "vernichten" or "lagern" local actionDesc = type == "shredder" and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!') - or (itemName .. ' (' .. amount .. 'x) wird entsorgt und nach Zeit gelöscht!') + or (itemName .. ' (' .. amount .. 'x) wird im Lager gespeichert!') lib.registerContext({ id = 'dispose_single_confirm', title = '⚠️ Item ' .. actionText .. '?', options = { { - title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen', + title = type == "shredder" and '🔥 Ja, vernichten' or '📦 Ja, lagern', description = actionDesc, - icon = 'check', + icon = type == "shredder" and 'check' or 'box', onSelect = function() TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type) end @@ -269,19 +257,19 @@ end -- Confirm all items disposal function confirmDestroyAll(containerID, type) - local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN" + local actionText = type == "shredder" and "VERNICHTEN" or "LAGERN" 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!' + or 'ALLE Items werden im Lager gespeichert!' lib.registerContext({ id = 'dispose_all_confirm', - title = '⚠️ WARNUNG ⚠️', + title = type == "shredder" and '⚠️ WARNUNG ⚠️' or '📦 LAGERUNG', options = { { - title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN', + title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '📦 JA, ALLES LAGERN', description = actionDesc, - icon = type == "shredder" and 'fire' or 'trash', + icon = type == "shredder" and 'fire' or 'archive', onSelect = function() TriggerServerEvent('disposal:server:disposeAll', containerID, type) end @@ -303,7 +291,7 @@ end -- Success notification with effect RegisterNetEvent('disposal:client:itemDisposed', function(message, type) lib.notify({ - title = type == "shredder" and 'Müllschredder' or 'Mülltonne', + title = type == "shredder" and 'Müllschredder' or 'Lager', description = message, type = 'success', duration = 4000 @@ -320,13 +308,13 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type) UseParticleFxAssetNextCall("core") - -- Different effects for shredder vs trash + -- Different effects for shredder vs storage 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 + -- Subtle effect for storage 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 diff --git a/resources/[inventory]/nordi_schredder/server.lua b/resources/[inventory]/nordi_schredder/server.lua index f3d7e34a5..905bded1d 100644 --- a/resources/[inventory]/nordi_schredder/server.lua +++ b/resources/[inventory]/nordi_schredder/server.lua @@ -1,40 +1,12 @@ local QBCore = exports['qb-core']:GetCoreObject() --- Table to store items scheduled for deletion -local scheduledDeletions = {} - --- Default time for trash bin deletion (2 days = 48 hours = 172800 seconds) -local DEFAULT_TRASH_DELETE_TIME = 172800 -- seconds - --- Function to schedule item deletion -function ScheduleItemDeletion(containerID, deleteTime) - -- Use default time if not specified - deleteTime = deleteTime or DEFAULT_TRASH_DELETE_TIME - - -- Cancel existing timer if there is one - if scheduledDeletions[containerID] and scheduledDeletions[containerID].timer then - clearTimeout(scheduledDeletions[containerID].timer) - end - - -- Schedule the deletion - scheduledDeletions[containerID] = { - deleteAt = os.time() + deleteTime, - timer = setTimeout(function() - DeleteTrashBinItems(containerID) - end, deleteTime * 1000) - } - - print("^3[DISPOSAL]^7 Items in " .. containerID .. " scheduled for deletion in " .. deleteTime .. " seconds") -end - --- Function to delete items from a trash bin -function DeleteTrashBinItems(containerID) - -- Get all items in the trash bin +-- Function to delete items from a shredder +function DeleteShredderItems(containerID) + -- Get all items in the shredder local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) if not items or next(items) == nil then print("^3[DISPOSAL]^7 No items to delete in " .. containerID) - scheduledDeletions[containerID] = nil return end @@ -50,35 +22,16 @@ function DeleteTrashBinItems(containerID) end end - print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID) + print("^3[DISPOSAL]^7 Deleted " .. totalItems .. " items from shredder " .. containerID) - -- Log the automatic deletion + -- Log the deletion local itemList = "" for _, item in pairs(disposedItems) do itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' end - TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Automatic Trash Deletion', 'yellow', + TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Shredder Items Destroyed', 'orange', '**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList) - - -- Remove from scheduled deletions - scheduledDeletions[containerID] = nil -end - --- Get time remaining for a scheduled deletion -function GetTimeRemaining(containerID) - if scheduledDeletions[containerID] then - local currentTime = os.time() - local deleteAt = scheduledDeletions[containerID].deleteAt - local remaining = deleteAt - currentTime - - if remaining < 0 then - return 0 - else - return remaining - end - end - return nil end -- Container inventory open @@ -92,17 +45,8 @@ RegisterNetEvent('disposal:server:openInventory', function(containerID, type) exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, { maxweight = 50000, -- 50kg max slots = 20, -- 20 Slots - label = type == "shredder" and 'Müllschredder' or 'Mülltonne' + label = type == "shredder" and 'Müllschredder' or 'Lager' }) - - -- If it's a trash bin, schedule deletion if not already scheduled - if type == "trash" and not scheduledDeletions[containerID] then - -- Check if there are items in the container - local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) - if items and next(items) then - ScheduleItemDeletion(containerID) - end - end end) -- Get items from container @@ -118,13 +62,7 @@ RegisterNetEvent('disposal:server:getItems', function(containerID, type) -- If items is nil, provide an empty table if items == nil then items = {} end - -- Get time remaining for trash bins - local timeRemaining = nil - if type == "trash" then - timeRemaining = GetTimeRemaining(containerID) - end - - TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type, timeRemaining) + TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type) end) -- Dispose single item @@ -134,44 +72,53 @@ RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slo if not Player then return end - -- Remove the item from the container - local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot) - - if success then + if type == "shredder" then + -- For shredders, remove the item permanently + local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot) + + if success then + -- Log for admins + print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has destroyed ' .. amount .. 'x ' .. itemName) + + -- Discord Webhook + TriggerEvent('qb-log:server:CreateLog', 'disposal', + 'Item Destroyed', + 'orange', + '**Player:** ' .. GetPlayerName(src) .. + '\n**Citizen ID:** ' .. Player.PlayerData.citizenid .. + '\n**Item:** ' .. amount .. 'x ' .. itemName .. + '\n**Action:** Item destroyed') + + -- Notification message + local message = amount .. 'x ' .. itemName .. ' wurde vernichtet!' + TriggerClientEvent('disposal:client:itemDisposed', src, message, type) + + -- Reload menu + Wait(1000) + TriggerEvent('disposal:server:getItems', containerID, type) + else + TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Vernichten des Items!', 'error') + end + else + -- For storage containers, just notify that the item is stored + local message = amount .. 'x ' .. itemName .. ' wurde im Lager gespeichert!' + TriggerClientEvent('disposal:client:itemDisposed', src, message, type) + -- Log for admins - print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' .. - (type == "shredder" and 'destroyed' or 'disposed') .. ' ' .. amount .. 'x ' .. itemName) + print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ' .. amount .. 'x ' .. itemName) -- Discord Webhook TriggerEvent('qb-log:server:CreateLog', 'disposal', - type == "shredder" and 'Item Destroyed' or 'Item Disposed', - type == "shredder" and 'orange' or 'blue', + 'Item Stored', + 'blue', '**Player:** ' .. GetPlayerName(src) .. '\n**Citizen ID:** ' .. Player.PlayerData.citizenid .. '\n**Item:** ' .. amount .. 'x ' .. itemName .. - '\n**Action:** ' .. (type == "shredder" and 'Item destroyed' or 'Item disposed')) - - -- Different messages based on type - local message = "" - if type == "shredder" then - message = amount .. 'x ' .. itemName .. ' wurde vernichtet!' - else - message = amount .. 'x ' .. itemName .. ' wurde entsorgt!' - - -- Schedule deletion if this is the first item in the trash bin - local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) - if items and next(items) and not scheduledDeletions[containerID] then - ScheduleItemDeletion(containerID) - end - end - - TriggerClientEvent('disposal:client:itemDisposed', src, message, type) + '\n**Action:** Item stored in container') -- Reload menu Wait(1000) TriggerEvent('disposal:server:getItems', containerID, type) - else - TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error') end end) @@ -187,100 +134,83 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type) if not items or next(items) == nil then TriggerClientEvent('QBCore:Notify', src, - type == "shredder" and 'Der Schredder ist bereits leer!' or 'Die Mülltonne ist bereits leer!', + type == "shredder" and 'Der Schredder ist bereits leer!' or 'Das Lager ist bereits leer!', 'error') return end - local disposedItems = {} - local totalItems = 0 - - -- Dispose all items - for slot, item in pairs(items) do - if item and item.amount and item.amount > 0 then - local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot) - if success then - table.insert(disposedItems, {name = item.name, amount = item.amount}) + if type == "shredder" then + -- For shredders, remove all items permanently + local disposedItems = {} + local totalItems = 0 + + -- Dispose all items + for slot, item in pairs(items) do + if item and item.amount and item.amount > 0 then + local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot) + if success then + table.insert(disposedItems, {name = item.name, amount = item.amount}) + totalItems = totalItems + item.amount + end + end + end + + if #disposedItems > 0 then + -- Log for admins + print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has destroyed ALL items (' .. totalItems .. ' items)') + + -- Discord Webhook with item list + local itemList = "" + for _, item in pairs(disposedItems) do + itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' + end + + TriggerEvent('qb-log:server:CreateLog', 'disposal', + 'All Items Destroyed', + 'red', + '**Player:** ' .. GetPlayerName(src) .. + '\n**Citizen ID:** ' .. Player.PlayerData.citizenid .. + '\n**Action:** All items destroyed' .. + '\n**Total Items:** ' .. totalItems .. + '\n**Items:**\n' .. itemList) + + -- Notification message + local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!' + TriggerClientEvent('disposal:client:itemDisposed', src, message, type) + else + TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Vernichten gefunden!', 'error') + end + else + -- For storage containers, just notify that all items are stored + local totalItems = 0 + for slot, item in pairs(items) do + if item and item.amount and item.amount > 0 then totalItems = totalItems + item.amount end end - end - - if #disposedItems > 0 then + -- Log for admins - print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' .. - (type == "shredder" and 'destroyed' or 'disposed') .. ' ALL items (' .. totalItems .. ' items)') + print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ALL items (' .. totalItems .. ' items)') -- Discord Webhook with item list local itemList = "" - for _, item in pairs(disposedItems) do - itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' - end - - TriggerEvent('qb-log:server:CreateLog', 'disposal', - type == "shredder" and 'All Items Destroyed' or 'All Items Disposed', - type == "shredder" and 'red' or 'green', - '**Player:** ' .. GetPlayerName(src) .. - '\n**Citizen ID:** ' .. Player.PlayerData.citizenid .. - '\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') .. - '\n**Total Items:** ' .. totalItems .. - '\n**Items:**\n' .. itemList) - - -- Different messages based on type - local message = "" - if type == "shredder" then - message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!' - else - message = 'ALLE Items (' .. totalItems .. ' Stück) wurden entsorgt!' - - -- For trash bins, schedule deletion if not already scheduled - if not scheduledDeletions[containerID] then - ScheduleItemDeletion(containerID) + for slot, item in pairs(items) do + if item and item.amount and item.amount > 0 then + itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' end end - TriggerClientEvent('disposal:client:itemDisposed', src, message, type) - else - TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error') - end -end) - --- Save scheduled deletions when resource stops -AddEventHandler('onResourceStop', function(resourceName) - if resourceName ~= GetCurrentResourceName() then return end - - -- Here you could save scheduledDeletions to a database - -- Example with KVP: - local savedData = {} - for containerID, data in pairs(scheduledDeletions) do - savedData[containerID] = { - deleteAt = data.deleteAt - } - end - - SaveResourceFile(GetCurrentResourceName(), "scheduled_deletions.json", json.encode(savedData), -1) - print("^3[DISPOSAL]^7 Saved " .. #savedData .. " scheduled deletions") -end) - --- Restore scheduled deletions when resource starts -AddEventHandler('onResourceStart', function(resourceName) - if resourceName ~= GetCurrentResourceName() then return end - - -- Here you could load scheduled deletions from a database - -- Example with KVP: - local savedData = json.decode(LoadResourceFile(GetCurrentResourceName(), "scheduled_deletions.json") or "{}") - - for containerID, data in pairs(savedData) do - local currentTime = os.time() - local remainingTime = data.deleteAt - currentTime + TriggerEvent('qb-log:server:CreateLog', 'disposal', + 'All Items Stored', + 'green', + '**Player:** ' .. GetPlayerName(src) .. + '\n**Citizen ID:** ' .. Player.PlayerData.citizenid .. + '\n**Action:** All items stored in container' .. + '\n**Total Items:** ' .. totalItems .. + '\n**Items:**\n' .. itemList) - if remainingTime > 0 then - ScheduleItemDeletion(containerID, remainingTime) - else - -- If the time has already passed, delete immediately - DeleteTrashBinItems(containerID) - end + -- Notification message + local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden im Lager gespeichert!' + TriggerClientEvent('disposal:client:itemDisposed', src, message, type) end - - print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions") end)