From 670d0c4b7fc2afcbbd40418f059a3ad0beb1647c Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:31:27 +0100 Subject: [PATCH 1/2] feat(es_extended/server/modules/paycheck): add offDuty pay --- .../es_extended/server/modules/paycheck.lua | 34 ++++++++++--------- [core]/es_extended/shared/config/main.lua | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/[core]/es_extended/server/modules/paycheck.lua b/[core]/es_extended/server/modules/paycheck.lua index 4bba19487..5a78cc364 100644 --- a/[core]/es_extended/server/modules/paycheck.lua +++ b/[core]/es_extended/server/modules/paycheck.lua @@ -6,61 +6,63 @@ function StartPayCheck() local jobLabel = xPlayer.job.label local job = xPlayer.job.grade_name local salary = xPlayer.job.grade_salary - + local onDuty = xPlayer.job.onDuty + local effectiveSalary = (job == "unemployed" or onDuty) and salary or ESX.Math.Round(salary * Config.OffDutyPaycheckMultiplier) + if xPlayer.paycheckEnabled then - if salary > 0 then + if effectiveSalary > 0 then if job == "unemployed" then -- unemployed - xPlayer.addAccountMoney("bank", salary, "Welfare Check") - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", salary), "CHAR_BANK_MAZE", 9) + xPlayer.addAccountMoney("bank", effectiveSalary, "Welfare Check") + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", effectiveSalary), "CHAR_BANK_MAZE", 9) if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - Unemployment Benefits", "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = salary, inline = true }, + { name = "Amount", value = effectiveSalary, inline = true }, }) end 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, "Paycheck") - account.removeMoney(salary) + if account.money >= effectiveSalary then -- does the society money to pay its employees? + xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") + account.removeMoney(effectiveSalary) if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = salary, inline = true }, + { name = "Amount", value = effectiveSalary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) else TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), "", TranslateCap("company_nomoney"), "CHAR_BANK_MAZE", 1) end end) else -- not a society - xPlayer.addAccountMoney("bank", salary, "Paycheck") + xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = salary, inline = true }, + { name = "Amount", value = effectiveSalary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) end end) else -- generic job - xPlayer.addAccountMoney("bank", salary, "Paycheck") + xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - Generic", "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = salary, inline = true }, + { name = "Amount", value = effectiveSalary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) end end end diff --git a/[core]/es_extended/shared/config/main.lua b/[core]/es_extended/shared/config/main.lua index f769f758e..5d37450af 100644 --- a/[core]/es_extended/shared/config/main.lua +++ b/[core]/es_extended/shared/config/main.lua @@ -44,6 +44,7 @@ Config.SaveDeathStatus = true -- Save the death status of a player Config.EnableDebug = false -- Use Debug options? Config.DefaultJobDuty = true -- A players default duty status when changing jobs +Config.OffDutyPaycheckMultiplier = 0.5 -- The multiplier for off duty paychecks. 0.5 = 50% of the on duty paycheck Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing" Config.Identity = true -- Select a character identity data before they have loaded in (this happens by default with multichar) From de96c066ed94a968110c7fede65561e1dd3da074 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:42:11 +0100 Subject: [PATCH 2/2] fix(es_extended/server/modules/paycheck): stick to salary var --- .../es_extended/server/modules/paycheck.lua | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/[core]/es_extended/server/modules/paycheck.lua b/[core]/es_extended/server/modules/paycheck.lua index 5a78cc364..98049fe8b 100644 --- a/[core]/es_extended/server/modules/paycheck.lua +++ b/[core]/es_extended/server/modules/paycheck.lua @@ -5,64 +5,63 @@ function StartPayCheck() for player, xPlayer in pairs(Core.Players) do local jobLabel = xPlayer.job.label local job = xPlayer.job.grade_name - local salary = xPlayer.job.grade_salary local onDuty = xPlayer.job.onDuty - local effectiveSalary = (job == "unemployed" or onDuty) and salary or ESX.Math.Round(salary * Config.OffDutyPaycheckMultiplier) - + local salary = (job == "unemployed" or onDuty) and xPlayer.job.grade_salary or ESX.Math.Round(xPlayer.job.grade_salary * Config.OffDutyPaycheckMultiplier) + if xPlayer.paycheckEnabled then - if effectiveSalary > 0 then + if salary > 0 then if job == "unemployed" then -- unemployed - xPlayer.addAccountMoney("bank", effectiveSalary, "Welfare Check") - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", effectiveSalary), "CHAR_BANK_MAZE", 9) + xPlayer.addAccountMoney("bank", salary, "Welfare Check") + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_help", salary), "CHAR_BANK_MAZE", 9) if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - Unemployment Benefits", "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = effectiveSalary, inline = true }, + { name = "Amount", value = salary, inline = true }, }) end 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 >= effectiveSalary then -- does the society money to pay its employees? - xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") - account.removeMoney(effectiveSalary) + if account.money >= salary then -- does the society money to pay its employees? + xPlayer.addAccountMoney("bank", salary, "Paycheck") + account.removeMoney(salary) if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = effectiveSalary, inline = true }, + { name = "Amount", value = salary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) else TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), "", TranslateCap("company_nomoney"), "CHAR_BANK_MAZE", 1) end end) else -- not a society - xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") + xPlayer.addAccountMoney("bank", salary, "Paycheck") if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - " .. jobLabel, "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = effectiveSalary, inline = true }, + { name = "Amount", value = salary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) end end) else -- generic job - xPlayer.addAccountMoney("bank", effectiveSalary, "Paycheck") + xPlayer.addAccountMoney("bank", salary, "Paycheck") if Config.LogPaycheck then ESX.DiscordLogFields("Paycheck", "Paycheck - Generic", "green", { { name = "Player", value = xPlayer.name, inline = true }, { name = "ID", value = xPlayer.source, inline = true }, - { name = "Amount", value = effectiveSalary, inline = true }, + { name = "Amount", value = salary, inline = true }, }) end - TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", effectiveSalary), "CHAR_BANK_MAZE", 9) + TriggerClientEvent("esx:showAdvancedNotification", player, TranslateCap("bank"), TranslateCap("received_paycheck"), TranslateCap("received_salary", salary), "CHAR_BANK_MAZE", 9) end end end