diff --git a/resources/[inventory]/nordi_schredder/client.lua b/resources/[inventory]/nordi_schredder/client.lua index 1a61e4c23..014368be3 100644 --- a/resources/[inventory]/nordi_schredder/client.lua +++ b/resources/[inventory]/nordi_schredder/client.lua @@ -29,31 +29,15 @@ Citizen.CreateThread(function() options = { { type = "client", - event = "disposal:openInventory", + event = "disposal:openShredderInventory", 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", + event = "disposal:openShredderMenu", 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 @@ -64,31 +48,15 @@ Citizen.CreateThread(function() options = { { type = "client", - event = "disposal:openInventory", + event = "disposal:openStorageInventory", icon = "fas fa-box-open", label = "Lager öffnen", - action = function(entity) - currentEntity = entity - currentType = "trash" - TriggerEvent('disposal:openInventory') - end, - canInteract = function() - return true - end, }, { type = "client", - event = "disposal:openMenu", + event = "disposal:openStorageMenu", icon = "fas fa-archive", label = "Items lagern", - action = function(entity) - currentEntity = entity - currentType = "trash" - TriggerEvent('disposal:openMenu') - end, - canInteract = function() - return true - end, } }, distance = 2.0 @@ -106,48 +74,164 @@ function GetContainerIDFromEntity(entity, type) return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z) end --- Open container inventory -RegisterNetEvent('disposal:openInventory', function() +-- Open shredder inventory +RegisterNetEvent('disposal:openShredderInventory', function() local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) - if not currentEntity or not DoesEntityExist(currentEntity) then + -- 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 = currentType == "shredder" and 'Müllschredder' or 'Lager', - description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!', + title = 'Müllschredder', + description = 'Kein Schredder gefunden!', type = 'error' }) return end -- Get container ID - local containerID = GetContainerIDFromEntity(currentEntity, currentType) + local containerID = GetContainerIDFromEntity(closestEntity, "shredder") if not containerID then return end -- Open inventory with this unique ID - TriggerServerEvent('disposal:server:openInventory', containerID, currentType) + TriggerServerEvent('disposal:server:openInventory', containerID, "shredder") end) --- Open disposal menu -RegisterNetEvent('disposal:openMenu', function() +-- Open storage inventory +RegisterNetEvent('disposal:openStorageInventory', function() local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) - if not currentEntity or not DoesEntityExist(currentEntity) then + -- 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 = currentType == "shredder" and 'Müllschredder' or 'Lager', - description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!', + title = 'Lager', + description = 'Kein Lager gefunden!', type = 'error' }) return end -- Get container ID - local containerID = GetContainerIDFromEntity(currentEntity, currentType) + 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") if not containerID then return end -- Get items in this container - TriggerServerEvent('disposal:server:getItems', containerID, currentType) + 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") end) -- Show menu with items