From 234d0798206df7dd9968958cdcc9f0b6af7417fe Mon Sep 17 00:00:00 2001 From: Mycroft Date: Wed, 7 Sep 2022 18:31:22 +0100 Subject: [PATCH] Experimental - refactor(es_extended):change accounts to handle index within its object this should correct the behaviour when working with ESX within v8 --- [esx]/es_extended/server/classes/player.lua | 14 +++++++------- [esx]/es_extended/server/main.lua | 10 ++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/[esx]/es_extended/server/classes/player.lua b/[esx]/es_extended/server/classes/player.lua index 32ad4e12..071cce15 100644 --- a/[esx]/es_extended/server/classes/player.lua +++ b/[esx]/es_extended/server/classes/player.lua @@ -109,7 +109,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, function self.getAccount(account) for i=1, #self.accounts do if self.accounts[i].name == account then - return self.accounts[i], i + return self.accounts[i] end end end @@ -177,11 +177,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, return end if money >= 0 then - local account, index = self.getAccount(accountName) + local account = self.getAccount(accountName) if account then money = account.round and ESX.Math.Round(money) or money - self.accounts[index].money = money + self.accounts[account.index].money = money self.triggerEvent('esx:setAccountMoney', account) else @@ -198,10 +198,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, return end if money > 0 then - local account, index = self.getAccount(accountName) + local account = self.getAccount(accountName) if account then money = account.round and ESX.Math.Round(money) or money - self.accounts[index].money += money + self.accounts[account.index].money += money self.triggerEvent('esx:setAccountMoney', account) else @@ -218,11 +218,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, return end if money > 0 then - local account, index = self.getAccount(accountName) + local account = self.getAccount(accountName) if account then money = account.round and ESX.Math.Round(money) or money - self.accounts[index].money -= money + self.accounts[account.index].money -= money self.triggerEvent('esx:setAccountMoney', account) else diff --git a/[esx]/es_extended/server/main.lua b/[esx]/es_extended/server/main.lua index 7ca0a701..2a46a02f 100644 --- a/[esx]/es_extended/server/main.lua +++ b/[esx]/es_extended/server/main.lua @@ -131,8 +131,14 @@ function loadESXPlayer(identifier, playerId, isNew) if data.round == nil then data.round = true end - userData.accounts[#userData.accounts + 1] = {name = account, money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0, - label = data.label, round = data.round} + local index = #userData.accounts + 1 + userData.accounts[index] = { + name = account, + money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0, + label = data.label, + round = data.round, + index = index + } end -- Job