. . . Posted December 29, 2021 Share Posted December 29, 2021 I was wondering is there a line of code to see if a player has a green/yellow/red ping connection to a server? I want to make somethings in mod do things faster, ect. if someone has worse ping then it isn't as annoying for them Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/ Share on other sites More sharing options...
IronHunter Posted December 30, 2021 Share Posted December 30, 2021 (edited) In playerstatusscreen.lua, there is code for the host and client performance TheNet:GetClientTable() TheNet:GetClientTable() returns a ordered list of client data These ones seem to be used by this klei code, I didn't do a data dump of the function to see if there is other data. userid colour prefab userflags base_skin playerage performance (for host) netscore (for clients) I have no idea for sure if this is the correct code, buts its a start to hunt down the solution. Edited December 30, 2021 by IronHunter 1 Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529343 Share on other sites More sharing options...
penguin0616 Posted December 30, 2021 Share Posted December 30, 2021 (edited) The green/yellow/red bar for players is determined by their netscore. If I remember correctly, 0 is green, 1 is yellow, 2 is red. If you want their actual ping, that can be retrieved on the client-side with TheNet:GetPing() or TheNet:GetAveragePing(). I'm not sure what it uses for the average. Edited December 30, 2021 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529376 Share on other sites More sharing options...
. . . Posted December 30, 2021 Author Share Posted December 30, 2021 9 hours ago, penguin0616 said: The green/yellow/red bar for players is determined by their netscore. If I remember correctly, 0 is green, 1 is yellow, 2 is red. Is there a code for it for this netscore thing? Like TheNet:GetClientNetScore() or something then it can be used in functions and stuff? Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529477 Share on other sites More sharing options...
penguin0616 Posted December 30, 2021 Share Posted December 30, 2021 1 hour ago, . . . said: Is there a code for it for this netscore thing? Like TheNet:GetClientNetScore() or something then it can be used in functions and stuff? TheNet:GetClientTableForUser(klei_id) returns the table of information that IronHunter outlined. 14 hours ago, IronHunter said: userid colour prefab userflags base_skin playerage performance (for host) netscore (for clients) That is how you can get the netscore. Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529500 Share on other sites More sharing options...
. . . Posted December 30, 2021 Author Share Posted December 30, 2021 2 hours ago, penguin0616 said: TheNet:GetClientTableForUser(klei_id) returns the table of information that IronHunter outlined. Would it be used like this? local function Something(inst) local player = TheNet:GetClientTableForUser(inst) if player.netscore >= 2 then print("lag") end end or it's just much more complicated, if it is then nvm Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529544 Share on other sites More sharing options...
CarlZalph Posted December 30, 2021 Share Posted December 30, 2021 (edited) 16 minutes ago, . . . said: Would it be used like this? local function Something(inst) local player = TheNet:GetClientTableForUser(inst) if player.netscore >= 2 then print("lag") end end or it's just much more complicated, if it is then nvm If you're doing it like that, then you'd also want to check if player isn't nil. And the input for TheNet:GetClientTableForUser is a userid. Assuming you're passing a player entity into it, then get its userid via `inst.userid`. If whatever you're doing needs a higher precision of the latency, then have the client send in its average ping or a current timestamp with the mod RPC call to the server to let it do some math and compensate for whatever it is you're trying to compensate. 14 hours ago, penguin0616 said: If you want their actual ping, that can be retrieved on the client-side with TheNet:GetPing() or TheNet:GetAveragePing(). I'm not sure what it uses for the average. Game uses RakNet for its network handling, and it has an API call that uses the same syntax. Briefly reading over the code bits it looks like an average of the last 5 ping responses. https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeerInterface.h#L334 https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeer.cpp#L2142 https://github.com/facebookarchive/RakNet/blob/master/Source/RakNetTypes.h#L462 Edited December 30, 2021 by CarlZalph 2 Link to comment https://forums.kleientertainment.com/forums/topic/136598-is-there-a-way-to-check-a-players-ping/#findComment-1529547 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now