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' |     '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 = { | local trashBinPropModels = { | ||||||
|     'prop_bin_01a', |     'prop_bin_01a', | ||||||
|     'prop_bin_03a', |     'prop_bin_03a', | ||||||
|  | @ -29,40 +29,72 @@ Citizen.CreateThread(function() | ||||||
|         options = { |         options = { | ||||||
|             { |             { | ||||||
|                 type = "client", |                 type = "client", | ||||||
|                 event = "disposal:openShredderInventory", |                 event = "disposal:openInventory", | ||||||
|                 icon = "fas fa-dumpster", |                 icon = "fas fa-dumpster", | ||||||
|                 label = "Müllschredder öffnen", |                 label = "Müllschredder öffnen", | ||||||
|  |                 action = function(entity) | ||||||
|  |                     currentEntity = entity | ||||||
|  |                     currentType = "shredder" | ||||||
|  |                     TriggerEvent('disposal:openInventory') | ||||||
|  |                 end, | ||||||
|  |                 canInteract = function() | ||||||
|  |                     return true | ||||||
|  |                 end, | ||||||
|             }, |             }, | ||||||
|             { |             { | ||||||
|                 type = "client",  |                 type = "client",  | ||||||
|                 event = "disposal:openShredderMenu", |                 event = "disposal:openMenu", | ||||||
|                 icon = "fas fa-fire", |                 icon = "fas fa-fire", | ||||||
|                 label = "Items vernichten", |                 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 | ||||||
|     }) |     }) | ||||||
|      |      | ||||||
|     -- Add target to storage container props (formerly trash bins) |     -- Add target to trash bin props | ||||||
|     exports['qb-target']:AddTargetModel(trashBinPropModels, { |     exports['qb-target']:AddTargetModel(trashBinPropModels, { | ||||||
|         options = { |         options = { | ||||||
|             { |             { | ||||||
|                 type = "client", |                 type = "client", | ||||||
|                 event = "disposal:openStorageInventory", |                 event = "disposal:openInventory", | ||||||
|                 icon = "fas fa-box-open", |                 icon = "fas fa-trash", | ||||||
|                 label = "Lager öffnen", |                 label = "Mülltonne öffnen", | ||||||
|  |                 action = function(entity) | ||||||
|  |                     currentEntity = entity | ||||||
|  |                     currentType = "trash" | ||||||
|  |                     TriggerEvent('disposal:openInventory') | ||||||
|  |                 end, | ||||||
|  |                 canInteract = function() | ||||||
|  |                     return true | ||||||
|  |                 end, | ||||||
|             }, |             }, | ||||||
|             { |             { | ||||||
|                 type = "client",  |                 type = "client",  | ||||||
|                 event = "disposal:openStorageMenu", |                 event = "disposal:openMenu", | ||||||
|                 icon = "fas fa-archive", |                 icon = "fas fa-clock", | ||||||
|                 label = "Items lagern", |                 label = "Müll entsorgen", | ||||||
|  |                 action = function(entity) | ||||||
|  |                     currentEntity = entity | ||||||
|  |                     currentType = "trash" | ||||||
|  |                     TriggerEvent('disposal:openMenu') | ||||||
|  |                 end, | ||||||
|  |                 canInteract = function() | ||||||
|  |                     return true | ||||||
|  |                 end, | ||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|         distance = 2.0 |         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) | end) | ||||||
|  |  | ||||||
| -- Function to get container ID from entity | -- 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) |     return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z) | ||||||
| end | end | ||||||
|  |  | ||||||
| -- Open shredder inventory | -- Open container inventory | ||||||
| RegisterNetEvent('disposal:openShredderInventory', function() | RegisterNetEvent('disposal:openInventory', function() | ||||||
|     local playerPed = PlayerPedId() |     local playerPed = PlayerPedId() | ||||||
|     local coords = GetEntityCoords(playerPed) |     local coords = GetEntityCoords(playerPed) | ||||||
|      |      | ||||||
|     -- Find the closest shredder |     if not currentEntity or not DoesEntityExist(currentEntity) then | ||||||
|     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({ |         lib.notify({ | ||||||
|             title = 'Müllschredder', |             title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||||
|             description = 'Kein Schredder gefunden!', |             description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!', | ||||||
|             type = 'error' |             type = 'error' | ||||||
|         }) |         }) | ||||||
|         return |         return | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     -- Get container ID |     -- Get container ID | ||||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "shredder") |     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||||
|     if not containerID then return end |     if not containerID then return end | ||||||
|      |      | ||||||
|     -- Open inventory with this unique ID |     -- Open inventory with this unique ID | ||||||
|     TriggerServerEvent('disposal:server:openInventory', containerID, "shredder") |     TriggerServerEvent('disposal:server:openInventory', containerID, currentType) | ||||||
| end) | end) | ||||||
|  |  | ||||||
| -- Open storage inventory | -- Open disposal menu | ||||||
| RegisterNetEvent('disposal:openStorageInventory', function() | RegisterNetEvent('disposal:openMenu', function() | ||||||
|     local playerPed = PlayerPedId() |     local playerPed = PlayerPedId() | ||||||
|     local coords = GetEntityCoords(playerPed) |     local coords = GetEntityCoords(playerPed) | ||||||
|      |      | ||||||
|     -- Find the closest storage container |     if not currentEntity or not DoesEntityExist(currentEntity) then | ||||||
|     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({ |         lib.notify({ | ||||||
|             title = 'Lager', |             title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||||
|             description = 'Kein Lager gefunden!', |             description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!', | ||||||
|             type = 'error' |             type = 'error' | ||||||
|         }) |         }) | ||||||
|         return |         return | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     -- Get container ID |     -- Get container ID | ||||||
|     local containerID = GetContainerIDFromEntity(closestEntity, "trash") |     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||||
|     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") |  | ||||||
|     if not containerID then return end |     if not containerID then return end | ||||||
|      |      | ||||||
|     -- Get items in this container |     -- Get items in this container | ||||||
|     TriggerServerEvent('disposal:server:getItems', containerID, "shredder") |     TriggerServerEvent('disposal:server:getItems', containerID, currentType) | ||||||
| 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") |  | ||||||
| end) | end) | ||||||
|  |  | ||||||
| -- Show menu with items | -- 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 |     -- Make sure items is a table | ||||||
|     items = items or {} |     items = items or {} | ||||||
|      |      | ||||||
|     -- Check if items is empty |     -- Check if items is empty | ||||||
|     if next(items) == nil then |     if next(items) == nil then | ||||||
|         lib.notify({ |         lib.notify({ | ||||||
|             title = type == "shredder" and 'Müllschredder' or 'Lager', |             title = type == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||||
|             description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!', |             description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!', | ||||||
|             type = 'error' |             type = 'error' | ||||||
|         }) |         }) | ||||||
|         return |         return | ||||||
|  | @ -252,20 +168,32 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | ||||||
|     local menuOptions = {} |     local menuOptions = {} | ||||||
|      |      | ||||||
|     -- All items action option |     -- 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"  |     local actionDesc = type == "shredder"  | ||||||
|         and 'Vernichtet alle Items im Schredder permanent!'  |         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, { |     table.insert(menuOptions, { | ||||||
|         title = type == "shredder" and '🔥 ' .. actionText or '📦 ' .. actionText, |         title = '🔥 ' .. actionText, | ||||||
|         description = actionDesc, |         description = actionDesc, | ||||||
|         icon = type == "shredder" and 'fire' or 'archive', |         icon = type == "shredder" and 'fire' or 'trash', | ||||||
|         onSelect = function() |         onSelect = function() | ||||||
|             confirmDestroyAll(containerID, type) |             confirmDestroyAll(containerID, type) | ||||||
|         end |         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, { |     table.insert(menuOptions, { | ||||||
|         title = '─────────────────', |         title = '─────────────────', | ||||||
|         description = 'Einzelne Items:', |         description = 'Einzelne Items:', | ||||||
|  | @ -280,7 +208,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | ||||||
|             table.insert(menuOptions, { |             table.insert(menuOptions, { | ||||||
|                 title = (item.label or item.name), |                 title = (item.label or item.name), | ||||||
|                 description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot, |                 description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot, | ||||||
|                 icon = type == "shredder" and 'trash' or 'box', |                 icon = 'trash', | ||||||
|                 onSelect = function() |                 onSelect = function() | ||||||
|                     confirmDestroySingle(item.name, item.amount, slot, containerID, type) |                     confirmDestroySingle(item.name, item.amount, slot, containerID, type) | ||||||
|                 end |                 end | ||||||
|  | @ -290,8 +218,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | ||||||
|      |      | ||||||
|     if not hasItems then |     if not hasItems then | ||||||
|         lib.notify({ |         lib.notify({ | ||||||
|             title = type == "shredder" and 'Müllschredder' or 'Lager', |             title = type == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||||
|             description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!', |             description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!', | ||||||
|             type = 'error' |             type = 'error' | ||||||
|         }) |         }) | ||||||
|         return |         return | ||||||
|  | @ -299,7 +227,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type) | ||||||
|      |      | ||||||
|     lib.registerContext({ |     lib.registerContext({ | ||||||
|         id = 'disposal_menu', |         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 |         options = menuOptions | ||||||
|     }) |     }) | ||||||
|      |      | ||||||
|  | @ -308,19 +236,19 @@ end) | ||||||
|  |  | ||||||
| -- Confirm single item disposal | -- Confirm single item disposal | ||||||
| function confirmDestroySingle(itemName, amount, slot, containerID, type) | 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"  |     local actionDesc = type == "shredder"  | ||||||
|         and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!')  |         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({ |     lib.registerContext({ | ||||||
|         id = 'dispose_single_confirm', |         id = 'dispose_single_confirm', | ||||||
|         title = '⚠️ Item ' .. actionText .. '?', |         title = '⚠️ Item ' .. actionText .. '?', | ||||||
|         options = { |         options = { | ||||||
|             { |             { | ||||||
|                 title = type == "shredder" and '🔥 Ja, vernichten' or '📦 Ja, lagern', |                 title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen', | ||||||
|                 description = actionDesc, |                 description = actionDesc, | ||||||
|                 icon = type == "shredder" and 'check' or 'box', |                 icon = 'check', | ||||||
|                 onSelect = function() |                 onSelect = function() | ||||||
|                     TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type) |                     TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type) | ||||||
|                 end |                 end | ||||||
|  | @ -341,19 +269,19 @@ end | ||||||
|  |  | ||||||
| -- Confirm all items disposal | -- Confirm all items disposal | ||||||
| function confirmDestroyAll(containerID, type) | function confirmDestroyAll(containerID, type) | ||||||
|     local actionText = type == "shredder" and "VERNICHTEN" or "LAGERN" |     local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN" | ||||||
|     local actionDesc = type == "shredder"  |     local actionDesc = type == "shredder"  | ||||||
|         and 'ALLE Items im Schredder werden permanent gelöscht!'  |         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({ |     lib.registerContext({ | ||||||
|         id = 'dispose_all_confirm', |         id = 'dispose_all_confirm', | ||||||
|         title = type == "shredder" and '⚠️ WARNUNG ⚠️' or '📦 LAGERUNG', |         title = '⚠️ WARNUNG ⚠️', | ||||||
|         options = { |         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, |                 description = actionDesc, | ||||||
|                 icon = type == "shredder" and 'fire' or 'archive', |                 icon = type == "shredder" and 'fire' or 'trash', | ||||||
|                 onSelect = function() |                 onSelect = function() | ||||||
|                     TriggerServerEvent('disposal:server:disposeAll', containerID, type) |                     TriggerServerEvent('disposal:server:disposeAll', containerID, type) | ||||||
|                 end |                 end | ||||||
|  | @ -375,7 +303,7 @@ end | ||||||
| -- Success notification with effect | -- Success notification with effect | ||||||
| RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | ||||||
|     lib.notify({ |     lib.notify({ | ||||||
|         title = type == "shredder" and 'Müllschredder' or 'Lager', |         title = type == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||||
|         description = message, |         description = message, | ||||||
|         type = 'success', |         type = 'success', | ||||||
|         duration = 4000 |         duration = 4000 | ||||||
|  | @ -392,13 +320,13 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | ||||||
|      |      | ||||||
|     UseParticleFxAssetNextCall("core") |     UseParticleFxAssetNextCall("core") | ||||||
|      |      | ||||||
|     -- Different effects for shredder vs storage |     -- Different effects for shredder vs trash | ||||||
|     if type == "shredder" then |     if type == "shredder" then | ||||||
|         -- More intense effect for shredder |         -- 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) |         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) |         PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1) | ||||||
|     else |     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) |         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) |         PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -1,12 +1,40 @@ | ||||||
| local QBCore = exports['qb-core']:GetCoreObject() | local QBCore = exports['qb-core']:GetCoreObject() | ||||||
|  |  | ||||||
| -- Function to delete items from a shredder | -- Table to store items scheduled for deletion | ||||||
| function DeleteShredderItems(containerID) | local scheduledDeletions = {} | ||||||
|     -- Get all items in the shredder |  | ||||||
|  | -- 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) |     local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) | ||||||
|      |      | ||||||
|     if not items or next(items) == nil then |     if not items or next(items) == nil then | ||||||
|         print("^3[DISPOSAL]^7 No items to delete in " .. containerID) |         print("^3[DISPOSAL]^7 No items to delete in " .. containerID) | ||||||
|  |         scheduledDeletions[containerID] = nil | ||||||
|         return |         return | ||||||
|     end |     end | ||||||
|      |      | ||||||
|  | @ -22,16 +50,35 @@ function DeleteShredderItems(containerID) | ||||||
|         end |         end | ||||||
|     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 = "" |     local itemList = "" | ||||||
|     for _, item in pairs(disposedItems) do |     for _, item in pairs(disposedItems) do | ||||||
|         itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' |         itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' | ||||||
|     end |     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) |         '**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 | end | ||||||
|  |  | ||||||
| -- Container inventory open | -- Container inventory open | ||||||
|  | @ -45,8 +92,17 @@ RegisterNetEvent('disposal:server:openInventory', function(containerID, type) | ||||||
|     exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, { |     exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, { | ||||||
|         maxweight = 50000, -- 50kg max |         maxweight = 50000, -- 50kg max | ||||||
|         slots = 20, -- 20 Slots |         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) | end) | ||||||
|  |  | ||||||
| -- Get items from container | -- 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 is nil, provide an empty table | ||||||
|     if items == nil then items = {} end |     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) | end) | ||||||
|  |  | ||||||
| -- Dispose single item | -- Dispose single item | ||||||
|  | @ -72,53 +134,44 @@ RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slo | ||||||
|      |      | ||||||
|     if not Player then return end |     if not Player then return end | ||||||
|      |      | ||||||
|     if type == "shredder" then |     -- Remove the item from the container | ||||||
|         -- For shredders, remove the item permanently |     local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot) | ||||||
|         local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot) |      | ||||||
|          |     if success then | ||||||
|         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 |         -- 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 |         -- Discord Webhook | ||||||
|         TriggerEvent('qb-log:server:CreateLog', 'disposal',  |         TriggerEvent('qb-log:server:CreateLog', 'disposal',  | ||||||
|             'Item Stored',  |             type == "shredder" and 'Item Destroyed' or 'Item Disposed',  | ||||||
|             'blue',  |             type == "shredder" and 'orange' or 'blue',  | ||||||
|             '**Player:** ' .. GetPlayerName(src) ..  |             '**Player:** ' .. GetPlayerName(src) ..  | ||||||
|             '\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..  |             '\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..  | ||||||
|             '\n**Item:** ' .. amount .. 'x ' .. itemName ..  |             '\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 |         -- Reload menu | ||||||
|         Wait(1000) |         Wait(1000) | ||||||
|         TriggerEvent('disposal:server:getItems', containerID, type) |         TriggerEvent('disposal:server:getItems', containerID, type) | ||||||
|  |     else | ||||||
|  |         TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error') | ||||||
|     end |     end | ||||||
| end) | end) | ||||||
|  |  | ||||||
|  | @ -134,83 +187,100 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type) | ||||||
|      |      | ||||||
|     if not items or next(items) == nil then |     if not items or next(items) == nil then | ||||||
|         TriggerClientEvent('QBCore:Notify', src,  |         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') |             'error') | ||||||
|         return |         return | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     if type == "shredder" then |     local disposedItems = {} | ||||||
|         -- For shredders, remove all items permanently |     local totalItems = 0 | ||||||
|         local disposedItems = {} |      | ||||||
|         local totalItems = 0 |     -- Dispose all items | ||||||
|          |     for slot, item in pairs(items) do | ||||||
|         -- Dispose all items |         if item and item.amount and item.amount > 0 then | ||||||
|         for slot, item in pairs(items) do |             local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot) | ||||||
|             if item and item.amount and item.amount > 0 then |             if success then | ||||||
|                 local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot) |                 table.insert(disposedItems, {name = item.name, amount = item.amount}) | ||||||
|                 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 |                 totalItems = totalItems + item.amount | ||||||
|             end |             end | ||||||
|         end |         end | ||||||
|          |     end | ||||||
|  |      | ||||||
|  |     if #disposedItems > 0 then | ||||||
|         -- Log for admins |         -- 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 |         -- Discord Webhook with item list | ||||||
|         local itemList = "" |         local itemList = "" | ||||||
|         for slot, item in pairs(items) do |         for _, item in pairs(disposedItems) do | ||||||
|             if item and item.amount and item.amount > 0 then |             itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' | ||||||
|                 itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n' |  | ||||||
|             end |  | ||||||
|         end |         end | ||||||
|          |          | ||||||
|         TriggerEvent('qb-log:server:CreateLog', 'disposal',  |         TriggerEvent('qb-log:server:CreateLog', 'disposal',  | ||||||
|             'All Items Stored',  |             type == "shredder" and 'All Items Destroyed' or 'All Items Disposed',  | ||||||
|             'green',  |             type == "shredder" and 'red' or 'green',  | ||||||
|             '**Player:** ' .. GetPlayerName(src) ..  |             '**Player:** ' .. GetPlayerName(src) ..  | ||||||
|             '\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..  |             '\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**Total Items:** ' .. totalItems ..  | ||||||
|             '\n**Items:**\n' .. itemList) |             '\n**Items:**\n' .. itemList) | ||||||
|          |          | ||||||
|         -- Notification message |         -- Different messages based on type | ||||||
|         local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden im Lager gespeichert!' |         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) |         TriggerClientEvent('disposal:client:itemDisposed', src, message, type) | ||||||
|  |     else | ||||||
|  |         TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error') | ||||||
|     end |     end | ||||||
| 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