Skip to content

Commit

Permalink
fix(client/qb): get item count on start
Browse files Browse the repository at this point in the history
playerItems was not being set on script start, only when triggering
SetPlayerData.
  • Loading branch information
thelindat committed Oct 28, 2022
1 parent e226a50 commit 76b797f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions client/framework/qb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@ local usingOxInventory = GetResourceState('ox_inventory') ~= "missing"

local playerItems = setmetatable({}, {
__index = function(self, index)
self[index] = usingOxInventory and exports.ox_inventory:Search('count', index) or exports['qb-inventory']:HasItem(index) or 0
self[index] = usingOxInventory and exports.ox_inventory:Search('count', index) or playerData.items[index] or 0
return self[index]
end
})

local function setPlayerItems()
for _, item in pairs(playerData.items) do
playerItems[item.name] = item.amount
end
end

if usingOxInventory then
AddEventHandler('ox_inventory:itemCount', function(name, count)
playerItems[name] = count
end)
elseif playerData then
setPlayerItems()
end

AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
playerData = QBCore.Functions.GetPlayerData()
if not usingOxInventory then setPlayerItems() end
end)

RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
if source == '' then return end

playerData = val

if usingOxInventory then return end

for _, v in pairs(val.items) do
if v then playerItems[v.name] = v.amount end
end
if not usingOxInventory then setPlayerItems() end
end)

function PlayerHasGroups(filter)
Expand Down

0 comments on commit 76b797f

Please sign in to comment.