Files
jim-payments/server/polchargeserver.lua

103 lines
4.0 KiB
Lua
Raw Normal View History

2025-02-21 13:54:49 +00:00
registerCommand("polcharge", {
2025-02-22 13:23:43 +00:00
locale("command", "charge"), {}, false,
2025-02-21 13:54:49 +00:00
function(source)
TriggerClientEvent(getScript()..":client:PolCharge", source)
end
})
2024-01-28 12:27:47 +00:00
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:PolCharge", function(citizen, price)
2024-01-28 12:27:47 +00:00
local src = source
2025-02-21 13:54:49 +00:00
local biller = getPlayer(src)
local billed = getPlayer(tonumber(citizen))
2024-01-28 12:27:47 +00:00
local price = math.floor(tonumber(price))
2025-02-21 13:54:49 +00:00
local commPercent = Config.PolCharge.FineJobs[biller.job] and Config.PolCharge.FineJobs[biller.job].Commission or 0.25
if Config.PolCharge.FineJobs[biller.job] then
commPercent = Config.PolCharge.FineJobs[biller.job].Commission
2024-01-28 12:27:47 +00:00
else
commPercent = 0.25
print("^3Warning^7: ^2Can't find player's job in ^7'Config.Polcharge.FineJobs', ^2defaulting to 0.25 (25% commission)^7")
2024-01-28 12:27:47 +00:00
end
local commission = math.floor(price * commPercent)
print(commission)
2024-01-28 12:27:47 +00:00
if price > 0 then
if not Config.PolCharge.FineJobConfirmation then
polCharge({
biller = biller,
billed = billed,
price = price,
commission = commission,
2025-02-21 13:54:49 +00:00
billerJob = tostring(biller.job),
2024-01-28 12:27:47 +00:00
amountChange = (price - commission)
})
2025-02-22 13:23:43 +00:00
triggerNotify(nil, billed.firstname..locale("success", "charged")..(price - commission), "success", src)
triggerNotify(nil, locale("success", "you_charged")..(price - commission), nil, billed.source)
2024-01-28 12:27:47 +00:00
else
2025-02-21 13:54:49 +00:00
TriggerClientEvent(getScript()..":client:PolPopup", billed.source, price, src, biller.job, commPercent)
2024-01-28 12:27:47 +00:00
end
2025-02-22 13:23:43 +00:00
else triggerNotify(nil, locale("error", "charge_zero"), 'error', source) return end
2024-01-28 12:27:47 +00:00
end)
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:PolPopup", function(data)
2024-01-28 12:27:47 +00:00
local src = source
2025-02-21 13:54:49 +00:00
local billed = getPlayer(src)
local biller = getPlayer(tonumber(data.biller))
2024-01-28 12:27:47 +00:00
local price = math.floor(data.amount)
local commission = math.floor(tonumber(data.amount) * data.commPercent)
if data.accept then
polCharge({
biller = biller,
billed = billed,
price = price,
commission = commission,
2025-02-21 13:54:49 +00:00
billerJob = tostring(biller.job),
2024-01-28 12:27:47 +00:00
amountChange = (price - commission)
})
elseif not data.accept then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error", "declined_payment"), nil, src)
triggerNotify(nil, billed.PlayerData.charinfo.firstname.." declined the $"..data.amount..locale("success", "charge_end"), "error", data.biller)
2024-01-28 12:27:47 +00:00
end
end)
function polCharge(data)
2025-02-21 13:54:49 +00:00
local billedSource, billerSource, newAmount = data.billed.source, data.biller.source, 0
local bankScript = nil
chargePlayer(data.price, "bank", billedSource)
debugPrint("^5Debug^7: ^3PolCharge^7 - ^2Player^7(^6"..billedSource.."^7) ^2charged ^7$^6"..data.price.."^7")
if Config.ApGov then
exports['ap-government']:chargeCityTax(billedSource, "Item", data.price)
2024-01-28 12:27:47 +00:00
end
2025-02-21 13:54:49 +00:00
fundPlayer(data.commission, "bank", billerSource)
debugPrint("^5Debug^7: ^3PolCharge^7 - ^2Commission of ^7$^6"..data.commission.." ^2sent to Player^7(^6"..billerSource.."^7)")
2024-01-28 12:27:47 +00:00
2025-02-21 13:54:49 +00:00
if isStarted("Renewed-Banking") then
bankScript = "Renewed-Banking"
exports["Renewed-Banking"]:addAccountMoney(data.billerJob, data.amountChange)
newAmount = exports["Renewed-Banking"]:getAccountMoney(data.billerJob)
2024-01-28 12:27:47 +00:00
2025-02-21 13:54:49 +00:00
elseif isStarted("qb-banking") then
bankScript = "qb-banking"
exports["qb-banking"]:AddMoney(data.billerJob, data.amountChange, "Cash Register Payment")
newAmount = exports["qb-banking"]:GetAccountBalance(data.billerJob)
2024-01-28 12:27:47 +00:00
2025-02-21 13:54:49 +00:00
elseif isStarted("fd_banking") then
bankScript = "fd_banking"
if gang then
exports["fd_banking"]:AddGangMoney(data.billerJob, data.amountChange)
newAmount = exports["fd_banking"]:GetGangAccount(data.billerJob)
else
exports["fd_banking"]:AddMoney(data.billerJob, data.amountChange)
newAmount = exports["fd_banking"]:GetAccount(data.billerJob)
end
elseif isStarted("okokBanking") then
bankScript = "okokBanking"
2024-01-28 12:27:47 +00:00
exports['okokBanking']:AddMoney(data.billerJob, data.amountChange)
newAmount = exports['okokBanking']:GetAccount(data.billerJob)
end
2025-02-21 13:54:49 +00:00
debugPrint("^5Debug^7: ^3"..bankScript.."^7(^3Job^7): ^2Adding ^7$"..data.amountChange.." ^2to account ^7'^6"..data.billerJob.."^7' ($"..newAmount..")")
2024-01-28 12:27:47 +00:00
end