mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 17:01:16 +00:00
Run paychecks in async thread and fix society check
Move the paycheck loop into a CreateThread to avoid blocking the main thread and prevent paychecks from stopping. Add a nil guard for Player and keep existing payment lookup logic. Tighten society payroll logic: check the society account balance before removing funds and still pay employees if the account is zero, avoiding duplicate AddMoney/Notify branches. Add a short Wait(50) between player iterations to yield. Preserve the existing SetTimeout scheduling for the next paycheck run.
This commit is contained in:
+22
-18
@@ -405,31 +405,35 @@ function PaycheckInterval()
|
|||||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
|
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for _, Player in pairs(QBCore.Players) do
|
CreateThread(function()
|
||||||
if not Player then return end
|
for _, Player in pairs(QBCore.Players) do
|
||||||
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
if Player then
|
||||||
if not payment then payment = Player.PlayerData.job.payment end
|
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
||||||
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
if not payment then payment = Player.PlayerData.job.payment end
|
||||||
if QBCore.Config.Money.PayCheckSociety then
|
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
||||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
if QBCore.Config.Money.PayCheckSociety then
|
||||||
if account ~= 0 then
|
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
||||||
if account < payment then
|
if account ~= 0 then
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
if account < payment then
|
||||||
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
||||||
|
else
|
||||||
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
|
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
|
||||||
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
||||||
exports['qb-banking']:RemoveMoney(Player.PlayerData.job.name, payment, 'Employee Paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
||||||
end
|
end
|
||||||
else
|
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
|
||||||
end
|
end
|
||||||
else
|
Wait(50)
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
|
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user