Hi Happy new year everyone,
I need some help with this code which is a simple countdown from 10 to 0 the problem is when i set the countdown variable to 10 at round start it doesn't get set to 10 i suppose because the countdown throws some negative numbers like if the variable number was set to 0 or -1, but when i call the countdown by a clcmd it counts without errors the code is down below, i don't have any idea why so i came here for help here is the code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
new g_count;
new const countdown_sounds[][] =
{
"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()
{
register_logevent("logevent_start_rnd", 2, "1=Round_Start");
register_clcmd("say /call", "count");
}
public plugin_precache()
{
for(new i = 0; i < sizeof(countdown_sounds); i++)
{
precache_sound(countdown_sounds[i]);
}
}
public count(id)
{
g_count = 10;
countdown_start(id);
}
public logevent_rnd_start()
{
new players[32], id, pnum;
get_players(players, pnum);
for(new i = 0; i < pnum; i++)
{
id = players[i];
if(!is_user_alive(id))
return PLUGIN_HANDLED;
g_count = 10;
//strip_user_weapons(id);
set_task(5.0, "countdown_start", id);
//set_task(1.0, "show_info", TASK_SHOW_HUD + id);
}
return PLUGIN_HANDLED;
}
public countdown_start(id)
{
g_count -= 1;
client_print(0, print_center, "%s Battle Starts in %i", TAG, g_count);
client_cmd(0, "spk ^"%s^"", countdown_sounds[g_count]);
if(g_count > 0)
{
set_task(1.0, "countdown_start", id);
}
else
{
set_task(2.0, "Battle_start", id);
}
}
BTW: there is one error that is index out of bound which happens because of the count returning a negative number and the countdown_sounds variable has no negative number so it throws the error but that does happen in the clcmd /call.
Thanks in advance.