Hello Facepunch,
I'm doing a reserved slot system and want to ask you for a little help with it.
To determine how many players are online at the moment I'm doing this:
[CODE]
hook.Add("PlayerConnect", "egm_join_manager_connect", function()
print("Player connected")
EGM.JoinManager.onlinePlayerNum = EGM.JoinManager.onlinePlayerNum + 1
end)
hook.Add("PlayerDisconnected", "egm_join_manager_disconnect", function()
print("Player disconnected")
EGM.JoinManager.onlinePlayerNum = EGM.JoinManager.onlinePlayerNum - 1
end)
[/CODE]
The problem I have is that PlayerConnect is not called for players that were online before the map changes.
So let's say 20 people are online and the map changes, EGM.JoinManager.onlinePlayersNum would be 0 even if 20 people are connected after the map change.
Is there any better method to get how many players are online? I can't use #player.GetAll() because players that aren't spawned (e.g they are in loading screen) need to count too.
[code]
#player.GetAll()
[/code]
Returns numbers of players? >w<
[QUOTE=P4sca1;50072912]I can't use #player.GetAll() because players that aren't spawned (e.g they are in loading screen) need to count too.[/QUOTE]
I use sockets to get around this limitation. It does the exact same thing as hlsw or server browsers, it just sends a source engine query and decodes the response.
requires bromsock
[url]https://github.com/blastehh/GModAddons/blob/master/sourcequery/lua/autorun/server/sv_sourcequery.lua[/url]
[QUOTE=Blasteh;50073128]I use sockets to get around this limitation. It does the exact same thing as hlsw or server browsers, it just sends a source engine query and decodes the response.
requires bromsock
[url]https://github.com/blastehh/GModAddons/blob/master/sourcequery/lua/autorun/server/sv_sourcequery.lua[/url][/QUOTE]
Just tested it and it is working fine. Thanks for the code!
[editline]5th April 2016[/editline]
Will there be any performace issues when I run a SourceQuery every player connect/disconnect?
I think there are a maximum of 3 connects/disconnects a minute.
[QUOTE=P4sca1;50073247]Just tested it and it is working fine. Thanks for the code!
[editline]5th April 2016[/editline]
Will there be any performace issues when I run a SourceQuery every player connect/disconnect?
I think there are a maximum of 3 connects/disconnects a minute.[/QUOTE]
you can try caching the result and limit to 1 query/sec ?
or put the query on the timer to update a global and just check the global when you need to...
[QUOTE=Blasteh;50073311]you can try caching the result and limit to 1 query/sec ?
or put the query on the timer to update a global and just check the global when you need to...[/QUOTE]
Okay, thank you!
I just spammed 20 querys in a few seconds with about 40 players online and everything was working fine.
Again, thanks for the code!
Sorry, you need to Log In to post a reply to this thread.