forked from Simnation/Main
62 lines
2.1 KiB
Lua
62 lines
2.1 KiB
Lua
![]() |
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)
|