From 9a251cd160c5ab88c0b1962c035cdd31670cc04b Mon Sep 17 00:00:00 2001 From: bmf1418 Date: Sat, 1 Jan 2022 15:18:32 -0600 Subject: [PATCH] Add paychecks from society account Added config option for paychecks to be taken from society account when the player is employed by a society. --- config.lua | 1 + server/functions.lua | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.lua b/config.lua index 201b599..f870cb6 100644 --- a/config.lua +++ b/config.lua @@ -9,6 +9,7 @@ QBConfig.Money = {} QBConfig.Money.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! QBConfig.Money.DontAllowMinus = { 'cash', 'crypto' } -- Money that is not allowed going in minus QBConfig.Money.PayCheckTimeOut = 10 -- The time in minutes that it will give the paycheck +QBConfig.Money.PayCheckSociety = true -- If true paycheck will come from the society account that the player is employed at, requires qb-bossmenu QBConfig.Player = {} QBConfig.Player.MaxWeight = 120000 -- Max weight a player can carry (currently 120kg, written in grams) diff --git a/server/functions.lua b/server/functions.lua index 8dad406..49f4b77 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -186,8 +186,25 @@ function PaycheckLoop() for _, Player in pairs(Players) do local payment = Player.PlayerData.job.payment if Player.PlayerData.job and payment > 0 and (QBShared.Jobs[Player.PlayerData.job.name].offDutyPay or Player.PlayerData.job.onduty) then - Player.Functions.AddMoney('bank', payment) - TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment)) + if QBCore.Config.Money.PayCheckSociety then + QBCore.Functions.TriggerCallback('qb-bossmenu:server:GetAccount', Player.PlayerData.source, function(account) + if account ~= 0 then -- Checks if player is employed by a society + if account < payment then -- Checks if company has enough money to pay society + TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, 'The company you\'re employeed at is too poor to pay out your salary') + else + Player.Functions.AddMoney('bank', payment) + TriggerEvent('qb-bossmenu:server:removeAccountMoney', Player.PlayerData.job.name, payment) + TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment)) + end + else + Player.Functions.AddMoney('bank', payment) + TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment)) + end + end, Player.PlayerData.job.name) + else + Player.Functions.AddMoney('bank', payment) + TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment)) + end end end SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckLoop)