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,28 +40,27 @@ 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
--TriggerEvent("QBCore:Notify", "Table Number: "..#playerList.." ["..GetPlayerServerId(v).."] - "..name.." ("..math.floor(dist+0.5).."m)", "error")
if v ~= PlayerId() then if v ~= PlayerId() then
playerList[#playerList+1] = { value = GetPlayerServerId(v), text = "["..GetPlayerServerId(v).."] - "..name.." ("..math.floor(dist+0.5).."m)" } nearbyList[#nearbyList+1] = onlineList[i]
nearbyList[#nearbyList].text = nearbyList[#nearbyList].text..' ('..math.floor(dist+0.05)..'m)'
end end
end, GetPlayerServerId(v))
Citizen.Wait(100)
end end
name,dist = nil end
dist = nil
end end
if playerList[#playerList] == 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 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 = playerList }, { text = " ", name = "citizen", type = "select", options = nearbyList },
{ 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' },}
}) })
@@ -69,6 +68,7 @@ RegisterNetEvent('jim-payments:client:Charge', function()
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()