From f9029f0951495b6e4053715833986c79ec64c334 Mon Sep 17 00:00:00 2001 From: jimathy Date: Mon, 11 Apr 2022 18:59:47 +0100 Subject: [PATCH] Commission update --- client.lua | 2 +- config.lua | 31 +++++++++++++++---------- fxmanifest.lua | 2 +- server.lua | 61 +++++++++++++++++++++++++++++++++++++------------- 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/client.lua b/client.lua index 025cb43..1f2eab2 100644 --- a/client.lua +++ b/client.lua @@ -51,7 +51,7 @@ end) RegisterNetEvent('jim-payments:Tickets:Menu', function() local amount = nil - while amount == nil do QBCore.Functions.TriggerCallback('jim-payments:Ticket:Count', function(cb) amount = cb end) Citizen.Wait(1) end + local p = promise.new() QBCore.Functions.TriggerCallback('jim-payments:Ticket:Count', function(cb) p:resolve(cb) end) amount = Citizen.Await(p) for k, v in pairs(Config.Jobs) do if k ~= PlayerJob.name then else exports['qb-menu']:openMenu({ { isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Receipts 🧾", txt = "Do you want trade your receipts for payment?" }, diff --git a/config.lua b/config.lua index 70728e2..e441582 100644 --- a/config.lua +++ b/config.lua @@ -1,4 +1,4 @@ -print("Jim-Payments v2.1 - Payments Script by Jimathy") +print("Jim-Payments v2.2 - Payments Script by Jimathy") -- If you need support I now have a discord available, it helps me keep track of issues and give better support. @@ -18,17 +18,24 @@ Config.ATMBlips = false -- Enable this if you are a pyscho and need every ATM to Config.PhoneBank = true -- Set this to false to use the popup payment system FOR CARD/BANK PAYMENTS instead of using phone invoices -- This doesn't affect Cash payments as they by default use confirmation now -- This is helpful for phones that don't support invoices well - + +Config.Commission = false -- Set this to true to enable Commissions and give the person charging a percentage of the total +Config.CommissionAll = false -- Set this to true to give commission to workers clocked in +Config.CommissionDouble = false -- Set this to true if you want the person charging to get double Commission +Config.CommissionLimit = false -- If true, this limits the Commission to only be given if over the "MinAmountForTicket". If false, Commission will be given for any amount + -- MinAmountforTicket should be your cheapest item -- PayPerTicket should never be higher than MinAmountforTicket +-- Commission is a percentage eg "0.10" becomes 10% + Config.Jobs = { - ['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['burgershot'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['catcafe'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['pizzathis'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['tequilala'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['vanilla'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['mechanic'] = { MinAmountforTicket = 1000, PayPerTicket = 500 }, -} + ['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['burgershot'] = { MinAmountforTicket = 50, PayPerTicket = 50 , Commission = 0.10,}, + ['catcafe'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['pizzathis'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['tequilala'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['vanilla'] = { MinAmountforTicket = 50, PayPerTicket = 50, Commission = 0.10, }, + ['mechanic'] = { MinAmountforTicket = 1000, PayPerTicket = 500, Commission = 0.10, }, +} \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index f2b84d8..1a17d05 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim-Payments" author "Jimathy" -version "v2" +version "v2.2" description "Payment Script By Jimathy" fx_version "cerulean" game "gta5" diff --git a/server.lua b/server.lua index d35c842..e9035e1 100644 --- a/server.lua +++ b/server.lua @@ -13,18 +13,45 @@ end --QBCore.Commands.Add("cashregister", "Use mobile cash register", {}, false, function(source) TriggerClientEvent("jim-payments:client:Charge", source, true) end) -RegisterServerEvent('jim-payments:Tickets:Give', function(amount, job) - if Config.TicketSystem then +RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller) + --Find the biller from their citizenid + if biller == nil then for k, v in pairs(QBCore.Functions.GetPlayers()) do - local Player = QBCore.Functions.GetPlayer(v) - if Player ~= nil then - if Player.PlayerData.job.name == job and Player.PlayerData.job.onduty then - if amount >= Config.Jobs[job].MinAmountforTicket then + local Player = QBCore.Functions.GetPlayer(v) + if Player.PlayerData.citizenid == data.senderCitizenId then biller = Player end + end + end + if Config.TicketSystem then + if data.amount >= Config.Jobs[data.society].MinAmountforTicket then + for k, v in pairs(QBCore.Functions.GetPlayers()) do + local Player = QBCore.Functions.GetPlayer(v) + if Player ~= nil 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) - elseif amount < Config.Jobs[job].MinAmountforTicket then - TriggerClientEvent("QBCore:Notify", Player.PlayerData.source, "Amount too low, didn't receive a receipt", "error") + end + end + end + end + end + -- Commission section, does each config option separately + 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 + 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 + 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 + Player.Functions.AddMoney("bank", math.floor(tonumber(data.amount) * comm)) + TriggerClientEvent("QBCore:Notify", Player.PlayerData.source, "Recieved $"..math.floor(tonumber(data.amount) * comm).." in Commission", "success") end end end @@ -56,14 +83,15 @@ RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billt local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) local amount = tonumber(price) + local balance = billed.Functions.GetMoney(billtype) if amount and amount > 0 then - if billtype == "cash" then balance = billed.Functions.GetMoney(billtype) - if balance >= amount then - TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img) - elseif balance < amount then - TriggerClientEvent("QBCore:Notify", src, "Customer doesn't have enough cash to pay", "error") - TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You don't have enough cash to pay", "error") - end + if balance < amount then + TriggerClientEvent("QBCore:Notify", src, "Customer doesn't have enough cash to pay", "error") + TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You don't have enough cash to pay", "error") + return + end + if billtype == "cash" then + TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img) elseif billtype == "bank" then if Config.PhoneBank == false then TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img) @@ -83,11 +111,12 @@ RegisterServerEvent("jim-payments:server:PayPopup", function(data) local src = source local billed = QBCore.Functions.GetPlayer(src) local biller = QBCore.Functions.GetPlayer(tonumber(data.biller)) + local newdata = { senderCitizenId = biller.PlayerData.citizenid, society = biller.PlayerData.job.name, amount = data.amount } if data.accept == true then billed.Functions.RemoveMoney(tostring(data.billtype), data.amount) exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount) --TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount) - TriggerEvent('jim-payments:Tickets:Give', data.amount, tostring(biller.PlayerData.job.name)) + TriggerEvent('jim-payments:Tickets:Give', newdata, biller) TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." accepted the payment", "success") elseif data.accept == false then TriggerClientEvent("QBCore:Notify", src, "You declined the payment")