From 9a14e004e9674c5c71c683509c33bd9f23f2910e Mon Sep 17 00:00:00 2001 From: jimathy Date: Thu, 5 May 2022 21:34:34 +0100 Subject: [PATCH 1/3] Attempting restricted payments outside of job --- client.lua | 50 ++++++++++++++++++++++++++------------------------ server.lua | 8 +++++--- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/client.lua b/client.lua index bd732af..3884bed 100644 --- a/client.lua +++ b/client.lua @@ -24,35 +24,37 @@ CreateThread(function() end end) -RegisterNetEvent('jim-payments:client:Charge', function(data) - if not onDuty then TriggerEvent("QBCore:Notify", "Not Clocked in!", "error") return end -- Require to be on duty when making a payment +RegisterNetEvent('jim-payments:client:Charge', function(data, outside) + if outside == nil then outside = false end + if not outside and not onDuty then TriggerEvent("QBCore:Notify", "Not Clocked in!", "error") return end -- Require to be on duty when making a payment local onlineList = {} local nearbyList = {} - QBCore.Functions.TriggerCallback('jim-payments:MakePlayerList', function(cb) onlineList = cb if onlineList[1] == nil then Wait(200) end - for k, v in pairs(QBCore.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.PaymentRadius)) do - local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId())) - for i = 1, #onlineList do - if onlineList[i].value == GetPlayerServerId(v) then - if v ~= PlayerId() then - nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' } - end + local p = promise.new() + QBCore.Functions.TriggerCallback('jim-payments:MakePlayerList', function(cb) p:resolve(cb) end) + onlineList = Citizen.Await(p) + for k, v in pairs(QBCore.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.PaymentRadius)) do + local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId())) + for i = 1, #onlineList do + if onlineList[i].value == GetPlayerServerId(v) then + if v ~= PlayerId() then + nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' } end end - dist = nil end - if data.img == nil then img = "" else img = data.img end - if nearbyList[#nearbyList] == nil then TriggerEvent("QBCore:Notify", "No one near by to charge", "error") return end - local newinputs = {} - if Config.List then newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList } end - if not Config.List then newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = '# Customer ID #' } end - newinputs[#newinputs+1] = { type = 'radio', name = 'billtype', text = 'Payment Type', options = { { value = "cash", text = "Cash" }, { value = "bank", text = "Card" } } } - newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = '💵 Amount to Charge' } - local dialog = exports['qb-input']:ShowInput({ header = img..PlayerJob.label.." Cash Register", submitText = "Send", inputs = newinputs}) - if dialog then - if not dialog.citizen or not dialog.price then return end - TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype, data.img) - end - end) + dist = nil + end + if not data.img then img = "" else img = data.img end + if nearbyList[#nearbyList] == nil then TriggerEvent("QBCore:Notify", "No one near by to charge", "error") return end + local newinputs = {} + if Config.List then newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList } end + if not Config.List then newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = '# Customer ID #' } end + newinputs[#newinputs+1] = { type = 'radio', name = 'billtype', text = 'Payment Type', options = { { value = "cash", text = "Cash" }, { value = "bank", text = "Card" } } } + newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = '💵 Amount to Charge' } + local dialog = exports['qb-input']:ShowInput({ header = img..PlayerJob.label.." Cash Register", submitText = "Send", inputs = newinputs}) + if dialog then + if not dialog.citizen or not dialog.price then return end + TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype, data.img, outside) + end end) RegisterNetEvent('jim-payments:Tickets:Menu', function() diff --git a/server.lua b/server.lua index 6e190dc..6f42d27 100644 --- a/server.lua +++ b/server.lua @@ -10,7 +10,7 @@ AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() == resource then for k, v in pairs(Config.Jobs) do if not QBCore.Shared.Jobs[k] then print("Jim-Payments: Config.Jobs searched for job '"..k.."' and couldn't find it in the Shared") end end end end) ---QBCore.Commands.Add("cashregister", "Use mobile cash register", {}, false, function(source) TriggerClientEvent("jim-payments:client:Charge", source, true) 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(data, biller) --Find the biller from their citizenid @@ -20,13 +20,15 @@ RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller) if Player.PlayerData.citizenid == data.senderCitizenId then biller = Player end end end + local duty = true + if biller.PlayerData.job.onduty then duty = true else duty = false end if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount) if Config.Debug then print("QB-Management: Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.job.name).."'") end 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 -- If ticket system enabled, do this - if Config.TicketSystem then + if duty and 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) @@ -84,7 +86,7 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb cb(amount) end) -RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img) +RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img, outside) local src = source local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) From 35e166d049c94c47adcfcd9d3ddf53e8bc8d93fa Mon Sep 17 00:00:00 2001 From: jimathy Date: Thu, 5 May 2022 21:37:45 +0100 Subject: [PATCH 2/3] don't need the variable here --- server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.lua b/server.lua index 6f42d27..7323810 100644 --- a/server.lua +++ b/server.lua @@ -86,7 +86,7 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb cb(amount) end) -RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img, outside) +RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img) local src = source local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) @@ -147,4 +147,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) \ No newline at end of file +end) From 100323927eba525ece490a995bd31e2e669d3524 Mon Sep 17 00:00:00 2001 From: jimathy Date: Thu, 5 May 2022 21:39:09 +0100 Subject: [PATCH 3/3] Explanation of new duty variables --- server.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/server.lua b/server.lua index 7323810..1ad94b7 100644 --- a/server.lua +++ b/server.lua @@ -20,6 +20,7 @@ RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller) if Player.PlayerData.citizenid == data.senderCitizenId then biller = Player end end end + -- Find out of person who sent the payment is on duty, this is then used to decide weather to give tickets or not local duty = true if biller.PlayerData.job.onduty then duty = true else duty = false end if Config.Manage then exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount)