I did it few times, but wierd things happen!!!! I'll tell you what i tried.:
in client_connect i did get_playersnum and if it has 10 players set a pass and do a client print.
in client_disconnect i did get_playersnum and if it has 10 players (before the client has left, meaning there are 9 now) remove the pass.
And this is what happened:
the 10th has logged in a pass was SET.
the 10th has logged out the pass was REMVOED.
the 8th has logged out a pass was set....
wierd random shit happen and i dont know why is this..
ill post the public here:
PHP Code:
// cvar "cvar_playersleft" equals to 10, yeah im sure.
public CheckEmpty(id) // Called on client_disconnect
{
if (get_maxplayers() == get_pcvar_num(cvar_playersleft))
return PLUGIN_HANDLED
if (get_playersnum() == get_pcvar_num(cvar_playersleft))
{
set_cvar_string("sv_password", "")
client_print(0, print_chat, "%s Server password has been REMOVED.", PREFIX)
set_task(5.0, "CheckNow")
}
return PLUGIN_CONTINUE
}
public CheckFull(id) // Called on client_Connect
{
if (get_maxplayers() == get_pcvar_num(cvar_playersleft))
return PLUGIN_HANDLED
if (get_playersnum()+1 == get_pcvar_num(cvar_playersleft))
{
new rnd = random_num(99, 9999)
new pass[10]
num_to_str(rnd, pass, 9)
set_cvar_string("sv_password", pass)
client_print(0, print_chat, "%s Server is now password PROTECTED", PREFIX)
}
return PLUGIN_HANDLED
}
and dont tell me why you did get_playersnum()+1, cuz i tried it in many many variations, with +1 and without ina ll sequences and havent found the correct code. help pls!