The plugin works, but not as expected. Currently, when I set MinPlayers to 10, it takes at least 11 players to enable respawn timer and at most 8 players to disable respawn timer. Why is there a 3 player gab between enabling and disabling? What I am expecting is that it takes at least 10 players to enable respawn timer, and at most 9 players to disable respawn timer. The problem is the client callbacks being used. This is what I did to make this plugin work as expected:
Code:
new Handle:ConMinPlayers = INVALID_HANDLE;
new Handle:ResTime = INVALID_HANDLE;
public OnPluginStart()
{
ConMinPlayers = CreateConVar("sm_respawner_threshold", "10", "Respawner Threshold");
CreateConVar("sm_respawner_version", PLUGIN_VERSION, "Respawner", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
HookConVarChange(ConMinPlayers, onChange);
ResTime = FindConVar("mp_disable_respawn_times");
}
public OnMapStart()
{
ServerCommand("mp_disable_respawn_times 1; mp_respawnwavetime 0; sm_cvar spec_freeze_time -1");
}
public OnClientPostAdminCheck(client)
{
doCheck();
}
public OnClientDisconnect_Post(client)
{
doCheck();
}
public onChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
doCheck();
}
public doCheck()
{
new bool:bSetting = GetConVarBool(ResTime);
new MinPlayers = GetConVarInt(ConMinPlayers);
new NumPlayers = 0;
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsClientInGame(i))
{
NumPlayers++;
}
}
if(NumPlayers < MinPlayers)
{
if(bSetting != true)
{
ServerCommand("mp_disable_respawn_times 1; mp_respawnwavetime 0; sm_cvar spec_freeze_time -1");
PrintToChatAll("\x01\x04[SM] Respawn Timer \x01[Disabled]");
}
}
else
{
if(bSetting != false)
{
ServerCommand("mp_disable_respawn_times 0; mp_respawnwavetime 10.0; sm_cvar spec_freeze_time 4.0");
PrintToChatAll("\x01\x04[SM] Respawn Timer \x01[Enabled]");
}
}
}