Reserved Slot System

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:



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)


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.



#player.GetAll()


Returns numbers of players? >w<

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

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.

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…

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!