Experimental - refactor(es_extended):change accounts to handle index within its object

this should correct the behaviour when working with ESX within v8
This commit is contained in:
Mycroft
2022-09-07 18:31:22 +01:00
parent 1ded3628bf
commit 234d079820
2 changed files with 15 additions and 9 deletions
+7 -7
View File
@@ -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
+8 -2
View File
@@ -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