Skip to content

Commit

Permalink
refactor(client/esx): tweaks when using ox_inventory
Browse files Browse the repository at this point in the history
Don't call setPlayerData or set a metatable. Wipe items on playerLoaded.
  • Loading branch information
thelindat committed Feb 22, 2023
1 parent 61c1d23 commit 4f2b9a8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions client/framework/esx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PlayerItems = {}

local function setPlayerData(playerData)
if playerData.inventory then
table.wipe(PlayerItems)

for _, v in pairs(playerData.inventory) do
if v.count > 0 then
PlayerItems[v.name] = v.count
Expand All @@ -27,22 +29,13 @@ end
SetTimeout(0, function()
local ESX = exports.es_extended:getSharedObject()

if ESX.PlayerLoaded then
if ESX.PlayerLoaded and not usingOxInventory then
setPlayerData(ESX.PlayerData)
end

if usingOxInventory then
setmetatable(PlayerItems, {
__index = function(self, index)
self[index] = exports.ox_inventory:Search('count', index) or 0
return self[index]
end
})
end
end)

RegisterNetEvent('esx:playerLoaded', function(data)
if source == '' then return end
if source == '' or usingOxInventory then return end
setPlayerData(data)
end)

Expand Down

0 comments on commit 4f2b9a8

Please sign in to comment.