From 1777aaec5bce126ac95eb284e98117291c477342 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Wed, 15 Feb 2023 12:10:59 +1100 Subject: [PATCH] fix(client/qb): actually add up item totals --- client/framework/qb.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/framework/qb.lua b/client/framework/qb.lua index bd90a99..6826848 100644 --- a/client/framework/qb.lua +++ b/client/framework/qb.lua @@ -17,10 +17,12 @@ local playerItems = setmetatable({}, { }) local function setPlayerItems() + if not playerData?.items then return end + table.wipe(playerItems) - + for _, item in pairs(playerData.items) do - playerItems[item.name] = item.amount + playerItems[item.name] = (playerItems[item.name] or 0) + item.amount end end @@ -28,7 +30,7 @@ if usingOxInventory then AddEventHandler('ox_inventory:itemCount', function(name, count) playerItems[name] = count end) -elseif next(playerData) then +else setPlayerItems() end @@ -39,8 +41,10 @@ end) RegisterNetEvent('QBCore:Player:SetPlayerData', function(val) if source == '' then return end + playerData = val - if not usingOxInventory and playerData.items then setPlayerItems() end + + if not usingOxInventory then setPlayerItems() end end) function PlayerHasGroups(filter)