1
0
Fork 0
forked from Simnation/Main

Update client.lua

This commit is contained in:
Nordi98 2025-07-28 01:50:57 +02:00
parent b960315876
commit 001c206759

View file

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