Rewrote the playerlist ANOTHER way

This commit is contained in:
jimathy
2022-02-17 12:43:15 +00:00
committed by GitHub
parent 5de2f99693
commit 3e9570607a

View File

@@ -40,35 +40,35 @@ end)
RegisterNetEvent('jim-payments:client:Charge', function() RegisterNetEvent('jim-payments:client:Charge', function()
if not onDuty then TriggerEvent("QBCore:Notify", "Not Clocked in!", "error") return end -- Require to be on duty when making a payment if not onDuty then TriggerEvent("QBCore:Notify", "Not Clocked in!", "error") return end -- Require to be on duty when making a payment
local playerList = { } local onlineList = {}
local name = nil local nearbyList = {}
for k,v in pairs(QBCore.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.PaymentRadius)) do QBCore.Functions.TriggerCallback('jim-payments:MakePlayerList', function(cb) onlineList = cb if onlineList[1] == nil then Wait(200) end
--Distance info, cosmetic for adding the "(5m)" when opening the register 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()))
while name == nil do for i = 1, #onlineList do
QBCore.Functions.TriggerCallback('jim-payments:Name:Find', function(cb) name = cb if onlineList[i].value == GetPlayerServerId(v) then
--Debugging notification, this shows the info it finds regardless of it adds to the list or not if v ~= PlayerId() then
--TriggerEvent("QBCore:Notify", "Table Number: "..#playerList.." ["..GetPlayerServerId(v).."] - "..name.." ("..math.floor(dist+0.5).."m)", "error") nearbyList[#nearbyList+1] = onlineList[i]
if v ~= PlayerId() then nearbyList[#nearbyList].text = nearbyList[#nearbyList].text..' ('..math.floor(dist+0.05)..'m)'
playerList[#playerList+1] = { value = GetPlayerServerId(v), text = "["..GetPlayerServerId(v).."] - "..name.." ("..math.floor(dist+0.5).."m)" } end
end end
end, GetPlayerServerId(v)) end
Citizen.Wait(100) dist = nil
end end
name,dist = nil
end
if nearbyList[#nearbyList] == nil then TriggerEvent("QBCore:Notify", "No one near by to charge", "error") return end
if playerList[#playerList] == nil then TriggerEvent("QBCore:Notify", "No one near by to charge", "error") return end local dialog = exports['qb-input']:ShowInput({ header = PlayerJob.label.." Cash Register", submitText = "Send",
local dialog = exports['qb-input']:ShowInput({ header = PlayerJob.label.." Cash Register", submitText = "Send", inputs = {
inputs = { { text = " ", name = "citizen", type = "select", options = nearbyList },
{ text = " ", name = "citizen", type = "select", options = playerList }, { type = 'radio', name = 'billtype', text = 'Payment Type', options = { { value = "cash", text = "Cash" }, { value = "card", text = "Card" } } },
{ type = 'radio', name = 'billtype', text = 'Payment Type', options = { { value = "cash", text = "Cash" }, { value = "card", text = "Card" } } }, { type = 'number', isRequired = true, name = 'price', text = '💵 Amount to Charge' },}
{ type = 'number', isRequired = true, name = 'price', text = '💵 Amount to Charge' },} })
}) 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)
TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype) end
end end)
end) end)
RegisterNetEvent('jim-payments:Tickets:Menu', function() RegisterNetEvent('jim-payments:Tickets:Menu', function()
@@ -85,4 +85,4 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function()
end) end)
RegisterNetEvent('jim-payments:Tickets:Sell:yes', function() TriggerServerEvent('jim-payments:Tickets:Sell') 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)