Skip to content

Commit

Permalink
Merge pull request #572 from Qwerty1Verified/main
Browse files Browse the repository at this point in the history
fix(drops): prevent drop deletion if first slot is nil due to empty indexes
  • Loading branch information
GhzGarage authored Sep 6, 2024
2 parents f01081d + ff01fc4 commit e8c6805
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
37 changes: 18 additions & 19 deletions client/drops.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local holdingDrop = false
holdingDrop = false
local bagObject = nil
local heldDrop = nil
CurrentDrop = nil
Expand All @@ -7,24 +7,23 @@ CurrentDrop = nil

function GetDrops()
QBCore.Functions.TriggerCallback('qb-inventory:server:GetCurrentDrops', function(drops)
if drops then
for k, v in pairs(drops) do
local bag = NetworkGetEntityFromNetworkId(v.entityId)
if DoesEntityExist(bag) then
exports['qb-target']:AddTargetEntity(bag, {
options = {
{
icon = 'fas fa-backpack',
label = Lang:t('menu.o_bag'),
action = function()
TriggerServerEvent('qb-inventory:server:openDrop', k)
CurrentDrop = dropId
end,
},
if not drops then return end
for k, v in pairs(drops) do
local bag = NetworkGetEntityFromNetworkId(v.entityId)
if DoesEntityExist(bag) then
exports['qb-target']:AddTargetEntity(bag, {
options = {
{
icon = 'fas fa-backpack',
label = Lang:t('menu.o_bag'),
action = function()
TriggerServerEvent('qb-inventory:server:openDrop', k)
CurrentDrop = k
end,
},
distance = 2.5,
})
end
},
distance = 2.5,
})
end
end
end)
Expand Down Expand Up @@ -59,7 +58,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId)
label = 'Pick up bag',
action = function()
if IsPedArmed(PlayerPedId(), 4) then
return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500)
return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500)
end
if holdingDrop then
return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500)
Expand Down
1 change: 1 addition & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
QBCore = exports['qb-core']:GetCoreObject()
PlayerData = nil
local hotbarShown = false

-- Handlers
Expand Down
9 changes: 8 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,18 @@ QBCore.Functions.CreateCallback('qb-inventory:server:createDrop', function(sourc
local bag = CreateObjectNoOffset(Config.ItemDropObject, playerCoords.x + 0.5, playerCoords.y + 0.5, playerCoords.z, true, true, false)
local dropId = NetworkGetNetworkIdFromEntity(bag)
local newDropId = 'drop-' .. dropId
local itemsTable = setmetatable({ item }, {
__len = function(t)
local length = 0
for _ in pairs(t) do length += 1 end
return length
end
})
if not Drops[newDropId] then
Drops[newDropId] = {
name = newDropId,
label = 'Drop',
items = { item },
items = itemsTable,
entityId = dropId,
createdTime = os.time(),
coords = playerCoords,
Expand Down

0 comments on commit e8c6805

Please sign in to comment.