From 91a0cadad7e6e549daf03bbd66ea807bf5df61b8 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Wed, 13 Jul 2022 18:09:08 +0100 Subject: [PATCH] Polcharge Commission now taken from society charge --- server.lua | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/server.lua b/server.lua index be01c30..01beaf1 100644 --- a/server.lua +++ b/server.lua @@ -22,9 +22,9 @@ RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller, gang) if biller then -- If this is found, it ISN'T a phone payment, so add money to society here if gang then if Config.Manage then exports["qb-management"]:AddGangMoney(tostring(biller.PlayerData.gang.name), data.amount) - if Config.Debug then print("^5Debug^7: ^3QB-Management^7(^3Gang^7): ^2Adding ^7$^6"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.gang.name).."^7' ($^6"..exports["qb-management"]:GetGangAccount(biller.PlayerData.gang.name).."^7)") end + if Config.Debug then print("^5Debug^7: ^3QB^7-^3Management^7(^3Gang^7): ^2Adding ^7$^6"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.gang.name).."^7' ($^6"..exports["qb-management"]:GetGangAccount(biller.PlayerData.gang.name).."^7)") end else TriggerEvent("qb-gangmenu:server:addAccountMoney", tostring(biller.PlayerData.gang.name), data.amount) - if Config.Debug then print("^5Debug^7: ^3QB-GangMenu^7: ^2Adding ^7$^6"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.gang.name).."^7'") end + if Config.Debug then print("^5Debug^7: ^3QB^7-^3GangMenu^7: ^2Adding ^7$^6"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.gang.name).."^7'") end end elseif not gang then if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount) @@ -173,40 +173,43 @@ RegisterServerEvent("jim-payments:server:PolCharge", function(citizen, price) local src = source local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) - if tonumber(price) and tonumber(price) > 0 then + local price = math.floor(tonumber(price)) + if price > 0 then if not Config.FineJobConfirmation then - billed.Functions.RemoveMoney("bank", math.floor(tonumber(price))) - local commission = (tonumber(price) * Config.FineJobs[biller.PlayerData.job.name].Commission) - biller.Functions.AddMoney("bank", math.floor(commission)) + if billed.Functions.AddMoney("bank", price) then if Config.Debug then print("^5Debug^7: ^3PolCharge^7 - ^2Player^7(^6"..billed.PlayerData.source.."^7) ^2charged ^7$^6"..price.."^7") end end + local commission = math.floor(price * Config.FineJobs[biller.PlayerData.job.name].Commission) + if biller.Functions.AddMoney("bank", commission) then if Config.Debug then print("^5Debug^7: ^3PolCharge^7 - ^2Commission of ^7$^6"..commission.." ^2sent to Player^7(^6"..biller.PlayerData.source.."^7)") end end if Config.Manage then - exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), price) - if Config.Debug then print("^5Debug^7: ^6QB-Management^7(^4Job^7): ^2Adding ^7$^6"..price.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end + exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), (price - commission)) + if Config.Debug then print("^5Debug^7: ^3QB^7-^3Management^7(^3Job^7): ^2Adding ^7$^6"..(price - commission).." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7' ($^6"..exports["qb-management"]:GetAccount(biller.PlayerData.job.name).."^7)") end else - TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), price) - if Config.Debug then print("^5Debug^7: ^6QB-BossMenu^7: ^2Adding ^7$^6"..price.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end + TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), (price - commission)) + if Config.Debug then print("^5Debug^7: ^3QB^7-^3BossMenu^7: ^2Adding ^7$^6"..(price - commission).." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end end - TriggerClientEvent('QBCore:Notify', src, billed.PlayerData.charinfo.firstname.." was charged for $"..tonumber(price), "success") - TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'You were charged for $'..tonumber(price)) + TriggerClientEvent('QBCore:Notify', src, billed.PlayerData.charinfo.firstname.." was charged for $"..(price - commission), "success") + TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'You were charged for $'..(price - commission)) else - TriggerClientEvent("jim-payments:client:PolPopup", billed.PlayerData.source, tonumber(price), src, biller.PlayerData.job.label) + TriggerClientEvent("jim-payments:client:PolPopup", billed.PlayerData.source, (price - commission), src, biller.PlayerData.job.label) end else TriggerClientEvent('QBCore:Notify', source, "You can't charge $0", 'error') return end end) + RegisterServerEvent("jim-payments:server:PolPopup", function(data) local src = source local billed = QBCore.Functions.GetPlayer(src) local biller = QBCore.Functions.GetPlayer(tonumber(data.biller)) + data.amount = math.floor(data.amount) if data.accept == true then - billed.Functions.RemoveMoney("bank", data.amount) + if billed.Functions.AddMoney("bank", data.amount) then if Config.Debug then print("^5Debug^7: ^3PolCharge^7 - ^2Player^7(^6"..billed.PlayerData.source.."^7) ^2charged 7$^6"..data.amount.."^7") end end TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." accepted the $"..data.amount.." charge", "success") - local commission = (tonumber(data.amount) * Config.FineJobs[biller.PlayerData.job.name].Commission) - if biller.Functions.AddMoney("bank", math.floor(commission)) then if Config.Debug then print("^5Debug^7: ^6PolCharge^7 - ^4Commission ^2 of ^7$^6"..commission.." ^2sent to Player^7(^6"..biller.PlayerData.source.."^7)") end end + local commission = math.floor(tonumber(data.amount) * Config.FineJobs[biller.PlayerData.job.name].Commission) + if biller.Functions.AddMoney("bank", commission) then if Config.Debug then print("^5Debug^7: ^3PolCharge^7 - ^2Commission ^2 of ^7$^6"..commission.." ^2sent to Player^7(^6"..biller.PlayerData.source.."^7)") end end if Config.Manage then - exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount) - if Config.Debug then print("^5Debug^7: ^6QB-Management^7(^4Job^7): ^2Adding ^7$^6"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end + exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount - commission) + if Config.Debug then print("^5Debug^7: ^3QB^7-^3Management^7(^3Job^7): ^2Adding ^7$^6"..data.amount - commission.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7' ($^6"..exports["qb-management"]:GetAccount(biller.PlayerData.job.name).."^7)") end else - TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount) - if Config.Debug then print("^5Debug^7: ^6QB-BossMenu^7: ^2Adding ^6$^7"..data.amount.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end + TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount - commission) + if Config.Debug then print("^5Debug^7: ^3QB^7-^3BossMenu^7: ^2Adding ^6$^7"..data.amount - commission.." ^2to account ^7'^6"..tostring(biller.PlayerData.job.name).."^7'") end end else TriggerClientEvent("QBCore:Notify", src, "You declined the payment")