I am having some problems understanding the whole Plugin_Continue, Plugin_Handled, and Plugin_Stop for timers. When OnClientPutInServer is triggered, I set off a 1.5 second timer which runs the code below. In this function I have a set of different situations contained in if statements. The first if is there to make sure we have at least the min number of bots. The rest are to take place after that min limit has been reached. Only one of those situations should be called at once so if one does get called I do not want the rest of the if statements being called.
PHP Code:
/**
* Spawn correct number of starting bots
*
*/
public Action: ControlClients(Handle: timer, any: Client)
{
// Get survivor values
new survivors = TeamPlayers(2);
new human_survivors = HumanTeamPlayers(2);
new survivors_min = GetConVarInt(Survivors_Min_Limit);
new survivors_max = GetConVarInt(Survivors_Max_Limit);
// We need to atleast reach our min number
if (survivors < survivors_min)
{
for (;survivors < survivors_min; survivors++)
{
SpawnFakeClient();
LogMessage("Spawning starting bots");
}
return Plugin_Continue;
}
if (Bot_Takeover)
{
// If team is full of humans tell client so
if (human_survivors == survivors_max)
{
survivors_full = true;
LogMessage("Survivor team full. human survivors = %i", human_survivors);
}
// If min survivor limit is all humans and max survivor limit hasn't been reached yet
if (human_survivors == survivors_min && survivors != survivors_max)
{
// Add one to survivor limit and spawn bot
new survivors_min_new = survivors_min + 1;
SetConVarInt(Survivors_Min_Limit, survivors_min_new);
SpawnFakeClient();
LogMessage("Spawning bot for takeover. human_survivors = %i, survivors = %i", human_survivors, survivors);
// Let the new client know a bot is spawning for him and what to do
bot_spawned = true;
return Plugin_Continue;
}
// If survivor team is full but contains bots change the human players team
if (survivors == survivors_max && human_survivors != survivors_max)
{
ChangeClientTeam(Client, 2);
LogMessage("Changing client team. survivors = %i, human_survivors = %i", survivors, human_survivors);
// Let the client know he has been auto connected
auto_connect = true;
return Plugin_Continue;
}
}
// Once the missing bots are made, dispose of the timer
SpawnTimer = INVALID_HANDLE;
return Plugin_Stop;
}