Attempting restricted payments outside of job

This commit is contained in:
jimathy
2022-05-05 21:34:34 +01:00
committed by GitHub
parent dbd3f33099
commit 9a14e004e9
2 changed files with 31 additions and 27 deletions

View File

@@ -24,11 +24,14 @@ CreateThread(function()
end end
end) end)
RegisterNetEvent('jim-payments:client:Charge', function(data) RegisterNetEvent('jim-payments:client:Charge', function(data, outside)
if not onDuty then TriggerEvent("QBCore:Notify", "Not Clocked in!", "error") return end -- Require to be on duty when making a payment 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 onlineList = {}
local nearbyList = {} local nearbyList = {}
QBCore.Functions.TriggerCallback('jim-payments:MakePlayerList', function(cb) onlineList = cb if onlineList[1] == nil then Wait(200) 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 for k, v in pairs(QBCore.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.PaymentRadius)) do
local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId())) local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId()))
for i = 1, #onlineList do for i = 1, #onlineList do
@@ -40,7 +43,7 @@ RegisterNetEvent('jim-payments:client:Charge', function(data)
end end
dist = nil dist = nil
end end
if data.img == nil then img = "" else img = data.img 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 if nearbyList[#nearbyList] == nil then TriggerEvent("QBCore:Notify", "No one near by to charge", "error") return end
local newinputs = {} local newinputs = {}
if Config.List then newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList } end if Config.List then newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList } end
@@ -50,10 +53,9 @@ RegisterNetEvent('jim-payments:client:Charge', function(data)
local dialog = exports['qb-input']:ShowInput({ header = img..PlayerJob.label.." Cash Register", submitText = "Send", inputs = newinputs}) local dialog = exports['qb-input']:ShowInput({ header = img..PlayerJob.label.." Cash Register", submitText = "Send", inputs = newinputs})
if dialog then if dialog then
if not dialog.citizen or not dialog.price then return end if not dialog.citizen or not dialog.price then return end
TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype, data.img) TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype, data.img, outside)
end end
end) end)
end)
RegisterNetEvent('jim-payments:Tickets:Menu', function() RegisterNetEvent('jim-payments:Tickets:Menu', function()
local amount = 0 local amount = 0

View File

@@ -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 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) 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) RegisterServerEvent('jim-payments:Tickets:Give', function(data, biller)
--Find the biller from their citizenid --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 if Player.PlayerData.citizenid == data.senderCitizenId then biller = Player end
end 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.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 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) 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 if Config.Debug then print("QB-BossMenu: Adding $"..data.amount.." to account '"..tostring(biller.PlayerData.job.name).."'") end
end end
-- If ticket system enabled, do this -- 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 if data.amount >= Config.Jobs[data.society].MinAmountforTicket then
for k, v in pairs(QBCore.Functions.GetPlayers()) do for k, v in pairs(QBCore.Functions.GetPlayers()) do
local Player = QBCore.Functions.GetPlayer(v) local Player = QBCore.Functions.GetPlayer(v)
@@ -84,7 +86,7 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb
cb(amount) cb(amount)
end) 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 src = source
local biller = QBCore.Functions.GetPlayer(src) local biller = QBCore.Functions.GetPlayer(src)
local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) local billed = QBCore.Functions.GetPlayer(tonumber(citizen))