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 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 local totalItems = 0 local disposedItems = {} -- Delete all items for slot, item in pairs(items) do if item and item.amount and item.amount > 0 then exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot) totalItems = totalItems + item.amount table.insert(disposedItems, {name = item.name, amount = item.amount}) end end print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID) -- Log the automatic 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', '**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 RegisterNetEvent('disposal:server:openInventory', function(containerID, type) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end -- Open the inventory exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, { maxweight = 50000, -- 50kg max slots = 20, -- 20 Slots label = type == "shredder" and 'Müllschredder' or 'Mülltonne' }) -- 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 RegisterNetEvent('disposal:server:getItems', function(containerID, type) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end -- Get items from the container local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) -- 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) end) -- Dispose single item RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID, type) local src = source local Player = QBCore.Functions.GetPlayer(src) 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 -- Log for admins print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' .. (type == "shredder" and 'destroyed' or 'disposed') .. ' ' .. 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', '**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) -- Reload menu Wait(1000) TriggerEvent('disposal:server:getItems', containerID, type) else TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error') end end) -- Dispose all items RegisterNetEvent('disposal:server:disposeAll', function(containerID, type) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end -- Get all items in the container local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) 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!', '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}) 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)') -- 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) 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 if remainingTime > 0 then ScheduleItemDeletion(containerID, remainingTime) else -- If the time has already passed, delete immediately DeleteTrashBinItems(containerID) end end print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions") end)