ed
This commit is contained in:
		
							parent
							
								
									001c206759
								
							
						
					
					
						commit
						5845490f4c
					
				
					 2 changed files with 264 additions and 266 deletions
				
			
		|  | @ -6,7 +6,7 @@ local shredderPropModels = { | |||
|     'prop_bin_08a' | ||||
| } | ||||
|  | ||||
| -- List of prop models that should be targetable as storage containers (formerly trash bins) | ||||
| -- List of prop models that should be targetable as trash bins with delayed deletion | ||||
| local trashBinPropModels = { | ||||
|     'prop_bin_01a', | ||||
|     'prop_bin_03a', | ||||
|  | @ -29,40 +29,72 @@ Citizen.CreateThread(function() | |||
|         options = { | ||||
|             { | ||||
|                 type = "client", | ||||
|                 event = "disposal:openShredderInventory", | ||||
|                 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, | ||||
|             }, | ||||
|             { | ||||
|                 type = "client",  | ||||
|                 event = "disposal:openShredderMenu", | ||||
|                 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 | ||||
|     }) | ||||
|      | ||||
|     -- Add target to storage container props (formerly trash bins) | ||||
|     -- Add target to trash bin props | ||||
|     exports['qb-target']:AddTargetModel(trashBinPropModels, { | ||||
|         options = { | ||||
|             { | ||||
|                 type = "client", | ||||
|                 event = "disposal:openStorageInventory", | ||||
|                 icon = "fas fa-box-open", | ||||
|                 label = "Lager öffnen", | ||||
|                 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:openStorageMenu", | ||||
|                 icon = "fas fa-archive", | ||||
|                 label = "Items lagern", | ||||
|                 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 .. " storage container models") | ||||
|     print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models") | ||||
| end) | ||||
|  | ||||
| -- Function to get container ID from entity | ||||
|  | @ -74,176 +106,60 @@ function GetContainerIDFromEntity(entity, type) | |||
|     return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z) | ||||
| end | ||||
|  | ||||
| -- Open shredder inventory | ||||
| RegisterNetEvent('disposal:openShredderInventory', function() | ||||
| -- Open container inventory | ||||
| RegisterNetEvent('disposal:openInventory', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|     -- Find the closest shredder | ||||
|     local closestEntity = nil | ||||
|     local closestDistance = 3.0 | ||||
|      | ||||
|     for _, model in ipairs(shredderPropModels) do | ||||
|         local hash = GetHashKey(model) | ||||
|         if hash then | ||||
|             local entity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.0, hash, false, false, false) | ||||
|             if entity ~= 0 then | ||||
|                 local distance = #(coords - GetEntityCoords(entity)) | ||||
|                 if distance < closestDistance then | ||||
|                     closestEntity = entity | ||||
|                     closestDistance = distance | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
|     end | ||||
|      | ||||
|     if not closestEntity 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 container ID | ||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "shredder") | ||||
|     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Open inventory with this unique ID | ||||
|     TriggerServerEvent('disposal:server:openInventory', containerID, "shredder") | ||||
|     TriggerServerEvent('disposal:server:openInventory', containerID, currentType) | ||||
| end) | ||||
|  | ||||
| -- Open storage inventory | ||||
| RegisterNetEvent('disposal:openStorageInventory', function() | ||||
| -- Open disposal menu | ||||
| RegisterNetEvent('disposal:openMenu', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|     -- Find the closest storage container | ||||
|     local closestEntity = nil | ||||
|     local closestDistance = 3.0 | ||||
|      | ||||
|     for _, model in ipairs(trashBinPropModels) do | ||||
|         local hash = GetHashKey(model) | ||||
|         if hash then | ||||
|             local entity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.0, hash, false, false, false) | ||||
|             if entity ~= 0 then | ||||
|                 local distance = #(coords - GetEntityCoords(entity)) | ||||
|                 if distance < closestDistance then | ||||
|                     closestEntity = entity | ||||
|                     closestDistance = distance | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
|     end | ||||
|      | ||||
|     if not closestEntity then | ||||
|     if not currentEntity or not DoesEntityExist(currentEntity) then | ||||
|         lib.notify({ | ||||
|             title = 'Lager', | ||||
|             description = 'Kein Lager 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 container ID | ||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "trash") | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Open inventory with this unique ID | ||||
|     TriggerServerEvent('disposal:server:openInventory', containerID, "trash") | ||||
| end) | ||||
|  | ||||
| -- Open shredder menu | ||||
| RegisterNetEvent('disposal:openShredderMenu', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|     -- Find the closest shredder | ||||
|     local closestEntity = nil | ||||
|     local closestDistance = 3.0 | ||||
|      | ||||
|     for _, model in ipairs(shredderPropModels) do | ||||
|         local hash = GetHashKey(model) | ||||
|         if hash then | ||||
|             local entity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.0, hash, false, false, false) | ||||
|             if entity ~= 0 then | ||||
|                 local distance = #(coords - GetEntityCoords(entity)) | ||||
|                 if distance < closestDistance then | ||||
|                     closestEntity = entity | ||||
|                     closestDistance = distance | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
|     end | ||||
|      | ||||
|     if not closestEntity then | ||||
|         lib.notify({ | ||||
|             title = 'Müllschredder', | ||||
|             description = 'Kein Schredder gefunden!', | ||||
|             type = 'error' | ||||
|         }) | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Get container ID | ||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "shredder") | ||||
|     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Get items in this container | ||||
|     TriggerServerEvent('disposal:server:getItems', containerID, "shredder") | ||||
| end) | ||||
|  | ||||
| -- Open storage menu | ||||
| RegisterNetEvent('disposal:openStorageMenu', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|     -- Find the closest storage container | ||||
|     local closestEntity = nil | ||||
|     local closestDistance = 3.0 | ||||
|      | ||||
|     for _, model in ipairs(trashBinPropModels) do | ||||
|         local hash = GetHashKey(model) | ||||
|         if hash then | ||||
|             local entity = GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.0, hash, false, false, false) | ||||
|             if entity ~= 0 then | ||||
|                 local distance = #(coords - GetEntityCoords(entity)) | ||||
|                 if distance < closestDistance then | ||||
|                     closestEntity = entity | ||||
|                     closestDistance = distance | ||||
|                 end | ||||
|             end | ||||
|         end | ||||
|     end | ||||
|      | ||||
|     if not closestEntity then | ||||
|         lib.notify({ | ||||
|             title = 'Lager', | ||||
|             description = 'Kein Lager gefunden!', | ||||
|             type = 'error' | ||||
|         }) | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Get container ID | ||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "trash") | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Get items in this container | ||||
|     TriggerServerEvent('disposal:server:getItems', containerID, "trash") | ||||
|     TriggerServerEvent('disposal:server:getItems', containerID, currentType) | ||||
| end) | ||||
|  | ||||
| -- Show menu with items | ||||
| RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | ||||
| 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 = type == "shredder" and 'Müllschredder' or 'Lager', | ||||
|             description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager 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 | ||||
|  | @ -252,20 +168,32 @@ 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 LAGERN" | ||||
|     local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN" | ||||
|     local actionDesc = type == "shredder"  | ||||
|         and 'Vernichtet alle Items im Schredder permanent!'  | ||||
|         or 'Lagert alle Items im Container!' | ||||
|         or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!' | ||||
|      | ||||
|     table.insert(menuOptions, { | ||||
|         title = type == "shredder" and '🔥 ' .. actionText or '📦 ' .. actionText, | ||||
|         title = '🔥 ' .. actionText, | ||||
|         description = actionDesc, | ||||
|         icon = type == "shredder" and 'fire' or 'archive', | ||||
|         icon = type == "shredder" and 'fire' or 'trash', | ||||
|         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:', | ||||
|  | @ -280,7 +208,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 = type == "shredder" and 'trash' or 'box', | ||||
|                 icon = 'trash', | ||||
|                 onSelect = function() | ||||
|                     confirmDestroySingle(item.name, item.amount, slot, containerID, type) | ||||
|                 end | ||||
|  | @ -290,8 +218,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | |||
|      | ||||
|     if not hasItems then | ||||
|         lib.notify({ | ||||
|             title = type == "shredder" and 'Müllschredder' or 'Lager', | ||||
|             description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager 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 | ||||
|  | @ -299,7 +227,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | |||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'disposal_menu', | ||||
|         title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '📦 Lager Verwaltung', | ||||
|         title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung', | ||||
|         options = menuOptions | ||||
|     }) | ||||
|      | ||||
|  | @ -308,19 +236,19 @@ end) | |||
|  | ||||
| -- Confirm single item disposal | ||||
| function confirmDestroySingle(itemName, amount, slot, containerID, type) | ||||
|     local actionText = type == "shredder" and "vernichten" or "lagern" | ||||
|     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 im Lager gespeichert!') | ||||
|         or (itemName .. ' (' .. amount .. 'x) wird entsorgt und nach Zeit gelöscht!') | ||||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'dispose_single_confirm', | ||||
|         title = '⚠️ Item ' .. actionText .. '?', | ||||
|         options = { | ||||
|             { | ||||
|                 title = type == "shredder" and '🔥 Ja, vernichten' or '📦 Ja, lagern', | ||||
|                 title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen', | ||||
|                 description = actionDesc, | ||||
|                 icon = type == "shredder" and 'check' or 'box', | ||||
|                 icon = 'check', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type) | ||||
|                 end | ||||
|  | @ -341,19 +269,19 @@ end | |||
|  | ||||
| -- Confirm all items disposal | ||||
| function confirmDestroyAll(containerID, type) | ||||
|     local actionText = type == "shredder" and "VERNICHTEN" or "LAGERN" | ||||
|     local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN" | ||||
|     local actionDesc = type == "shredder"  | ||||
|         and 'ALLE Items im Schredder werden permanent gelöscht!'  | ||||
|         or 'ALLE Items werden im Lager gespeichert!' | ||||
|         or 'ALLE Items in der Mülltonne werden nach Zeit automatisch gelöscht!' | ||||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'dispose_all_confirm', | ||||
|         title = type == "shredder" and '⚠️ WARNUNG ⚠️' or '📦 LAGERUNG', | ||||
|         title = '⚠️ WARNUNG ⚠️', | ||||
|         options = { | ||||
|             { | ||||
|                 title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '📦 JA, ALLES LAGERN', | ||||
|                 title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN', | ||||
|                 description = actionDesc, | ||||
|                 icon = type == "shredder" and 'fire' or 'archive', | ||||
|                 icon = type == "shredder" and 'fire' or 'trash', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:disposeAll', containerID, type) | ||||
|                 end | ||||
|  | @ -375,7 +303,7 @@ end | |||
| -- Success notification with effect | ||||
| RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | ||||
|     lib.notify({ | ||||
|         title = type == "shredder" and 'Müllschredder' or 'Lager', | ||||
|         title = type == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||
|         description = message, | ||||
|         type = 'success', | ||||
|         duration = 4000 | ||||
|  | @ -392,13 +320,13 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | |||
|      | ||||
|     UseParticleFxAssetNextCall("core") | ||||
|      | ||||
|     -- Different effects for shredder vs storage | ||||
|     -- 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 storage | ||||
|         -- 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 | ||||
|  |  | |||
|  | @ -1,12 +1,40 @@ | |||
| local QBCore = exports['qb-core']:GetCoreObject() | ||||
|  | ||||
| -- Function to delete items from a shredder | ||||
| function DeleteShredderItems(containerID) | ||||
|     -- Get all items in the shredder | ||||
| -- 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 | ||||
|      | ||||
|  | @ -22,16 +50,35 @@ function DeleteShredderItems(containerID) | |||
|         end | ||||
|     end | ||||
|      | ||||
|     print("^3[DISPOSAL]^7 Deleted " .. totalItems .. " items from shredder " .. containerID) | ||||
|     print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID) | ||||
|      | ||||
|     -- Log the deletion | ||||
|     -- 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', 'Shredder Items Destroyed', 'orange',  | ||||
|     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 | ||||
|  | @ -45,8 +92,17 @@ 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 'Lager' | ||||
|         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 | ||||
|  | @ -62,7 +118,13 @@ RegisterNetEvent('disposal:server:getItems', function(containerID, type) | |||
|     -- If items is nil, provide an empty table | ||||
|     if items == nil then items = {} end | ||||
|      | ||||
|     TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type) | ||||
|     -- 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 | ||||
|  | @ -72,53 +134,44 @@ RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slo | |||
|      | ||||
|     if not Player then return end | ||||
|      | ||||
|     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) | ||||
|     -- 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 stored ' .. amount .. 'x ' .. itemName) | ||||
|         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',  | ||||
|             'Item Stored',  | ||||
|             'blue',  | ||||
|             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:** Item stored in container') | ||||
|             '\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) | ||||
|  | ||||
|  | @ -134,83 +187,100 @@ 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 'Das Lager ist bereits leer!',  | ||||
|             type == "shredder" and 'Der Schredder ist bereits leer!' or 'Die Mülltonne ist bereits leer!',  | ||||
|             'error') | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     if type == "shredder" then | ||||
|         -- For shredders, remove all items permanently | ||||
|         local disposedItems = {} | ||||
|         local totalItems = 0 | ||||
|     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 | ||||
|     -- 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 stored ALL items (' .. totalItems .. ' items)') | ||||
|         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 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 | ||||
|         for _, item in pairs(disposedItems) do | ||||
|             itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' | ||||
|         end | ||||
|          | ||||
|         TriggerEvent('qb-log:server:CreateLog', 'disposal',  | ||||
|             'All Items Stored',  | ||||
|             'green',  | ||||
|             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:** All items stored in container' ..  | ||||
|             '\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') ..  | ||||
|             '\n**Total Items:** ' .. totalItems ..  | ||||
|             '\n**Items:**\n' .. itemList) | ||||
|          | ||||
|         -- Notification message | ||||
|         local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden im Lager gespeichert!' | ||||
|         -- 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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98