From 61fc56d82d2984db1e10f6eaeff0ef7c9290d6da Mon Sep 17 00:00:00 2001 From: jimathy Date: Sun, 20 Feb 2022 15:30:15 +0000 Subject: [PATCH] Add ability to disable receipts --- config.lua | 2 ++ server.lua | 47 ++++++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/config.lua b/config.lua index 2d5180e..df1084a 100644 --- a/config.lua +++ b/config.lua @@ -6,6 +6,8 @@ print("Jim-Payments v2 - Payments Script by Jimathy") Config = {} +Config.TicketSystem = true -- Enable this if you want to use the ticket system + Config.PaymentRadius = 30 -- This is how far the player list will check -- MinAmountforTicket should be your cheapest item diff --git a/server.lua b/server.lua index 3d591b4..4ceb706 100644 --- a/server.lua +++ b/server.lua @@ -1,21 +1,35 @@ local QBCore = exports['qb-core']:GetCoreObject() -RegisterServerEvent('jim-payments:Tickets:Give') -AddEventHandler('jim-payments:Tickets:Give', function(amount, job) - 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 - 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 +local function cv(amount) + local formatted = amount + while true do + formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') + if (k==0) then + break end end + return formatted +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 + 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 + 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 end) RegisterServerEvent('jim-payments:Tickets:Sell', function() @@ -27,7 +41,7 @@ RegisterServerEvent('jim-payments:Tickets:Sell', function() pay = (tickets * Config.Jobs[Player.PlayerData.job.name].PayPerTicket) Player.Functions.AddMoney('bank', pay, 'ticket-payment') TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['payticket'], "remove", tickets) - TriggerClientEvent('QBCore:Notify', source, "Tickets traded: "..tickets.." Total: $"..pay, 'success') + TriggerClientEvent('QBCore:Notify', source, "Tickets traded: "..tickets.." Total: $"..cv(pay), 'success') end end) @@ -41,7 +55,6 @@ RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billt local biller = QBCore.Functions.GetPlayer(source) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) local amount = tonumber(price) - local billtype = string.lower(tostring(billtype)) if amount and amount > 0 then if billtype == "cash" then balance = billed.Functions.GetMoney(billtype) @@ -71,4 +84,4 @@ QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, onlineList[#onlineList+1] = { value = tonumber(v), text = "["..v.."] - "..P.PlayerData.charinfo.firstname..' '..P.PlayerData.charinfo.lastname } end cb(onlineList) -end) +end) \ No newline at end of file