From 3e036d6996dd01be3a9f7472025bd4bcd18d45df Mon Sep 17 00:00:00 2001 From: jimathy Date: Fri, 11 Mar 2022 00:30:49 +0000 Subject: [PATCH] v2.1 - Add confirmation popups for payments --- client.lua | 44 ++++++++++++++++---------------------------- config.lua | 12 ++++++++---- server.lua | 39 +++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 44 deletions(-) diff --git a/client.lua b/client.lua index 7fa7f7c..d391f53 100644 --- a/client.lua +++ b/client.lua @@ -3,33 +3,13 @@ local QBCore = exports['qb-core']:GetCoreObject() PlayerJob = {} local onDuty = false -RegisterNetEvent('QBCore:Client:OnPlayerLoaded') -AddEventHandler('QBCore:Client:OnPlayerLoaded', function() - QBCore.Functions.GetPlayerData(function(PlayerData) - PlayerJob = PlayerData.job - PlayerGang = PlayerData.gang - end) -end) - -RegisterNetEvent('QBCore:Client:OnJobUpdate') -AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) - PlayerJob = JobInfo - onDuty = PlayerJob.onduty -end) - -RegisterNetEvent('QBCore:Client:SetDuty') -AddEventHandler('QBCore:Client:SetDuty', function(duty) - onDuty = duty -end) - -RegisterNetEvent('QBCore:Client:OnGangUpdate') -AddEventHandler('QBCore:Client:OnGangUpdate', function(GangInfo) - PlayerGang = GangInfo -end) +RegisterNetEvent('QBCore:Client:OnPlayerLoaded') AddEventHandler('QBCore:Client:OnPlayerLoaded', function() QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang end) end) +RegisterNetEvent('QBCore:Client:OnJobUpdate') AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) PlayerJob = JobInfo onDuty = PlayerJob.onduty end) +RegisterNetEvent('QBCore:Client:SetDuty') AddEventHandler('QBCore:Client:SetDuty', function(duty) onDuty = duty end) +RegisterNetEvent('QBCore:Client:OnGangUpdate') AddEventHandler('QBCore:Client:OnGangUpdate', function(GangInfo) PlayerGang = GangInfo end) --Keeps track of duty on script restarts -AddEventHandler('onResourceStart', function(resource) -if GetCurrentResourceName() == resource then QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end) end end) +AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() == resource then QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end) end end) Citizen.CreateThread(function() local jobroles = {} @@ -76,11 +56,19 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function() else exports['qb-menu']:openMenu({ { isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Receipts 🧾", txt = "Do you want trade your receipts for payment?" }, { isMenuHeader = true, header = "", txt = "Amount of Tickets: "..amount.."
Total Payment: $"..(Config.Jobs[PlayerJob.name].PayPerTicket * amount) }, - { header = "Yes", txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } }, - { header = "No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, }) + { header = "✅ Yes", txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } }, + { header = "❌ No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, }) end end end) +RegisterNetEvent("jim-payments:client:PayPopup", function(amount, biller, billtype) + exports['qb-menu']:openMenu({ + { isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Payment 🧾", txt = "Do you want accept the payment?" }, + { isMenuHeader = true, header = "", txt = billtype:gsub("^%l", string.upper).." Payment: $"..amount }, + { header = "✅ Yes", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = true, amount = amount, biller = biller, billtype = billtype } } }, + { header = "❌ No", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = false, amount = amount, biller = biller, billtype = billtype } } }, }) +end) + RegisterNetEvent('jim-payments:Tickets:Sell:yes', function() TriggerServerEvent('jim-payments:Tickets:Sell') end) -RegisterNetEvent('jim-payments:Tickets:Sell:no', function() exports['qb-menu']:closeMenu() end) +RegisterNetEvent('jim-payments:Tickets:Sell:no', function() exports['qb-menu']:closeMenu() end) \ No newline at end of file diff --git a/config.lua b/config.lua index 8e18264..70728e2 100644 --- a/config.lua +++ b/config.lua @@ -1,4 +1,4 @@ -print("Jim-Payments v2 - Payments Script by Jimathy") +print("Jim-Payments v2.1 - 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. @@ -15,15 +15,19 @@ Config.useBanks = true -- Enable this to use my banking stuff Config.BankBlips = true -- Enable this if you disabled qb-banking and need bank locations Config.ATMBlips = false -- Enable this if you are a pyscho and need every ATM to be on the map too +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 + -- MinAmountforTicket should be your cheapest item -- PayPerTicket should never be higher than MinAmountforTicket Config.Jobs = { - ['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, ['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50 }, - ['pizzathis'] = { 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 }, diff --git a/server.lua b/server.lua index 32cfab5..9a84d6e 100644 --- a/server.lua +++ b/server.lua @@ -52,31 +52,46 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb end) RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype) - local biller = QBCore.Functions.GetPlayer(source) + local src = source + local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) local amount = tonumber(price) - if amount and amount > 0 then if billtype == "cash" then balance = billed.Functions.GetMoney(billtype) if balance >= amount then - billed.Functions.RemoveMoney('cash', amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), amount) - TriggerEvent('jim-payments:Tickets:Give', amount, tostring(biller.PlayerData.job.name)) + TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype) elseif balance < amount then - TriggerClientEvent("QBCore:Notify", source, "Customer doesn't have enough cash to pay", "error") + 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 elseif billtype == "card" then - MySQL.Async.insert( - 'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)', - {billed.PlayerData.citizenid, amount, biller.PlayerData.job.name, - biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid}) - TriggerClientEvent('qb-phone:RefreshPhone', billed.PlayerData.source) - TriggerClientEvent('QBCore:Notify', source, 'Invoice Successfully Sent', 'success') - TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'New Invoice Received') + if Config.PhoneBank == false then + TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype) + else + MySQL.Async.insert( + 'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)', + {billed.PlayerData.citizenid, amount, biller.PlayerData.job.name, biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid}) + TriggerClientEvent('qb-phone:RefreshPhone', billed.PlayerData.source) + TriggerClientEvent('QBCore:Notify', src, 'Invoice Successfully Sent', 'success') + TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'New Invoice Received') + end end else TriggerClientEvent('QBCore:Notify', source, "You can't charge $0", 'error') return end end) +RegisterServerEvent("jim-payments:server:PayPopup", 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(tostring(data.billtype), data.amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount) + TriggerEvent('jim-payments:Tickets:Give', data.amount, tostring(billed.PlayerData.job.name)) + elseif data.accept == false then + TriggerClientEvent("QBCore:Notify", src, "You declined the payment") + TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." declined the payment", "error") + end +end) + QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, cb) local onlineList = {} for k, v in pairs(QBCore.Functions.GetPlayers()) do