ed
This commit is contained in:
parent
92d275a753
commit
683833a326
4 changed files with 293 additions and 0 deletions
61
resources/[inventory]/nordi_trashcan/client.lua
Normal file
61
resources/[inventory]/nordi_trashcan/client.lua
Normal file
|
@ -0,0 +1,61 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- Variable to store the current entity being interacted with
|
||||
local currentEntity = nil
|
||||
|
||||
-- Add QB-Target to all matching props in the world
|
||||
Citizen.CreateThread(function()
|
||||
-- Add target to trash can props
|
||||
exports['qb-target']:AddTargetModel(Config.TrashCanModels, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "trash:openInventory",
|
||||
icon = "fas fa-dumpster",
|
||||
label = "Mülltonne öffnen",
|
||||
action = function(entity)
|
||||
currentEntity = entity
|
||||
TriggerEvent('trash:openInventory')
|
||||
end,
|
||||
canInteract = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
|
||||
print("^2[TRASH-SYSTEM]^7 Added QB-Target to " .. #Config.TrashCanModels .. " trash can models")
|
||||
end)
|
||||
|
||||
-- Function to get container ID from entity
|
||||
function GetContainerIDFromEntity(entity)
|
||||
if not entity or not DoesEntityExist(entity) then return nil end
|
||||
|
||||
local model = GetEntityModel(entity)
|
||||
local entityCoords = GetEntityCoords(entity)
|
||||
return "trashcan" .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
||||
end
|
||||
|
||||
-- Open container inventory
|
||||
RegisterNetEvent('trash:openInventory', function()
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||
lib.notify(Config.Notifications.noTrashCanFound)
|
||||
return
|
||||
end
|
||||
|
||||
-- Get container ID
|
||||
local containerID = GetContainerIDFromEntity(currentEntity)
|
||||
if not containerID then return end
|
||||
|
||||
-- Open inventory with this unique ID
|
||||
TriggerServerEvent('trash:server:openInventory', containerID)
|
||||
end)
|
||||
|
||||
-- Notification when trash is emptied (can be triggered by server)
|
||||
RegisterNetEvent('trash:client:notifyEmptied', function()
|
||||
lib.notify(Config.Notifications.trashCanEmptied)
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue