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