mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
feat: es_extended - allow decimals in accounts
This commit is contained in:
@@ -2,9 +2,18 @@ Config = {}
|
||||
Config.Locale = 'en'
|
||||
|
||||
Config.Accounts = {
|
||||
bank = _U('account_bank'),
|
||||
black_money = _U('account_black_money'),
|
||||
money = _U('account_money')
|
||||
bank = {
|
||||
label = _U('account_bank'),
|
||||
round = true
|
||||
},
|
||||
black_money = {
|
||||
label = _U('account_black_money'),
|
||||
round = true
|
||||
},
|
||||
money = {
|
||||
label = _U('account_money'),
|
||||
round = true
|
||||
}
|
||||
}
|
||||
|
||||
Config.StartingAccountMoney = {bank = 50000}
|
||||
|
||||
@@ -107,9 +107,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.getAccount(account)
|
||||
for k,v in ipairs(self.accounts) do
|
||||
if v.name == account then
|
||||
return v
|
||||
for i=1, #self.accounts do
|
||||
if self.accounts[i].name == account then
|
||||
return self.accounts[i], i
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -172,41 +172,64 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
function self.setAccountMoney(accountName, money)
|
||||
if not tonumber(money) then
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
return
|
||||
end
|
||||
if money >= 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
local account, index = self.getAccount(accountName)
|
||||
|
||||
if account then
|
||||
local newMoney = ESX.Math.Round(money)
|
||||
account.money = newMoney
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[index].money = money
|
||||
|
||||
self.triggerEvent('esx:setAccountMoney', account)
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId))
|
||||
end
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
end
|
||||
end
|
||||
|
||||
function self.addAccountMoney(accountName, money)
|
||||
if not tonumber(money) then
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
return
|
||||
end
|
||||
if money > 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
|
||||
local account, index = self.getAccount(accountName)
|
||||
if account then
|
||||
local newMoney = account.money + ESX.Math.Round(money)
|
||||
account.money = newMoney
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[index].money = money
|
||||
|
||||
self.triggerEvent('esx:setAccountMoney', account)
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId))
|
||||
end
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
end
|
||||
end
|
||||
|
||||
function self.removeAccountMoney(accountName, money)
|
||||
if not tonumber(money) then
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
return
|
||||
end
|
||||
if money > 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
local account, index = self.getAccount(accountName)
|
||||
|
||||
if account then
|
||||
local newMoney = account.money - ESX.Math.Round(money)
|
||||
account.money = newMoney
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[index].money = money
|
||||
|
||||
self.triggerEvent('esx:setAccountMoney', account)
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!'):format(accountName, self.playerId))
|
||||
end
|
||||
else
|
||||
print(('[^1ERROR^7] Tried To Set Account ^5%s^0 For Player ^5%s^0 To An Invalid Number!'):format(accountName, self.playerId))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -135,11 +135,15 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
end
|
||||
end
|
||||
|
||||
for account, label in pairs(Config.Accounts) do
|
||||
for account, data in pairs(Config.Accounts) do
|
||||
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 = label
|
||||
label = data.label,
|
||||
round = data.round
|
||||
}
|
||||
end
|
||||
|
||||
@@ -432,9 +436,9 @@ if not Config.OxInventory then
|
||||
targetXPlayer.addAccountMoney(itemName, itemCount)
|
||||
|
||||
sourceXPlayer.showNotification(_U('gave_account_money', ESX.Math.GroupDigits(itemCount),
|
||||
Config.Accounts[itemName], targetXPlayer.name))
|
||||
Config.Accounts[itemName].label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(_U('received_account_money', ESX.Math.GroupDigits(itemCount),
|
||||
Config.Accounts[itemName], sourceXPlayer.name))
|
||||
Config.Accounts[itemName].label, sourceXPlayer.name))
|
||||
else
|
||||
sourceXPlayer.showNotification(_U('imp_invalid_amount'))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user