Thread: Timer Issue
View Single Post
Author Message
Lubricant Jam
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-29-2018 , 02:55   Timer Issue
Reply With Quote #1

Hey,

This is my first time creating my own plugins so please bare with me on this, I'm learning as I go from the usual tinkering and adaptation.

I am trying to create a simple timer which allows one person to complete the map, then slays them and after 30 seconds slays the rest of the server. It works perfectly for the first round, however any rounds after that the countdown starts at the beginning of every round after that and they continue to stack on top of each other.

Code:
public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
	EndZoneTimer = INVALID_HANDLE;
	g_iCompleted = 0;
	g_iCountdown = 30;
	EndZoneTimer = CreateTimer(1.0, EndZoneCheck, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public Action EndZoneCheck(Handle timer, int userid)
{
    for (int client = 1; client <= MaxClients; ++client)
    {
		if (IsClientInGame(client) && coursetimer_InEndZone(client) && IsPlayerAlive(client))
		{
			if (g_iCompleted == 0) {
				EmitSoundToAll("training/countdown.wav", client, SNDCHAN_VOICE, SNDLEVEL_RAIDSIREN);
				PrintToChatAll("[SM] \x07%N \x02has reached the end!", client);
				PrintToChatAll("[SM] \x0330 seconds remaining to complete the map.");
				ForcePlayerSuicide(client);
				CountdownTimer = CreateTimer(1.0, Timer_Countdown, GetClientUserId(client), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
				g_iCompleted++;
			}
		}
	}
}

public Action Timer_Countdown(Handle timer, int userid)
{
	int client = GetClientOfUserId(userid);

	if (g_iCountdown > 0 && IsClientInGame(client))
	{
		if ((g_iCountdown == 20) || (g_iCountdown == 10) || (g_iCountdown == 5) || (g_iCountdown < 4))
			if (g_iCountdown == 1)
			{
				CountdownTimer = INVALID_HANDLE;
				PrintToChatAll("[SM] \x03%d second remaining to complete the map.", g_iCountdown);
				for (int i = 1; i <= MaxClients; ++i)
				{
					if(IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) > 1)
					{
						ForcePlayerSuicide(i);
					}
				}
			}
			else PrintToChatAll("[SM] \x03%d seconds remaining to complete the map.", g_iCountdown);

		g_iCountdown--;
	}
}
Any help is greatly appreciated.

Last edited by Lubricant Jam; 12-29-2018 at 09:22.
Lubricant Jam is offline