mirror of
https://github.com/jimathy/jim-payments.git
synced 2026-08-17 06:16:02 +01:00
Add /polcharge support
This commit is contained in:
@@ -1 +1,81 @@
|
|||||||
-- wip
|
RegisterNetEvent('jim-payments:client:PolCharge', function()
|
||||||
|
--Check if player is allowed to use /cashregister command
|
||||||
|
local allowed = false
|
||||||
|
for k in pairs(Config.PolCharge.FineJobs) do if k == PlayerJob.name then allowed = true end end
|
||||||
|
if not allowed then triggerNotify(nil, Loc[Config.Lan].error["no_job"], "error") return end
|
||||||
|
|
||||||
|
local newinputs = {} -- Begin qb-input creation here.
|
||||||
|
local nearbyList = {}
|
||||||
|
if Config.PolCharge.FineJobList then -- If nearby player list is wanted:
|
||||||
|
--Retrieve a list of nearby players from server
|
||||||
|
local onlineList = triggerCallback("jim-payments:MakePlayerList")
|
||||||
|
--Convert list of players nearby into one qb-input understands + add distance info
|
||||||
|
for _, v in pairs(Core.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.General.PaymentRadius)) do
|
||||||
|
local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId()))
|
||||||
|
for i = 1, #onlineList do
|
||||||
|
if onlineList[i].value == GetPlayerServerId(v) then
|
||||||
|
if v ~= PlayerId() or Config.System.Debug then
|
||||||
|
nearbyList[#nearbyList+1] = { value = onlineList[i].value, label = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)', text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--If list is empty(no one nearby) show error and stop
|
||||||
|
if not nearbyList[1] then triggerNotify(nil, Loc[Config.Lan].error["no_one"], "error") return end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Config.PolCharge.FineJobList then
|
||||||
|
newinputs[#newinputs+1] = { type = "select", text = Loc[Config.Lan].menu["cus_id"], name = "citizen", label = Loc[Config.Lan].menu["cus_id"], default = 1, options = nearbyList }
|
||||||
|
else
|
||||||
|
newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = Loc[Config.Lan].menu["cus_id"] }
|
||||||
|
end
|
||||||
|
newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = Loc[Config.Lan].menu["amount_charge"] }
|
||||||
|
|
||||||
|
local dialog = createInput(img, newinputs)
|
||||||
|
if dialog then
|
||||||
|
if dialog[1] then
|
||||||
|
dialog.citizen = dialog[1]
|
||||||
|
dialog.price = dialog[2]
|
||||||
|
end
|
||||||
|
TriggerServerEvent('jim-payments:server:PolCharge', dialog.citizen, dialog.price)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent("jim-payments:client:PolPopup", function(amount, biller, billerjob)
|
||||||
|
local Menu = {}
|
||||||
|
Menu[#Menu+1] = { isMenuHeader = true, header = "", txt = Loc[Config.Lan].menu["bank_charge"]..amount }
|
||||||
|
Menu[#Menu+1] = {
|
||||||
|
icon = "fas fa-circle-check",
|
||||||
|
header = Loc[Config.Lan].menu["yes"],
|
||||||
|
txt = "",
|
||||||
|
onSelect = function()
|
||||||
|
TriggerServerEvent("jim-payments:server:PolPopup", {
|
||||||
|
accept = true,
|
||||||
|
amount = amount,
|
||||||
|
biller = biller,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
Menu[#Menu+1] = {
|
||||||
|
icon = "fas fa-circle-xmark",
|
||||||
|
header = Loc[Config.Lan].menu["no"],
|
||||||
|
onSelect = function()
|
||||||
|
TriggerServerEvent("jim-payments:server:PolPopup", {
|
||||||
|
accept = false,
|
||||||
|
amount = amount,
|
||||||
|
biller = biller,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
openMenu(Menu, {
|
||||||
|
header = "🧾 "..billerjob..Loc[Config.Lan].menu["payment"],
|
||||||
|
headertxt = Loc[Config.Lan].menu["accept_payment"],
|
||||||
|
onExit = function()
|
||||||
|
TriggerServerEvent("jim-payments:server:PolPopup", {
|
||||||
|
accept = false,
|
||||||
|
amount = amount,
|
||||||
|
biller = biller,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end)
|
||||||
@@ -1 +1,91 @@
|
|||||||
-- Wip
|
registerCommand("polcharge", { Loc[Config.Lan].command["charge"], {}, false, function(source) TriggerClientEvent("jim-payments:client:PolCharge", source) end })
|
||||||
|
|
||||||
|
RegisterServerEvent("jim-payments:server:PolCharge", function(citizen, price)
|
||||||
|
local src = source
|
||||||
|
local biller = Core.Functions.GetPlayer(src)
|
||||||
|
local billed = Core.Functions.GetPlayer(tonumber(citizen))
|
||||||
|
local price = math.floor(tonumber(price))
|
||||||
|
|
||||||
|
local commPercent = Config.PolCharge.FineJobs[biller.PlayerData.job.name] and Config.PolCharge.FineJobs[biller.PlayerData.job.name].Commission or 0.25
|
||||||
|
if Config.PolCharge.FineJobs[biller.PlayerData.job.name] then
|
||||||
|
commPercent = Config.PolCharge.FineJobs[biller.PlayerData.job.name].Commission
|
||||||
|
else
|
||||||
|
commPercent = 0.25
|
||||||
|
print("Can't find job in 'FineJobs', defaulting to 0.25 (25% commission)")
|
||||||
|
end
|
||||||
|
local commission = math.floor(price * commPercent)
|
||||||
|
|
||||||
|
if price > 0 then
|
||||||
|
if not Config.PolCharge.FineJobConfirmation then
|
||||||
|
polCharge({
|
||||||
|
biller = biller,
|
||||||
|
billed = billed,
|
||||||
|
price = price,
|
||||||
|
commission = commission,
|
||||||
|
billerJob = tostring(biller.PlayerData.job.name),
|
||||||
|
amountChange = (price - commission)
|
||||||
|
})
|
||||||
|
|
||||||
|
triggerNotify(nil, billed.PlayerData.charinfo.firstname..Loc[Config.Lan].success["charged"]..(price - commission), "success", src)
|
||||||
|
triggerNotify(nil, Loc[Config.Lan].success["you_charged"]..(price - commission), nil, billed.PlayerData.source)
|
||||||
|
else
|
||||||
|
TriggerClientEvent("jim-payments:client:PolPopup", billed.PlayerData.source, price, src, biller.PlayerData.job.label, commPercent)
|
||||||
|
end
|
||||||
|
else triggerNotify(nil, Loc[Config.Lan].error["charge_zero"], 'error', source) return end
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterServerEvent("jim-payments:server:PolPopup", function(data)
|
||||||
|
local src = source
|
||||||
|
local billed = Core.Functions.GetPlayer(src)
|
||||||
|
local biller = Core.Functions.GetPlayer(tonumber(data.biller))
|
||||||
|
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,
|
||||||
|
billerJob = tostring(biller.PlayerData.job.name),
|
||||||
|
amountChange = (price - commission)
|
||||||
|
})
|
||||||
|
elseif not data.accept then
|
||||||
|
triggerNotify(nil, Loc[Config.Lan].error["declined_payment"], nil, src)
|
||||||
|
triggerNotify(nil, billed.PlayerData.charinfo.firstname.." declined the $"..data.amount..Loc[Config.Lan].success["charge_end"], "error", data.biller)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function polCharge(data)
|
||||||
|
local billedSource, billerSource, newAmount = data.billed.PlayerData.source, data.biller.PlayerData.source, 0
|
||||||
|
if data.billed.Functions.RemoveMoney("bank", data.price) then
|
||||||
|
if Config.System.Debug then print("^5Debug^7: ^3PolCharge^7 - ^2Player^7(^6"..billedSource.."^7) ^2charged ^7$^6"..data.price.."^7") end
|
||||||
|
end
|
||||||
|
if Config.ApGov then exports['ap-government']:chargeCityTax(billedSource, "Item", data.price) end
|
||||||
|
if data.biller.Functions.AddMoney("bank", data.commission) then
|
||||||
|
if Config.System.Debug then
|
||||||
|
print("^5Debug^7: ^3PolCharge^7 - ^2Commission of ^7$^6"..data.commission.." ^2sent to Player^7(^6"..billerSource.."^7)")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Config.General.Banking == "renewed" then
|
||||||
|
exports['Renewed-Banking']:addAccountMoney(data.billerJob, data.amountChange)
|
||||||
|
newAmount = exports['Renewed-Banking']:getAccountMoney(data.billerJob)
|
||||||
|
|
||||||
|
elseif Config.General.Banking == "qb-management" or Config.General.Banking == "qb-banking" then
|
||||||
|
exports[Config.General.Banking]:AddMoney(data.billerJob, data.amountChange)
|
||||||
|
newAmount = exports[Config.General.Banking]:GetAccount(data.billerJob)
|
||||||
|
if Config.General.Banking == "qb-banking" then newAmount = newAmount.account_balance end
|
||||||
|
|
||||||
|
elseif Config.General.Banking == "fd" then
|
||||||
|
exports["fd_banking"]:AddMoney(data.billerJob, data.amountChange)
|
||||||
|
newAmount = exports["fd_banking"]:GetAccount(data.billerJob)
|
||||||
|
|
||||||
|
elseif Config.General.Banking == "okok" then
|
||||||
|
exports['okokBanking']:AddMoney(data.billerJob, data.amountChange)
|
||||||
|
newAmount = exports['okokBanking']:GetAccount(data.billerJob)
|
||||||
|
|
||||||
|
end
|
||||||
|
if Config.System.Debug then
|
||||||
|
print("^5Debug^7: ^3"..Config.General.Banking.."^7(^3Job^7): ^2Adding ^7$"..data.amountChange.." ^2to account ^7'^6"..data.billerJob.."^7' ($"..newAmount..")")
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user