View Single Post
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 01-02-2018 , 11:40   Re: [Help] Simple Countdown error
Reply With Quote #2

Review below code:
HTML Code:
#include <amxmodx>
#include <amxmisc>

#define TASK_COUNT 2018

new g_iCount

new const CountdownSounds[][] = 
{
	"BR/one.wav",
	"BR/two.wav",
	"BR/three.wav",
	"BR/four.wav",
	"BR/five.wav",
	"BR/six.wav",
	"BR/seven.wav",
	"BR/eight.wav",
	"BR/nine.wav",
	"BR/ten.wav"
}

public plugin_init()
{
	// Use below event instead register_logevent("Logevent_Start", 2, "1=Round_Start");
	register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
}

public plugin_precache()
{
	for(new i = 0; i < sizeof(CountdownSounds); i++)
	{
		precache_sound(CountdownSounds[i]);
	}
}

public Event_NewRound()
{
	// Set hardcode countdown global variable
	g_iCount = 10
	
	// Call countdown function every 1s
	set_task(1.0, "CountdownFunc", TASK_COUNT, _, _, "b")
}

public CountdownFunc()
{
	// If g_iCount equal to 0
	if(g_iCount > 0)
	{
		client_print(0, print_center, "Battle starts in %d", g_iCount)
		client_cmd(0, "spk ^"%s^"", CountdownSounds[g_iCount]);
	}
	else
	{
		// Remove CountdownFunc task
		remove_task(TASK_COUNT)
		
		// Start other function below
	}
	
	// Deduct countdown variable
	g_iCount--
}

Last edited by zmd94; 01-04-2018 at 09:47.
zmd94 is offline