Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(config/server): extract paycheck function to config #522

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return {
moneyTypes = { cash = 500, bank = 5000, crypto = 0 }, -- type = startamount - Add or remove money types for your server (for ex. blackmoney = 0), remember once added it will not be removed from the database!
dontAllowMinus = { 'cash', 'crypto' }, -- Money that is not allowed going in minus
paycheckTimeout = 10, -- The time in minutes that it will give the paycheck
paycheckSociety = false -- If true paycheck will come from the society account that the player is employed at, requires qb-management
paycheckSociety = false -- If true paycheck will come from the society account that the player is employed at
},

player = {
Expand Down Expand Up @@ -124,4 +124,12 @@ return {
removeSocietyMoney = function(accountName, payment)
return exports['Renewed-Banking']:removeAccountMoney(accountName, payment)
end,

---Paycheck function
---@param player Player Player object
---@param payment number Payment amount
sendPaycheck = function (player, payment)
player.Functions.AddMoney('bank', payment)
Notify(player.PlayerData.source, locale('info.received_paycheck', payment))
end,
}
11 changes: 3 additions & 8 deletions server/loops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,26 @@ CreateThread(function()
end
end)

local function sendPaycheck(player, payment)
player.Functions.AddMoney('bank', payment)
Notify(player.PlayerData.source, locale('info.received_paycheck', payment))
end

local function pay(player)
local job = player.PlayerData.job
local payment = GetJob(job.name).grades[job.grade.level].payment or job.payment
if payment <= 0 then return end
if not GetJob(job.name).offDutyPay and not job.onduty then return end
if not config.money.paycheckSociety then
sendPaycheck(player, payment)
config.sendPaycheck(player, payment)
return
end
local account = config.getSocietyAccount(job.name)
if not account or account == 0 then -- Checks if player is employed by a society
sendPaycheck(player, payment)
config.sendPaycheck(player, payment)
return
end
if account < payment then -- Checks if company has enough money to pay society
Notify(player.PlayerData.source, locale('error.company_too_poor'), 'error')
return
end
config.removeSocietyMoney(job.name, payment)
sendPaycheck(player, payment)
config.sendPaycheck(player, payment)
end

CreateThread(function()
Expand Down