From d10f3a60da240ac2b513a95d9c3289129ecc0ffe Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 11:50:17 -0700 Subject: [PATCH 1/2] fix(drops): drop deletion due to incorrect table length with empty indexes --- server/main.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/main.lua b/server/main.lua index 6aff6530..e613fd3c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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, From ff01fc467db51dfccefcf529f988d9ecdd4ded60 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 6 Sep 2024 12:35:22 -0700 Subject: [PATCH 2/2] chore(lint): fix unused and inacessible variables --- client/drops.lua | 37 ++++++++++++++++++------------------- client/main.lua | 1 + 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/drops.lua b/client/drops.lua index 69a23de0..298d75e7 100644 --- a/client/drops.lua +++ b/client/drops.lua @@ -1,4 +1,4 @@ -local holdingDrop = false +holdingDrop = false local bagObject = nil local heldDrop = nil CurrentDrop = nil @@ -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) @@ -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) diff --git a/client/main.lua b/client/main.lua index 161ecd7b..5d675ffa 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,4 +1,5 @@ QBCore = exports['qb-core']:GetCoreObject() +PlayerData = nil local hotbarShown = false -- Handlers