From 4f2b9a8efe4f335603c8474e6ea02882b76a6569 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:18:10 +1100 Subject: [PATCH] refactor(client/esx): tweaks when using ox_inventory Don't call setPlayerData or set a metatable. Wipe items on playerLoaded. --- client/framework/esx.lua | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/client/framework/esx.lua b/client/framework/esx.lua index 55c42ea..c63bf80 100644 --- a/client/framework/esx.lua +++ b/client/framework/esx.lua @@ -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 @@ -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)