90 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
	
		
			3 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)
 | |
| 
 | |
| -- Get the trash can the player is looking at (for admin command)
 | |
| RegisterNetEvent('trash:client:getTargetTrashCan', function()
 | |
|     local playerPed = PlayerPedId()
 | |
|     local coords = GetEntityCoords(playerPed)
 | |
|     local found = false
 | |
|     
 | |
|     -- Check if we're looking at a trash can
 | |
|     if currentEntity and DoesEntityExist(currentEntity) then
 | |
|         local model = GetEntityModel(currentEntity)
 | |
|         
 | |
|         -- Check if this model is in our trash can list
 | |
|         for _, trashModel in ipairs(Config.TrashCanModels) do
 | |
|             if model == GetHashKey(trashModel) then
 | |
|                 found = true
 | |
|                 break
 | |
|             end
 | |
|         end
 | |
|         
 | |
|         if found then
 | |
|             local containerID = GetContainerIDFromEntity(currentEntity)
 | |
|             TriggerServerEvent('trash:server:fillTargetTrashCan', containerID)
 | |
|         else
 | |
|             lib.notify(Config.Notifications.noTrashCanFound)
 | |
|         end
 | |
|     else
 | |
|         lib.notify(Config.Notifications.noTrashCanFound)
 | |
|     end
 | |
| end)
 | 
