1
0
Fork 0
forked from Simnation/Main

Update client.lua

This commit is contained in:
Nordi98 2025-07-27 21:54:10 +02:00
parent 75219990cf
commit dfe7a276b1

View file

@ -14,12 +14,13 @@ local shredderPropModels = {
'prop_dumpster_3a'
}
-- Variable to store the current entity being interacted with
local currentShredderEntity = nil
-- Add QB-Target to all matching props in the world
Citizen.CreateThread(function()
-- Add target to all existing props
for _, model in ipairs(shredderPropModels) do
local modelHash = GetHashKey(model)
-- Add QB-Target to this model
exports['qb-target']:AddTargetModel(model, {
options = {
@ -28,6 +29,10 @@ Citizen.CreateThread(function()
event = "shredder:openInventory",
icon = "fas fa-dumpster",
label = "Müllschredder öffnen",
action = function(entity)
currentShredderEntity = entity
TriggerEvent('shredder:openInventory')
end,
canInteract = function()
return true
end,
@ -37,6 +42,10 @@ Citizen.CreateThread(function()
event = "shredder:openMenu",
icon = "fas fa-fire",
label = "Items vernichten",
action = function(entity)
currentShredderEntity = entity
TriggerEvent('shredder:openMenu')
end,
canInteract = function()
return true
end,
@ -49,15 +58,21 @@ Citizen.CreateThread(function()
print("^2[SHREDDER]^7 Added QB-Target to " .. #shredderPropModels .. " shredder prop models")
end)
-- Function to get shredder ID from entity
function GetShredderIDFromEntity(entity)
if not entity or not DoesEntityExist(entity) then return nil end
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
return "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
end
-- Schredder Inventar öffnen
RegisterNetEvent('shredder:openInventory', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
-- Get the entity player is targeting
local entity = exports['qb-target']:GetCurrentEntity()
if not entity or not DoesEntityExist(entity) then
if not currentShredderEntity or not DoesEntityExist(currentShredderEntity) then
lib.notify({
title = 'Müllschredder',
description = 'Kein Schredder gefunden!',
@ -66,10 +81,9 @@ RegisterNetEvent('shredder:openInventory', function()
return
end
-- Get entity model and position for unique ID
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
-- Get shredder ID
local shredderID = GetShredderIDFromEntity(currentShredderEntity)
if not shredderID then return end
-- Open inventory with this unique ID
TriggerServerEvent('shredder:server:openInventory', shredderID)
@ -80,10 +94,7 @@ RegisterNetEvent('shredder:openMenu', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
-- Get the entity player is targeting
local entity = exports['qb-target']:GetCurrentEntity()
if not entity or not DoesEntityExist(entity) then
if not currentShredderEntity or not DoesEntityExist(currentShredderEntity) then
lib.notify({
title = 'Müllschredder',
description = 'Kein Schredder gefunden!',
@ -92,17 +103,16 @@ RegisterNetEvent('shredder:openMenu', function()
return
end
-- Get entity model and position for unique ID
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
-- Get shredder ID
local shredderID = GetShredderIDFromEntity(currentShredderEntity)
if not shredderID then return end
-- Get items in this shredder
TriggerServerEvent('shredder:server:getItems', shredderID)
end)
-- Menü mit Items anzeigen
RegisterNetEvent('shredder:client:showMenu', function(items)
RegisterNetEvent('shredder:client:showMenu', function(items, shredderID)
if not items or #items == 0 then
lib.notify({
title = 'Müllschredder',
@ -120,7 +130,7 @@ RegisterNetEvent('shredder:client:showMenu', function(items)
description = 'Vernichtet alle Items im Schredder permanent!',
icon = 'fire',
onSelect = function()
confirmDestroyAll()
confirmDestroyAll(shredderID)
end
})
@ -138,7 +148,7 @@ RegisterNetEvent('shredder:client:showMenu', function(items)
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
icon = 'trash',
onSelect = function()
confirmDestroySingle(item.name, item.amount, slot)
confirmDestroySingle(item.name, item.amount, slot, shredderID)
end
})
end
@ -154,7 +164,7 @@ RegisterNetEvent('shredder:client:showMenu', function(items)
end)
-- Einzelnes Item vernichten bestätigen
function confirmDestroySingle(itemName, amount, slot)
function confirmDestroySingle(itemName, amount, slot, shredderID)
lib.registerContext({
id = 'shred_single_confirm',
title = '⚠️ Item vernichten?',
@ -164,32 +174,16 @@ function confirmDestroySingle(itemName, amount, slot)
description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
icon = 'check',
onSelect = function()
-- Get the entity player is targeting for the unique ID
local entity = exports['qb-target']:GetCurrentEntity()
if entity and DoesEntityExist(entity) then
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
TriggerServerEvent('shredder:server:destroySingle', itemName, amount, slot, shredderID)
end
end
},
{
title = '❌ Abbrechen',
description = 'Zurück zum Hauptmenü',
icon = 'times',
onSelect = function()
-- Get the entity player is targeting for the unique ID
local entity = exports['qb-target']:GetCurrentEntity()
if entity and DoesEntityExist(entity) then
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
TriggerServerEvent('shredder:server:getItems', shredderID)
end
end
}
}
})
@ -198,7 +192,7 @@ function confirmDestroySingle(itemName, amount, slot)
end
-- Alle Items vernichten bestätigen
function confirmDestroyAll()
function confirmDestroyAll(shredderID)
lib.registerContext({
id = 'shred_all_confirm',
title = '⚠️ WARNUNG ⚠️',
@ -208,32 +202,16 @@ function confirmDestroyAll()
description = 'ALLE Items im Schredder werden permanent gelöscht!',
icon = 'fire',
onSelect = function()
-- Get the entity player is targeting for the unique ID
local entity = exports['qb-target']:GetCurrentEntity()
if entity and DoesEntityExist(entity) then
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
TriggerServerEvent('shredder:server:destroyAll', shredderID)
end
end
},
{
title = '❌ Abbrechen',
description = 'Zurück zum Hauptmenü',
icon = 'times',
onSelect = function()
-- Get the entity player is targeting for the unique ID
local entity = exports['qb-target']:GetCurrentEntity()
if entity and DoesEntityExist(entity) then
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
local shredderID = "shredder_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
TriggerServerEvent('shredder:server:getItems', shredderID)
end
end
}
}
})