mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
move paychecks
This commit is contained in:
+2
-1
@@ -30,7 +30,8 @@ server_scripts {
|
|||||||
'server/commands.lua',
|
'server/commands.lua',
|
||||||
'server/exports.lua',
|
'server/exports.lua',
|
||||||
'server/debug.lua',
|
'server/debug.lua',
|
||||||
'server/editor.lua'
|
'server/editor.lua',
|
||||||
|
'server/paychecks.lua'
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_page 'html/index.html'
|
ui_page 'html/index.html'
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ QBCore.Commands.Add('tp', Lang:t('command.tp.help'), { { name = Lang:t('command.
|
|||||||
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
|
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local location = QBShared.Locations[args[1]]
|
local location = QBCore.Shared.Locations[args[1]]
|
||||||
if location then
|
if location then
|
||||||
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, location.x, location.y, location.z, location.w)
|
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, location.x, location.y, location.z, location.w)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -389,39 +389,6 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
|
|||||||
return veh
|
return veh
|
||||||
end
|
end
|
||||||
|
|
||||||
function PaycheckInterval()
|
|
||||||
if not next(QBCore.Players) then
|
|
||||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for _, Player in pairs(QBCore.Players) do
|
|
||||||
if not Player then return end
|
|
||||||
local payment = QBShared.Jobs[Player.PlayerData.job.name]['grades'][tostring(Player.PlayerData.job.grade.level)].payment
|
|
||||||
if not payment then payment = Player.PlayerData.job.payment end
|
|
||||||
if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then
|
|
||||||
if QBCore.Config.Money.PayCheckSociety then
|
|
||||||
local account = exports['qb-banking']:GetAccountBalance(Player.PlayerData.job.name)
|
|
||||||
if account ~= 0 then
|
|
||||||
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
|
|
||||||
Player.Functions.AddMoney('bank', payment, 'paycheck')
|
|
||||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', { value = payment }))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Callback Functions --
|
-- Callback Functions --
|
||||||
|
|
||||||
---Trigger Client Callback
|
---Trigger Client Callback
|
||||||
@@ -827,6 +794,3 @@ for functionName, func in pairs(QBCore.Functions) do
|
|||||||
exports(functionName, func)
|
exports(functionName, func)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Access a specific function directly:
|
|
||||||
-- exports['qb-core']:Notify(source, 'Hello Player!')
|
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
local function givePlayerBank(player, amount)
|
||||||
|
player.Functions.AddMoney('bank', amount, 'paycheck')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function notify(player, langKey, amount)
|
||||||
|
TriggerClientEvent(
|
||||||
|
'QBCore:Notify',
|
||||||
|
player.PlayerData.source,
|
||||||
|
Lang:t(langKey, { value = amount }),
|
||||||
|
'success'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function payFromSociety(player, amount)
|
||||||
|
local acctName = player.PlayerData.job.name
|
||||||
|
local balance = exports['qb-banking']:GetAccountBalance(acctName)
|
||||||
|
if balance >= amount then
|
||||||
|
exports['qb-banking']:RemoveMoney(acctName, amount, 'Employee Paycheck')
|
||||||
|
givePlayerBank(player, amount)
|
||||||
|
notify(player, 'info.received_paycheck', amount)
|
||||||
|
elseif balance > 0 then
|
||||||
|
TriggerClientEvent('QBCore:Notify', player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
|
||||||
|
else
|
||||||
|
givePlayerBank(player, amount)
|
||||||
|
notify(player, 'info.received_paycheck', amount)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handlePaycheck(player, amount)
|
||||||
|
if QBCore.Config.Money.PayCheckSociety then
|
||||||
|
payFromSociety(player, amount)
|
||||||
|
else
|
||||||
|
givePlayerBank(player, amount)
|
||||||
|
notify(player, 'info.received_paycheck', amount)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shouldReceivePay(player)
|
||||||
|
local jobDef = QBCore.Shared.Jobs[player.PlayerData.job.name]
|
||||||
|
local onDuty = player.PlayerData.job.onduty
|
||||||
|
return jobDef.offDutyPay or onDuty
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getPlayerPayment(player)
|
||||||
|
local jobDef = QBCore.Shared.Jobs[player.PlayerData.job.name]
|
||||||
|
local gradeDef = jobDef.grades[tostring(player.PlayerData.job.grade.level)]
|
||||||
|
return gradeDef.payment or player.PlayerData.job.payment or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function isPlayerValid(player)
|
||||||
|
if not player or not player.PlayerData or not player.PlayerData.job then
|
||||||
|
print(('Paycheck: invalid player data (source=%s)'):format(
|
||||||
|
tostring(player and player.PlayerData and player.PlayerData.source or 'nil')
|
||||||
|
))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local jobName = player.PlayerData.job.name
|
||||||
|
local jobDef = QBCore.Shared.Jobs[jobName]
|
||||||
|
if not jobDef then
|
||||||
|
print(("Paycheck: tried paying for job '%s' that doesn't exist"):format(jobName))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local gradeLevel = tostring(player.PlayerData.job.grade.level)
|
||||||
|
local gradeDef = jobDef.grades[gradeLevel]
|
||||||
|
if not gradeDef then
|
||||||
|
print(("Paycheck: tried paying for job '%s' with invalid grade '%s'"):format(jobName, gradeLevel))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ProcessAllPaychecks()
|
||||||
|
for _, player in pairs(QBCore.Players) do
|
||||||
|
if isPlayerValid(player) then
|
||||||
|
local payment = getPlayerPayment(player)
|
||||||
|
if payment > 0 and shouldReceivePay(player) then
|
||||||
|
handlePaycheck(player, payment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
local interval = QBCore.Config.Money.PayCheckTimeOut * 60 * 1000
|
||||||
|
while true do
|
||||||
|
Wait(interval)
|
||||||
|
ProcessAllPaychecks()
|
||||||
|
end
|
||||||
|
end)
|
||||||
@@ -584,5 +584,3 @@ function QBCore.Player.GetFirstSlotByItem(items, itemName)
|
|||||||
if GetResourceState('qb-inventory') == 'missing' then return end
|
if GetResourceState('qb-inventory') == 'missing' then return end
|
||||||
return exports['qb-inventory']:GetFirstSlotByItem(items, itemName)
|
return exports['qb-inventory']:GetFirstSlotByItem(items, itemName)
|
||||||
end
|
end
|
||||||
|
|
||||||
PaycheckInterval() -- This starts the paycheck system
|
|
||||||
|
|||||||
Reference in New Issue
Block a user