Im trying to put players ping instead of wantedlevel in the scoreboard ressource. I cant get it work… (learning lua ^^)
I hope this post can help other people aswell.
The code:
Citizen.CreateThread(function()
listOn = false
while true do
Wait(0)
if IsControlPressed(0, 37)--[[ INPUT_SELECT_WEAPON ]] then
if not listOn then
local players = {}
ptable = GetPlayers()
for _, i in ipairs(ptable) do
local ping = GetPlayerPing(i)
r, g, b = GetPlayerRgbColour(i)
table.insert(players,
'<tr style=\"color: rgb(' .. r .. ', ' .. g .. ', ' .. b .. ')\"><td>' .. GetPlayerServerId(i) .. '</td><td>' .. GetPlayerName(i) .. '</td><td>' .. ping .. '</td></tr>'
)
end
SendNUIMessage({ text = table.concat(players) })
listOn = true
while listOn do
Wait(0)
if(IsControlPressed(0, 37) == false) then
listOn = false
SendNUIMessage({
meta = 'close'
})
break
end
end
end
end
end
end)
The error:
Error resuming coroutine: scoreboard.lua:13: attempt to call a nil value (global ‘GetPlayerPing’)
stack traceback:
scoreboard.lua:13 in function <scoreboard.lua3>
Exactly.
You can’t call GetPlayerPing on client, you have to do that on the server.
However a client could ask the server for a specific ping with some event and that event would send back to that client the ping of the user
Do you have an example of how to do that? I too am looking for this function. I was just throwing out what I have already learned to see if it would help him.
Here is what I have so far:
Amending Scoreboard.lua:
TriggerServerEvent('checkPlayerPing')
AddEventHandler("checkPlayerPing", function()
local ping = GetPlayerPing(i)
table.insert(players,
'<tr style=\"color: rgb(' .. r .. ', ' .. g .. ', ' .. b .. ')\"><td>' .. GetPlayerServerId(i) .. '</td><td>' .. GetPlayerName(i) .. '</td><td>' .. ping(i) .. '</td></tr>'
)
end
You’re kinda doing it completely wrong with the code.
Something like this:
Client:
TriggerServerEvent("checkPlayerPing", clientid, playerid)
RegisterNetEvent("playerPingResult")
AddEventHandler("playerPingResult", function(id, ping)
--Do whatever you want with the id of that player and his ping :)
end)
for clientid needs to be the id of the user that is requesting the player ping check (opening scoreboard in this case) and the playerid is the id of the layer that he wants the ping.
Not sure if there is a better way, because I myself am just 1-2 weeks into this, but I hope I could help.