Total players connected.

I can make myself a decent script for a reserved slot system, but I need a way to know how many players are connected. (Not spawned as entities, but even just in loading screen.) .

For the loading screen part you will need this module : gmsv_gatekeeper

[lua]
local clients = gatekeeper.GetNumClients()
print(clients.active) – prints the number of clients currently active (have spawned) in the server
print(clients.spawning) – prints the number of clients in the connection process
print(clients.total) – prints the total number of clients in the server (connecting AND in game)
[/lua]

So this is what I need?

So something in lua I should make, as IF clients.total is greater/equal to, say, 11, then close=1, else close=0, run this every frame. If close is 1, and I use the gamemode hook for players connecting, then kick them, and say the non-reserved slots are full. (Using that sv_ command to hide the real player-limit.) .

[lua]require(“gatekeeper”)

local reservedslots = 3
local kickreason = “Kicked for using a reserved slot!”

local ReservedAdminsOnline = {}

local pass_new = CreateConVar(“sv_password_new”, “”, FCVAR_PROTECTED | FCVAR_NOTIFY)
local pass_makeroom = CreateConVar(“sv_password_makeroom”, “”, FCVAR_PROTECTED | FCVAR_NOTIFY)

local ReservedAdmins = string.Explode( "
", file.Read(“BAdmin/reservedslots.txt”) )

local function PasswordCheck(name, pass, steamid, ip)

if name == "" then --Kicks people who join with no name or "unconnected"
	return { false, "Hahaha! No." }
end

local players = gatekeeper.GetNumClients().total

local IsReserved = table.HasValue( ReservedAdmins, steamid )

if players >= MaxPlayers() - reservedslots + #ReservedAdminsOnline and !IsReserved  then
	return { false, kickreason }
elseif IsReserved then
	table.insert( ReservedAdminsOnline, steamid )
	game.ConsoleCommand("sv_visiblemaxplayers ".. MaxPlayers() - reservedslots + #ReservedAdminsOnline .."

")
return true
end

end
hook.Add(“PlayerPasswordAuth”, “ReservedSlots:PlayerPasswordAuth”, PasswordCheck)

local function PlayerDisconnected( ply )
if table.HasValue( ReservedAdmins, ply:SteamID()) then
for k,stmid in pairs( ReservedAdminsOnline ) do
if stmid == ply:SteamID() then
table.remove( ReservedAdminsOnline, k )
end
end
game.ConsoleCommand("sv_visiblemaxplayers “… MaxPlayers()-reservedslots+#ReservedAdminsOnline …”
")
end
end
hook.Add( “PlayerDisconnected”, “ReservedSlots:PlayerDisconnected”, PlayerDisconnected )

local function SetVisibleSlots()
game.ConsoleCommand("sv_visiblemaxplayers “… MaxPlayers()-reservedslots …”
")
end
hook.Add(“Initialize”, “ReservedSlots:Initialize”, SetVisibleSlots)[/lua]

Here’s a simple reserved slot mod I made with gatekeeper.

It changes the visible max players to compensate for admins online so player won’t be constantly trying to join and getting kicked.

Actually you shouldn’t need that… Some hook was fired when someone is connecting, I suppose it was PlayerConnected or OnPlayaerConnect or something like that, and the hook gives you the SteamID, IP and name of the connecting player. Just add them to a table of connecting players, and remove them from there on initial spawn. If they disconnect before they spawn, remove them from there, too.

But you can’t kick people using PlayerConnect and that’s the whole point of gatekeeper. Trust me, this is a lot better than using the default hooks.

My server has 16 slots, and sv_visiblemaxplayers on 11. I need it to stay at 11, with 5 reserved slots. (I’m ok with it showing something like 13/11, and I don’t want any non-reserved members auto-kicked just so that an admin can get in, who already got in before it was 11/11.) Is this how your script does it?

EDIT:

Made my own.