mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 10:01:28 +00:00
refactor(esx/server): Replace recursive functions with loops; removed functions from the ESX object
These should never be called outside of ESX, so there's no reason to include them
This commit is contained in:
@@ -18,6 +18,13 @@ function getSharedObject()
|
||||
return ESX
|
||||
end
|
||||
|
||||
local function StartDBSync()
|
||||
Citizen.CreateThread(function()
|
||||
Citizen.Wait(10 * 60 * 1000)
|
||||
ESX.SavePlayers()
|
||||
end)
|
||||
end
|
||||
|
||||
MySQL.ready(function()
|
||||
MySQL.Async.fetchAll('SELECT * FROM items', {}, function(result)
|
||||
for k,v in ipairs(result) do
|
||||
@@ -54,8 +61,8 @@ MySQL.ready(function()
|
||||
end
|
||||
ESX.Jobs = Jobs
|
||||
print('[^2INFO^7] ESX ^5Legacy^0 initialized')
|
||||
ESX.StartDBSync()
|
||||
ESX.StartPayCheck()
|
||||
StartDBSync()
|
||||
StartPayCheck()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -239,15 +239,6 @@ ESX.SavePlayers = function(cb)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.StartDBSync = function()
|
||||
function saveData()
|
||||
ESX.SavePlayers()
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
end
|
||||
|
||||
SetTimeout(10 * 60 * 1000, saveData)
|
||||
end
|
||||
|
||||
ESX.GetPlayers = function()
|
||||
local sources = {}
|
||||
|
||||
|
||||
@@ -1,44 +1,40 @@
|
||||
ESX.StartPayCheck = function()
|
||||
function payCheck()
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
StartPayCheck = function()
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(Config.PaycheckInterval)
|
||||
local xPlayers = ESX.GetExtendedPlayers()
|
||||
for _, xPlayer in pairs(xPlayers) do
|
||||
local job = xPlayer.job.grade_name
|
||||
local salary = xPlayer.job.grade_salary
|
||||
|
||||
for i=1, #xPlayers, 1 do
|
||||
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
|
||||
local job = xPlayer.job.grade_name
|
||||
local salary = xPlayer.job.grade_salary
|
||||
if salary > 0 then
|
||||
if job == 'unemployed' then -- unemployed
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
|
||||
elseif Config.EnableSocietyPayouts then -- possibly a society
|
||||
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
|
||||
if society ~= nil then -- verified society
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
|
||||
if account.money >= salary then -- does the society money to pay its employees?
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
account.removeMoney(salary)
|
||||
|
||||
if salary > 0 then
|
||||
if job == 'unemployed' then -- unemployed
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
|
||||
elseif Config.EnableSocietyPayouts then -- possibly a society
|
||||
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
|
||||
if society ~= nil then -- verified society
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
|
||||
if account.money >= salary then -- does the society money to pay its employees?
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
account.removeMoney(salary)
|
||||
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
else
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
|
||||
end
|
||||
end)
|
||||
else -- not a society
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end)
|
||||
else -- generic job
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
else
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
|
||||
end
|
||||
end)
|
||||
else -- not a society
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end)
|
||||
else -- generic job
|
||||
xPlayer.addAccountMoney('bank', salary)
|
||||
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
SetTimeout(Config.PaycheckInterval, payCheck)
|
||||
end
|
||||
|
||||
SetTimeout(Config.PaycheckInterval, payCheck)
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user