diff --git a/client/drops.lua b/client/drops.lua index 10c8a3788..b59045c29 100644 --- a/client/drops.lua +++ b/client/drops.lua @@ -32,6 +32,14 @@ end -- Events +RegisterNetEvent('qb-inventory:client:removeDropTarget', function(dropId) + while not NetworkDoesNetworkIdExist(dropId) do Wait(10) end + local bag = NetworkGetEntityFromNetworkId(dropId) + while not DoesEntityExist(bag) do Wait(10) end + --Run exsport to remove entity target bag + exports['qb-target']:RemoveTargetEntity(bag) +end) + RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId) while not NetworkDoesNetworkIdExist(dropId) do Wait(10) end local bag = NetworkGetEntityFromNetworkId(dropId) @@ -51,29 +59,32 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId) icon = 'fas fa-hand-pointer', label = 'Pick up bag', action = function() - AttachEntityToEntity( - bag, - PlayerPedId(), - GetPedBoneIndex(PlayerPedId(), Config.ItemDropObjectBone), - Config.ItemDropObjectOffset[1].x, - Config.ItemDropObjectOffset[1].y, - Config.ItemDropObjectOffset[1].z, - Config.ItemDropObjectOffset[2].x, - Config.ItemDropObjectOffset[2].y, - Config.ItemDropObjectOffset[2].z, - true, true, false, true, 1, true - ) - bagObject = bag - holdingDrop = true - heldDrop = newDropId - exports['qb-core']:DrawText('Press [G] to drop the bag') + if not holdingDrop then + AttachEntityToEntity( + bag, + PlayerPedId(), + GetPedBoneIndex(PlayerPedId(), Config.ItemDropObjectBone), + Config.ItemDropObjectOffset[1].x, + Config.ItemDropObjectOffset[1].y, + Config.ItemDropObjectOffset[1].z, + Config.ItemDropObjectOffset[2].x, + Config.ItemDropObjectOffset[2].y, + Config.ItemDropObjectOffset[2].z, + true, true, false, true, 1, true + ) + bagObject = bag + holdingDrop = true + heldDrop = newDropId + exports['qb-core']:DrawText('Press [G] to drop the bag') + else + QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500) + end end, } }, distance = 2.5, }) end) - -- NUI Callbacks RegisterNUICallback('DropItem', function(item, cb) diff --git a/server/main.lua b/server/main.lua index 508476e0d..d9e0f4012 100644 --- a/server/main.lua +++ b/server/main.lua @@ -159,6 +159,13 @@ RegisterNetEvent('qb-inventory:server:closeInventory', function(inventory) end if Drops[inventory] then Drops[inventory].isOpen = false + if #Drops[inventory].items == 0 and not Drops[inventory].isOpen then -- if no listeed items in the drop on close + TriggerClientEvent('qb-inventory:client:removeDropTarget', -1, Drops[inventory].entityId) + Wait(500) + local entity = NetworkGetEntityFromNetworkId(Drops[inventory].entityId) + if DoesEntityExist(entity) then DeleteEntity(entity) end + Drops[inventory] = nil + end return end if not Inventories[inventory] then return end