ed
This commit is contained in:
		
							parent
							
								
									31ddbf70b2
								
							
						
					
					
						commit
						55ce22c3de
					
				
					 2 changed files with 241 additions and 237 deletions
				
			
		|  | @ -1,12 +1,12 @@ | |||
| local QBCore = exports['qb-core']:GetCoreObject() | ||||
|  | ||||
| -- Liste der Prop-Modelle für sofortige Schredder | ||||
| -- List of prop models that should be targetable as immediate shredders | ||||
| local shredderPropModels = { | ||||
|     'p_secret_weapon_02', | ||||
|     'prop_bin_08a' | ||||
| } | ||||
|  | ||||
| -- Liste der Prop-Modelle für zeitverzögerte Mülltonnen | ||||
| -- List of prop models that should be targetable as trash bins with delayed deletion | ||||
| local trashBinPropModels = { | ||||
|     'prop_bin_01a', | ||||
|     'prop_bin_03a', | ||||
|  | @ -18,78 +18,86 @@ local trashBinPropModels = { | |||
|     'prop_dumpster_3a' | ||||
| } | ||||
|  | ||||
| -- Variable zum Speichern der aktuellen Entität | ||||
| -- Variable to store the current entity being interacted with | ||||
| local currentEntity = nil | ||||
| local currentType = nil | ||||
|  | ||||
| -- QB-Target zu allen passenden Props in der Welt hinzufügen | ||||
| -- Add QB-Target to all matching props in the world | ||||
| Citizen.CreateThread(function() | ||||
|     -- Schredder-Optionen definieren | ||||
|     local shredderOptions = { | ||||
|         { | ||||
|             type = "client", | ||||
|             event = "disposal:openInventory", | ||||
|             icon = "fas fa-dumpster", | ||||
|             label = "Müllschredder öffnen", | ||||
|             action = function(entity) | ||||
|                 currentEntity = entity | ||||
|                 currentType = "shredder" | ||||
|                 TriggerEvent('disposal:openInventory') | ||||
|             end, | ||||
|             canInteract = function() | ||||
|                 return true | ||||
|             end, | ||||
|         }, | ||||
|         { | ||||
|             type = "client",  | ||||
|             event = "disposal:openMenu", | ||||
|             icon = "fas fa-fire", | ||||
|             label = "Items vernichten", | ||||
|             action = function(entity) | ||||
|                 currentEntity = entity | ||||
|                 currentType = "shredder" | ||||
|                 TriggerEvent('disposal:openMenu') | ||||
|             end, | ||||
|             canInteract = function() | ||||
|                 return true | ||||
|             end, | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     -- Mülltonnen-Optionen definieren | ||||
|     local trashOptions = { | ||||
|         { | ||||
|             type = "client", | ||||
|             event = "disposal:openInventory", | ||||
|             icon = "fas fa-trash", | ||||
|             label = "Mülltonne öffnen", | ||||
|             action = function(entity) | ||||
|                 currentEntity = entity | ||||
|                 currentType = "trash" | ||||
|                 TriggerEvent('disposal:openInventory') | ||||
|             end, | ||||
|             canInteract = function() | ||||
|                 return true | ||||
|             end, | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     -- QB-Target für Schredder hinzufügen | ||||
|     -- Add target to shredder props | ||||
|     exports['qb-target']:AddTargetModel(shredderPropModels, { | ||||
|         options = shredderOptions, | ||||
|         options = { | ||||
|             { | ||||
|                 type = "client", | ||||
|                 event = "disposal:openInventory", | ||||
|                 icon = "fas fa-dumpster", | ||||
|                 label = "Müllschredder öffnen", | ||||
|                 action = function(entity) | ||||
|                     currentEntity = entity | ||||
|                     currentType = "shredder" | ||||
|                     TriggerEvent('disposal:openInventory') | ||||
|                 end, | ||||
|                 canInteract = function() | ||||
|                     return true | ||||
|                 end, | ||||
|             }, | ||||
|             { | ||||
|                 type = "client",  | ||||
|                 event = "disposal:openMenu", | ||||
|                 icon = "fas fa-fire", | ||||
|                 label = "Items vernichten", | ||||
|                 action = function(entity) | ||||
|                     currentEntity = entity | ||||
|                     currentType = "shredder" | ||||
|                     TriggerEvent('disposal:openMenu') | ||||
|                 end, | ||||
|                 canInteract = function() | ||||
|                     return true | ||||
|                 end, | ||||
|             } | ||||
|         }, | ||||
|         distance = 2.0 | ||||
|     }) | ||||
|      | ||||
|     -- QB-Target für Mülltonnen hinzufügen | ||||
|     -- Add target to trash bin props | ||||
|     exports['qb-target']:AddTargetModel(trashBinPropModels, { | ||||
|         options = trashOptions, | ||||
|         options = { | ||||
|             { | ||||
|                 type = "client", | ||||
|                 event = "disposal:openInventory", | ||||
|                 icon = "fas fa-trash", | ||||
|                 label = "Mülltonne öffnen", | ||||
|                 action = function(entity) | ||||
|                     currentEntity = entity | ||||
|                     currentType = "trash" | ||||
|                     TriggerEvent('disposal:openInventory') | ||||
|                 end, | ||||
|                 canInteract = function() | ||||
|                     return true | ||||
|                 end, | ||||
|             }, | ||||
|             { | ||||
|                 type = "client",  | ||||
|                 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 QB-Target zu " .. #shredderPropModels .. " Schredder-Modellen und " .. #trashBinPropModels .. " Mülltonnen-Modellen hinzugefügt") | ||||
|     print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models") | ||||
| end) | ||||
|  | ||||
| -- Funktion zum Abrufen der Container-ID aus der Entität | ||||
| -- Function to get container ID from entity | ||||
| function GetContainerIDFromEntity(entity, type) | ||||
|     if not entity or not DoesEntityExist(entity) then return nil end | ||||
|      | ||||
|  | @ -98,7 +106,7 @@ function GetContainerIDFromEntity(entity, type) | |||
|     return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z) | ||||
| end | ||||
|  | ||||
| -- Container-Inventar öffnen | ||||
| -- Open container inventory | ||||
| RegisterNetEvent('disposal:openInventory', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|  | @ -112,49 +120,46 @@ RegisterNetEvent('disposal:openInventory', function() | |||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Container-ID abrufen | ||||
|     -- Get container ID | ||||
|     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Inventar mit dieser eindeutigen ID öffnen | ||||
|     -- Open inventory with this unique ID | ||||
|     TriggerServerEvent('disposal:server:openInventory', containerID, currentType) | ||||
| end) | ||||
|  | ||||
| -- Vernichtungsmenü öffnen (nur für Schredder) | ||||
| -- Open disposal menu | ||||
| RegisterNetEvent('disposal:openMenu', function() | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|     if not currentEntity or not DoesEntityExist(currentEntity) or currentType ~= "shredder" 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 | ||||
|      | ||||
|     -- Container-ID abrufen | ||||
|     -- Get container ID | ||||
|     local containerID = GetContainerIDFromEntity(currentEntity, currentType) | ||||
|     if not containerID then return end | ||||
|      | ||||
|     -- Items in diesem Container abrufen | ||||
|     -- Get items in this container | ||||
|     TriggerServerEvent('disposal:server:getItems', containerID, currentType) | ||||
| end) | ||||
|  | ||||
| -- Menü mit Items anzeigen (nur für Schredder) | ||||
| -- Show menu with items | ||||
| RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining) | ||||
|     -- Nur für Schredder fortfahren | ||||
|     if type ~= "shredder" then return end | ||||
|      | ||||
|     -- Sicherstellen, dass items eine Tabelle ist | ||||
|     -- Make sure items is a table | ||||
|     items = items or {} | ||||
|      | ||||
|     -- Prüfen, ob items leer ist | ||||
|     -- Check if items is empty | ||||
|     if next(items) == nil then | ||||
|         lib.notify({ | ||||
|             title = 'Müllschredder', | ||||
|             description = 'Der Schredder 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 | ||||
|  | @ -162,23 +167,40 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, | |||
|      | ||||
|     local menuOptions = {} | ||||
|      | ||||
|     -- Alle Items vernichten Option | ||||
|     -- All items action option | ||||
|     local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN" | ||||
|     local actionDesc = type == "shredder"  | ||||
|         and 'Vernichtet alle Items im Schredder permanent!'  | ||||
|         or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!' | ||||
|      | ||||
|     table.insert(menuOptions, { | ||||
|         title = '🔥 ALLE ITEMS VERNICHTEN', | ||||
|         description = 'Vernichtet alle Items im Schredder permanent!', | ||||
|         icon = 'fire', | ||||
|         title = '🔥 ' .. actionText, | ||||
|         description = actionDesc, | ||||
|         icon = type == "shredder" and 'fire' or 'trash', | ||||
|         onSelect = function() | ||||
|             confirmDestroyAll(containerID) | ||||
|             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:', | ||||
|         disabled = true | ||||
|     }) | ||||
|      | ||||
|     -- Einzelne Items zum Menü hinzufügen | ||||
|     -- Add individual items to menu | ||||
|     local hasItems = false | ||||
|     for slot, item in pairs(items) do | ||||
|         if item and item.amount and item.amount > 0 then | ||||
|  | @ -188,7 +210,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, | |||
|                 description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot, | ||||
|                 icon = 'trash', | ||||
|                 onSelect = function() | ||||
|                     confirmDestroySingle(item.name, item.amount, slot, containerID) | ||||
|                     confirmDestroySingle(item.name, item.amount, slot, containerID, type) | ||||
|                 end | ||||
|             }) | ||||
|         end | ||||
|  | @ -196,8 +218,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, | |||
|      | ||||
|     if not hasItems then | ||||
|         lib.notify({ | ||||
|             title = 'Müllschredder', | ||||
|             description = 'Der Schredder 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 | ||||
|  | @ -205,25 +227,30 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, | |||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'disposal_menu', | ||||
|         title = '🗑️ Müllschredder Verwaltung', | ||||
|         title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung', | ||||
|         options = menuOptions | ||||
|     }) | ||||
|      | ||||
|     lib.showContext('disposal_menu') | ||||
| end) | ||||
|  | ||||
| -- Einzelnes Item vernichten bestätigen (nur für Schredder) | ||||
| function confirmDestroySingle(itemName, amount, slot, containerID) | ||||
| -- Confirm single item disposal | ||||
| function confirmDestroySingle(itemName, amount, slot, containerID, type) | ||||
|     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 entsorgt und nach Zeit gelöscht!') | ||||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'dispose_single_confirm', | ||||
|         title = '⚠️ Item vernichten?', | ||||
|         title = '⚠️ Item ' .. actionText .. '?', | ||||
|         options = { | ||||
|             { | ||||
|                 title = '🔥 Ja, vernichten', | ||||
|                 description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!', | ||||
|                 icon = 'fire', | ||||
|                 title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen', | ||||
|                 description = actionDesc, | ||||
|                 icon = 'check', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, "shredder") | ||||
|                     TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type) | ||||
|                 end | ||||
|             }, | ||||
|             { | ||||
|  | @ -231,7 +258,7 @@ function confirmDestroySingle(itemName, amount, slot, containerID) | |||
|                 description = 'Zurück zum Hauptmenü', | ||||
|                 icon = 'times', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:getItems', containerID, "shredder") | ||||
|                     TriggerServerEvent('disposal:server:getItems', containerID, type) | ||||
|                 end | ||||
|             } | ||||
|         } | ||||
|  | @ -240,18 +267,23 @@ function confirmDestroySingle(itemName, amount, slot, containerID) | |||
|     lib.showContext('dispose_single_confirm') | ||||
| end | ||||
|  | ||||
| -- Alle Items vernichten bestätigen (nur für Schredder) | ||||
| function confirmDestroyAll(containerID) | ||||
| -- Confirm all items disposal | ||||
| function confirmDestroyAll(containerID, type) | ||||
|     local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN" | ||||
|     local actionDesc = type == "shredder"  | ||||
|         and 'ALLE Items im Schredder werden permanent gelöscht!'  | ||||
|         or 'ALLE Items in der Mülltonne werden nach Zeit automatisch gelöscht!' | ||||
|      | ||||
|     lib.registerContext({ | ||||
|         id = 'dispose_all_confirm', | ||||
|         title = '⚠️ WARNUNG ⚠️', | ||||
|         options = { | ||||
|             { | ||||
|                 title = '🔥 JA, ALLES VERNICHTEN', | ||||
|                 description = 'ALLE Items im Schredder werden permanent gelöscht!', | ||||
|                 icon = 'fire', | ||||
|                 title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN', | ||||
|                 description = actionDesc, | ||||
|                 icon = type == "shredder" and 'fire' or 'trash', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:disposeAll', containerID, "shredder") | ||||
|                     TriggerServerEvent('disposal:server:disposeAll', containerID, type) | ||||
|                 end | ||||
|             }, | ||||
|             { | ||||
|  | @ -259,7 +291,7 @@ function confirmDestroyAll(containerID) | |||
|                 description = 'Zurück zum Hauptmenü', | ||||
|                 icon = 'times', | ||||
|                 onSelect = function() | ||||
|                     TriggerServerEvent('disposal:server:getItems', containerID, "shredder") | ||||
|                     TriggerServerEvent('disposal:server:getItems', containerID, type) | ||||
|                 end | ||||
|             } | ||||
|         } | ||||
|  | @ -268,7 +300,7 @@ function confirmDestroyAll(containerID) | |||
|     lib.showContext('dispose_all_confirm') | ||||
| end | ||||
|  | ||||
| -- Erfolgs-Notification mit Effekt | ||||
| -- Success notification with effect | ||||
| RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | ||||
|     lib.notify({ | ||||
|         title = type == "shredder" and 'Müllschredder' or 'Mülltonne', | ||||
|  | @ -277,7 +309,7 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | |||
|         duration = 4000 | ||||
|     }) | ||||
|      | ||||
|     -- Partikel-Effekt | ||||
|     -- Particle effect | ||||
|     local playerPed = PlayerPedId() | ||||
|     local coords = GetEntityCoords(playerPed) | ||||
|      | ||||
|  | @ -288,35 +320,14 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type) | |||
|      | ||||
|     UseParticleFxAssetNextCall("core") | ||||
|      | ||||
|     -- Unterschiedliche Effekte je nach Typ | ||||
|     -- Different effects for shredder vs trash | ||||
|     if type == "shredder" then | ||||
|         -- Intensiverer Effekt für Schredder | ||||
|         -- 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 | ||||
|         -- Subtiler Effekt für Mülltonnen | ||||
|         -- 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 | ||||
| end) | ||||
|  | ||||
| -- Informationen über zeitverzögerte Löschung anzeigen | ||||
| RegisterNetEvent('disposal:client:showTrashInfo', function(deleteTime) | ||||
|     local days = math.floor(deleteTime / 86400) | ||||
|     local hours = math.floor((deleteTime % 86400) / 3600) | ||||
|     local minutes = math.floor((deleteTime % 3600) / 60) | ||||
|      | ||||
|     local timeString = "" | ||||
|     if days > 0 then | ||||
|         timeString = days .. " Tag" .. (days > 1 and "e" or "") .. ", " | ||||
|     end | ||||
|     timeString = timeString .. hours .. " Stunde" .. (hours > 1 and "n" or "") .. ", " | ||||
|     timeString = timeString .. minutes .. " Minute" .. (minutes > 1 and "n" or "") | ||||
|      | ||||
|     lib.notify({ | ||||
|         title = 'Mülltonne', | ||||
|         description = 'Items werden in ' .. timeString .. ' automatisch gelöscht!', | ||||
|         type = 'info', | ||||
|         duration = 6000 | ||||
|     }) | ||||
| end) | ||||
|  |  | |||
|  | @ -1,22 +1,22 @@ | |||
| local QBCore = exports['qb-core']:GetCoreObject() | ||||
|  | ||||
| -- Tabelle zum Speichern von geplanten Löschungen | ||||
| -- Table to store items scheduled for deletion | ||||
| local scheduledDeletions = {} | ||||
|  | ||||
| -- Standard-Zeit für Mülltonnen-Löschung (2 Tage = 48 Stunden = 172800 Sekunden) | ||||
| -- Default time for trash bin deletion (2 days = 48 hours = 172800 seconds) | ||||
| local DEFAULT_TRASH_DELETE_TIME = 172800 -- seconds | ||||
|  | ||||
| -- Funktion zum Planen der Item-Löschung | ||||
| -- Function to schedule item deletion | ||||
| function ScheduleItemDeletion(containerID, deleteTime) | ||||
|     -- Standard-Löschzeit verwenden, wenn nicht angegeben | ||||
|     -- Use default time if not specified | ||||
|     deleteTime = deleteTime or DEFAULT_TRASH_DELETE_TIME | ||||
|      | ||||
|     -- Bestehenden Timer abbrechen, falls vorhanden | ||||
|     -- Cancel existing timer if there is one | ||||
|     if scheduledDeletions[containerID] and scheduledDeletions[containerID].timer then | ||||
|         clearTimeout(scheduledDeletions[containerID].timer) | ||||
|     end | ||||
|      | ||||
|     -- Löschung planen | ||||
|     -- Schedule the deletion | ||||
|     scheduledDeletions[containerID] = { | ||||
|         deleteAt = os.time() + deleteTime, | ||||
|         timer = setTimeout(function() | ||||
|  | @ -24,18 +24,16 @@ function ScheduleItemDeletion(containerID, deleteTime) | |||
|         end, deleteTime * 1000) | ||||
|     } | ||||
|      | ||||
|     print("^3[DISPOSAL]^7 Items in " .. containerID .. " werden in " .. deleteTime .. " Sekunden gelöscht") | ||||
|      | ||||
|     return deleteTime | ||||
|     print("^3[DISPOSAL]^7 Items in " .. containerID .. " scheduled for deletion in " .. deleteTime .. " seconds") | ||||
| end | ||||
|  | ||||
| -- Funktion zum Löschen von Items aus einer Mülltonne | ||||
| -- Function to delete items from a trash bin | ||||
| function DeleteTrashBinItems(containerID) | ||||
|     -- Alle Items in der Mülltonne abrufen | ||||
|     -- 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 Keine Items zum Löschen in " .. containerID) | ||||
|         print("^3[DISPOSAL]^7 No items to delete in " .. containerID) | ||||
|         scheduledDeletions[containerID] = nil | ||||
|         return | ||||
|     end | ||||
|  | @ -43,7 +41,7 @@ function DeleteTrashBinItems(containerID) | |||
|     local totalItems = 0 | ||||
|     local disposedItems = {} | ||||
|      | ||||
|     -- Alle Items löschen | ||||
|     -- 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) | ||||
|  | @ -52,22 +50,22 @@ function DeleteTrashBinItems(containerID) | |||
|         end | ||||
|     end | ||||
|      | ||||
|     print("^3[DISPOSAL]^7 Automatisch " .. totalItems .. " Items aus " .. containerID .. " gelöscht") | ||||
|     print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID) | ||||
|      | ||||
|     -- Log der automatischen Löschung | ||||
|     -- 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', 'Automatische Müllentsorgung', 'yellow',  | ||||
|     TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Automatic Trash Deletion', 'yellow',  | ||||
|         '**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList) | ||||
|      | ||||
|     -- Aus geplanten Löschungen entfernen | ||||
|     -- Remove from scheduled deletions | ||||
|     scheduledDeletions[containerID] = nil | ||||
| end | ||||
|  | ||||
| -- Verbleibende Zeit für eine geplante Löschung abrufen | ||||
| -- Get time remaining for a scheduled deletion | ||||
| function GetTimeRemaining(containerID) | ||||
|     if scheduledDeletions[containerID] then | ||||
|         local currentTime = os.time() | ||||
|  | @ -83,131 +81,121 @@ function GetTimeRemaining(containerID) | |||
|     return nil | ||||
| end | ||||
|  | ||||
| -- Container-Inventar öffnen | ||||
| -- 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 | ||||
|      | ||||
|     -- Inventar öffnen | ||||
|     -- 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' | ||||
|     }) | ||||
|      | ||||
|     -- Wenn es eine Mülltonne ist, nach Items prüfen und Löschung planen | ||||
|     if type == "trash" then | ||||
|         -- Kurze Verzögerung, um sicherzustellen, dass das Inventar geladen ist | ||||
|         SetTimeout(500, function() | ||||
|             -- Prüfen, ob Items in der Mülltonne sind | ||||
|             local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) | ||||
|             if items and next(items) then | ||||
|                 -- Nur planen, wenn noch nicht geplant | ||||
|                 if not scheduledDeletions[containerID] then | ||||
|                     local deleteTime = ScheduleItemDeletion(containerID) | ||||
|                      | ||||
|                     -- Spieler über die geplante Löschung informieren | ||||
|                     local days = math.floor(deleteTime / 86400) | ||||
|                     local hours = math.floor((deleteTime % 86400) / 3600) | ||||
|                     local minutes = math.floor((deleteTime % 3600) / 60) | ||||
|                      | ||||
|                     local timeString = "" | ||||
|                     if days > 0 then | ||||
|                         timeString = days .. " Tag" .. (days > 1 and "e" or "") .. ", " | ||||
|                     end | ||||
|                     timeString = timeString .. hours .. " Stunde" .. (hours > 1 and "n" or "") .. ", " | ||||
|                     timeString = timeString .. minutes .. " Minute" .. (minutes > 1 and "n" or "") | ||||
|                      | ||||
|                     TriggerClientEvent('disposal:client:showTrashInfo', src, deleteTime) | ||||
|                 else | ||||
|                     -- Wenn bereits geplant, verbleibende Zeit anzeigen | ||||
|                     local remainingTime = GetTimeRemaining(containerID) | ||||
|                     if remainingTime then | ||||
|                         TriggerClientEvent('disposal:client:showTrashInfo', src, remainingTime) | ||||
|                     end | ||||
|                 end | ||||
|             end | ||||
|         end) | ||||
|     -- 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) | ||||
|  | ||||
| -- Items aus Container abrufen (nur für Schredder) | ||||
| -- 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 | ||||
|      | ||||
|     -- Nur für Schredder fortfahren | ||||
|     if type ~= "shredder" then return end | ||||
|      | ||||
|     -- Items aus dem Container abrufen | ||||
|     -- Get items from the container | ||||
|     local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID) | ||||
|      | ||||
|     -- Wenn items nil ist, leere Tabelle bereitstellen | ||||
|     -- 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) | ||||
|  | ||||
| -- Einzelnes Item entsorgen (nur für Schredder) | ||||
| -- 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 | ||||
|      | ||||
|     -- Nur für Schredder fortfahren | ||||
|     if type ~= "shredder" then return end | ||||
|      | ||||
|     -- Item aus dem Container entfernen | ||||
|     -- Remove the item from the container | ||||
|     local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot) | ||||
|      | ||||
|     if success then | ||||
|         -- Log für Admins | ||||
|         print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') hat ' .. amount .. 'x ' .. itemName .. ' vernichtet') | ||||
|         -- 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', 'Item Vernichtet', 'orange',  | ||||
|             '**Spieler:** ' .. GetPlayerName(src) ..  | ||||
|         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**Aktion:** Item vernichtet') | ||||
|             '\n**Action:** ' .. (type == "shredder" and 'Item destroyed' or 'Item disposed')) | ||||
|          | ||||
|         TriggerClientEvent('disposal:client:itemDisposed', src, amount .. 'x ' .. itemName .. ' wurde vernichtet!', type) | ||||
|         -- 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 | ||||
|          | ||||
|         -- Menü neu laden | ||||
|         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') | ||||
|         TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error') | ||||
|     end | ||||
| end) | ||||
|  | ||||
| -- Alle Items entsorgen (nur für Schredder) | ||||
| -- 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 | ||||
|      | ||||
|     -- Nur für Schredder fortfahren | ||||
|     if type ~= "shredder" then return end | ||||
|      | ||||
|     -- Alle Items im Container abrufen | ||||
|     -- 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, 'Der Schredder ist bereits leer!', 'error') | ||||
|         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 | ||||
|      | ||||
|     -- Alle Items entsorgen | ||||
|     -- 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) | ||||
|  | @ -219,45 +207,50 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type) | |||
|     end | ||||
|      | ||||
|     if #disposedItems > 0 then | ||||
|         -- Log für Admins | ||||
|         print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') hat ALLE Items vernichtet (' .. totalItems .. ' Items)') | ||||
|         -- 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 mit Item-Liste | ||||
|         -- 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', 'Alle Items Vernichtet', 'red',  | ||||
|             '**Spieler:** ' .. GetPlayerName(src) ..  | ||||
|         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**Aktion:** Alle Items vernichtet' ..  | ||||
|             '\n**Anzahl Items:** ' .. totalItems ..  | ||||
|             '\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') ..  | ||||
|             '\n**Total Items:** ' .. totalItems ..  | ||||
|             '\n**Items:**\n' .. itemList) | ||||
|          | ||||
|         TriggerClientEvent('disposal:client:itemDisposed', src, 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!', type) | ||||
|     else | ||||
|         TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Vernichten gefunden!', 'error') | ||||
|     end | ||||
| end) | ||||
|  | ||||
| -- Export-Funktion, die von tgiann-inventory aufgerufen werden kann, wenn Items hinzugefügt werden | ||||
| exports('OnItemAddedToStash', function(stashId, itemName, amount, slot, metadata) | ||||
|     -- Prüfen, ob dies eine Mülltonne ist | ||||
|     if string.find(stashId, "trash_") then | ||||
|         -- Löschung planen, wenn noch nicht geplant | ||||
|         if not scheduledDeletions[stashId] then | ||||
|             ScheduleItemDeletion(stashId) | ||||
|             print("^3[DISPOSAL]^7 Timer für " .. stashId .. " gestartet, nachdem Item hinzugefügt wurde") | ||||
|         -- 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 | ||||
|     return true | ||||
| end) | ||||
|  | ||||
| -- Geplante Löschungen speichern, wenn die Ressource gestoppt wird | ||||
| -- 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] = { | ||||
|  | @ -266,15 +259,16 @@ AddEventHandler('onResourceStop', function(resourceName) | |||
|     end | ||||
|      | ||||
|     SaveResourceFile(GetCurrentResourceName(), "scheduled_deletions.json", json.encode(savedData), -1) | ||||
|     print("^3[DISPOSAL]^7 " .. #savedData .. " geplante Löschungen gespeichert") | ||||
|     print("^3[DISPOSAL]^7 Saved " .. #savedData .. " scheduled deletions") | ||||
| end) | ||||
|  | ||||
| -- Geplante Löschungen wiederherstellen, wenn die Ressource gestartet wird | ||||
| -- 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 "{}") | ||||
|     local restoredCount = 0 | ||||
|      | ||||
|     for containerID, data in pairs(savedData) do | ||||
|         local currentTime = os.time() | ||||
|  | @ -282,12 +276,11 @@ AddEventHandler('onResourceStart', function(resourceName) | |||
|          | ||||
|         if remainingTime > 0 then | ||||
|             ScheduleItemDeletion(containerID, remainingTime) | ||||
|             restoredCount = restoredCount + 1 | ||||
|         else | ||||
|             -- Wenn die Zeit bereits abgelaufen ist, sofort löschen | ||||
|             -- If the time has already passed, delete immediately | ||||
|             DeleteTrashBinItems(containerID) | ||||
|         end | ||||
|     end | ||||
|      | ||||
|     print("^3[DISPOSAL]^7 " .. restoredCount .. " geplante Löschungen wiederhergestellt") | ||||
|     print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions") | ||||
| end) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98