From d4693d3ad917d585b8d3b82d25c09d045b5d298c Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 17:10:21 +0200 Subject: [PATCH 1/5] fix: amount is nil in `GetTotalWeight` --- server/functions.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/functions.lua b/server/functions.lua index 9cea1e8f1..b526f2156 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -219,7 +219,12 @@ function GetTotalWeight(items) if not items then return 0 end local weight = 0 for _, item in pairs(items) do - weight = weight + (item.weight * item.amount) + local amount = item.amount + if type(amount) ~= "number" then + amount = 1 + end + + weight = weight + (item.weight * amount) end return tonumber(weight) end From db531504fadd0127e1a1e027f8d8d7f22222b814 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 15:34:38 +0000 Subject: [PATCH 2/5] fix: `accessing undefined variable 'PlayerData'` --- client/main.lua | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/client/main.lua b/client/main.lua index 0b7153785..4ce20f885 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,5 +1,6 @@ QBCore = exports['qb-core']:GetCoreObject() local hotbarShown = false +local PlayerData = nil -- Handlers @@ -11,7 +12,7 @@ end) RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() LocalPlayer.state:set('inv_busy', true, true) - PlayerData = {} + PlayerData = nil end) RegisterNetEvent('QBCore:Client:UpdateObject', function() @@ -78,19 +79,21 @@ function HasItem(items, amount) for _ in pairs(items) do totalItems = totalItems + 1 end end - for _, itemData in pairs(PlayerData.items) do - if isTable then - for k, v in pairs(items) do - if itemData and itemData.name == (isArray and v or k) and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then - count = count + 1 - if count == totalItems then - return true + if PlayerData and type(PlayerData.items) == "table" then + for _, itemData in pairs(PlayerData.items) do + if isTable then + for k, v in pairs(items) do + if itemData and itemData.name == (isArray and v or k) and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then + count = count + 1 + if count == totalItems then + return true + end end end - end - else -- Single item as string - if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then - return true + else -- Single item as string + if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then + return true + end end end end @@ -137,9 +140,14 @@ RegisterNetEvent('qb-inventory:client:closeInv', function() end) RegisterNetEvent('qb-inventory:client:updateInventory', function() + local items = {} + if PlayerData and type(PlayerData.items) == "table" then + items = PlayerData.items + end + SendNUIMessage({ action = 'update', - inventory = PlayerData.items + inventory = items }) end) @@ -298,9 +306,11 @@ end, false) for i = 1, 5 do RegisterCommand('slot_' .. i, function() - local itemData = PlayerData.items[i] - if not itemData then return end - TriggerServerEvent('qb-inventory:server:useItem', itemData) + if PlayerData and type(PlayerData.items) == "table" then + local itemData = PlayerData.items[i] + if not itemData then return end + TriggerServerEvent('qb-inventory:server:useItem', itemData) + end end, false) RegisterKeyMapping('slot_' .. i, Lang:t('inf_mapping.use_item') .. i, 'keyboard', i) end From 0810aef5716a8912c2687cee8cfa336ba2b5ddd8 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 15:47:18 +0000 Subject: [PATCH 3/5] fix: accessing undefined variable 'dropId' --- client/drops.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/drops.lua b/client/drops.lua index 10c8a3788..b63a8fa8d 100644 --- a/client/drops.lua +++ b/client/drops.lua @@ -18,7 +18,7 @@ function GetDrops() label = Lang:t('menu.o_bag'), action = function() TriggerServerEvent('qb-inventory:server:openDrop', k) - CurrentDrop = dropId + CurrentDrop = k end, }, }, From 3df176354d10c97a51d007dff8c16b3cdf439222 Mon Sep 17 00:00:00 2001 From: Zerio Date: Thu, 30 May 2024 18:55:45 +0000 Subject: [PATCH 4/5] fix: lint & lua issues --- client/drops.lua | 12 ++++++------ client/main.lua | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/drops.lua b/client/drops.lua index 00c341bfb..c39095ca2 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 @@ -59,9 +59,9 @@ 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 + if HoldingDrop then return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500) end AttachEntityToEntity( @@ -77,7 +77,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId) true, true, false, true, 1, true ) bagObject = bag - holdingDrop = true + HoldingDrop = true heldDrop = newDropId exports['qb-core']:DrawText('Press [G] to drop the bag') end, @@ -109,7 +109,7 @@ end) CreateThread(function() while true do - if holdingDrop then + if HoldingDrop then if IsControlJustPressed(0, 47) then DetachEntity(bagObject, true, true) local coords = GetEntityCoords(PlayerPedId()) @@ -119,7 +119,7 @@ CreateThread(function() FreezeEntityPosition(bagObject, true) exports['qb-core']:HideText() TriggerServerEvent('qb-inventory:server:updateDrop', heldDrop, coords) - holdingDrop = false + HoldingDrop = false bagObject = nil heldDrop = nil end diff --git a/client/main.lua b/client/main.lua index 540a79d03..fa5d26e44 100644 --- a/client/main.lua +++ b/client/main.lua @@ -309,7 +309,7 @@ for i = 1, 5 do local itemData = PlayerData.items[i] if not itemData then return end if itemData.type == "weapon" then - if holdingDrop then + if HoldingDrop then return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500) end end From 5d781264ea3d47abe39e685855b7c68f821c1361 Mon Sep 17 00:00:00 2001 From: Zerio Date: Tue, 5 Nov 2024 22:46:25 +0100 Subject: [PATCH 5/5] fix: incorrect `PlayerData` variable assignal --- client/main.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 0646f5876..7481b5a70 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,7 +1,6 @@ QBCore = exports['qb-core']:GetCoreObject() PlayerData = nil local hotbarShown = false -local PlayerData = nil -- Handlers