mirror of
https://github.com/jimathy/jim-payments.git
synced 2026-08-17 06:16:02 +01:00
/polcharge for police billing + Optimize + Fixes
This commit is contained in:
71
server.lua
71
server.lua
@@ -7,7 +7,7 @@ local function cv(amount)
|
||||
end
|
||||
|
||||
AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() ~= resource then return end
|
||||
for k, v in pairs(Config.Jobs) do
|
||||
for k in pairs(Config.Jobs) do
|
||||
if not QBCore.Shared.Jobs[k] and not QBCore.Shared.Gangs[k] then
|
||||
print("Jim-Payments: Config.Jobs searched for job/gang '"..k.."' and couldn't find it in the Shared")
|
||||
end
|
||||
@@ -15,25 +15,26 @@ AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName(
|
||||
end)
|
||||
|
||||
QBCore.Commands.Add("cashregister", "Use mobile cash register", {}, false, function(source) TriggerClientEvent("jim-payments:client:Charge", source, {}, true) end)
|
||||
QBCore.Commands.Add("polcharge", "Charge another person", {}, false, function(source) TriggerClientEvent("jim-payments:client:PolCharge", source) end)
|
||||
|
||||
RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller, gang)
|
||||
local billed = QBCore.Functions.GetPlayer(source) -- This should always be from the person who accepted the payment
|
||||
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.Manage then exports["qb-management"]:AddGangMoney(tostring(biller.PlayerData.gang.name), data.amount)
|
||||
if Config.Debug then print("QB-Management(Gang): Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.gang.name).."'") end
|
||||
else TriggerEvent("qb-gangmenu:server:addAccountMoney", tostring(biller.PlayerData.gang.name), data.amount)
|
||||
else TriggerEvent("qb-gangmenu:server:addAccountMoney", tostring(biller.PlayerData.gang.name), data.amount)
|
||||
if Config.Debug then print("QB-GangMenu: Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.gang.name).."'") end
|
||||
end
|
||||
end
|
||||
elseif not gang then
|
||||
if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount)
|
||||
if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount)
|
||||
if Config.Debug then print("QB-Management(Job): Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.job.name).."'") end
|
||||
else TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount)
|
||||
else TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount)
|
||||
if Config.Debug then print("QB-BossMenu: Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.job.name).."'") end
|
||||
end
|
||||
end
|
||||
elseif not biller then --Find the biller from their citizenid
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
for _, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
local Player = QBCore.Functions.GetPlayer(v)
|
||||
if Player.PlayerData.citizenid == data.senderCitizenId then biller = Player end
|
||||
end
|
||||
@@ -46,19 +47,19 @@ RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller, gang)
|
||||
-- If ticket system enabled, do this
|
||||
if duty and Config.TicketSystem then
|
||||
if data.amount >= Config.Jobs[data.society].MinAmountforTicket then
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
for _, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
local Player = QBCore.Functions.GetPlayer(v)
|
||||
if Player ~= nil or Player ~= billed then
|
||||
if Player.PlayerData.job.name == data.society and Player.PlayerData.job.onduty then
|
||||
Player.Functions.AddItem('payticket', 1, false, {["quality"] = nil})
|
||||
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, 'Receipt received', 'success')
|
||||
TriggerClientEvent('inventory:client:ItemBox', Player.PlayerData.source, QBCore.Shared.Items['payticket'], "add", 1)
|
||||
TriggerClientEvent('inventory:client:ItemBox', Player.PlayerData.source, QBCore.Shared.Items['payticket'], "add", 1)
|
||||
end
|
||||
end
|
||||
if gang then
|
||||
biller.Functions.AddItem('payticket', 1, false, {["quality"] = nil})
|
||||
TriggerClientEvent('QBCore:Notify', biller.PlayerData.source, 'Receipt received', 'success')
|
||||
TriggerClientEvent('inventory:client:ItemBox', biller.PlayerData.source, QBCore.Shared.Items['payticket'], "add", 1)
|
||||
TriggerClientEvent('inventory:client:ItemBox', biller.PlayerData.source, QBCore.Shared.Items['payticket'], "add", 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -67,14 +68,14 @@ RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller, gang)
|
||||
local comm = tonumber(Config.Jobs[data.society].Commission)
|
||||
if Config.Commission and comm ~= 0 then
|
||||
if Config.CommissionLimit and data.amount < Config.Jobs[data.society].MinAmountforTicket then return end
|
||||
if Config.CommissionDouble then
|
||||
if Config.CommissionDouble then
|
||||
biller.Functions.AddMoney("bank", math.floor(tonumber(data.amount) * (comm *2)))
|
||||
TriggerClientEvent("QBCore:Notify", biller.PlayerData.source, "Recieved $"..math.floor(tonumber(data.amount) * (comm *2)).." in Commission", "success")
|
||||
else biller.Functions.AddMoney("bank", math.floor(tonumber(data.amount) *comm))
|
||||
TriggerClientEvent("QBCore:Notify", biller.PlayerData.source, "Recieved $"..math.floor(tonumber(data.amount) * comm).." in Commission", "success")
|
||||
end
|
||||
if Config.CommissionAll then
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
for _, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
local Player = QBCore.Functions.GetPlayer(v)
|
||||
if Player ~= nil and Player ~= biller then
|
||||
if Player.PlayerData.job.name == data.society and Player.PlayerData.job.onduty then
|
||||
@@ -100,10 +101,10 @@ RegisterServerEvent('jim-payments:Tickets:Sell', function()
|
||||
end
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb)
|
||||
QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb)
|
||||
if QBCore.Functions.GetPlayer(source).Functions.GetItemByName('payticket') == nil then amount = 0
|
||||
else amount = QBCore.Functions.GetPlayer(source).Functions.GetItemByName('payticket').amount end
|
||||
cb(amount)
|
||||
else amount = QBCore.Functions.GetPlayer(source).Functions.GetItemByName('payticket').amount end
|
||||
cb(amount)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img, outside, gang)
|
||||
@@ -121,7 +122,7 @@ RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billt
|
||||
local label = biller.PlayerData.job.label
|
||||
if gang == true then label = biller.PlayerData.gang.label end
|
||||
if Config.PhoneBank == false or gang == true or billtype == "cash" then
|
||||
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img, label, gang)
|
||||
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img, label, gang, outside)
|
||||
else
|
||||
if Config.PhoneType == "qb" then
|
||||
MySQL.Async.insert(
|
||||
@@ -162,11 +163,47 @@ RegisterServerEvent("jim-payments:server:PayPopup", function(data)
|
||||
end
|
||||
end)
|
||||
|
||||
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
|
||||
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 Config.Manage then
|
||||
if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), price)
|
||||
if Config.Debug then print("QB-Management(Job): Adding $"..price.." to account '"..tostring(biller.PlayerData.job.name).."'") end
|
||||
else TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), price)
|
||||
if Config.Debug then print("QB-BossMenu: Adding $"..price.." to account '"..tostring(biller.PlayerData.job.name).."'") end
|
||||
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))
|
||||
else
|
||||
TriggerClientEvent("jim-payments:client:PolPopup", billed.PlayerData.source, tonumber(price), 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))
|
||||
if data.accept == true then
|
||||
billed.Functions.RemoveMoney("bank", data.amount)
|
||||
TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." accepted the $"..data.amount.." charge", "success")
|
||||
else
|
||||
TriggerClientEvent("QBCore:Notify", src, "You declined the payment")
|
||||
TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." declined the $"..data.amount.." charge", "error")
|
||||
end
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, cb)
|
||||
local onlineList = {}
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
local P = QBCore.Functions.GetPlayer(v)
|
||||
onlineList[#onlineList+1] = { value = tonumber(v), text = "["..v.."] - "..P.PlayerData.charinfo.firstname..' '..P.PlayerData.charinfo.lastname }
|
||||
end
|
||||
cb(onlineList)
|
||||
cb(onlineList)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user