09.04.2007, 03:03
A small but effective countdown, by me :
First some variables needed :
Under OnGameModeInit :
The dcmd command :
The timer:
The function i used to play sounds:
Thanks for pointing that boylett , i added a min and max limit and changed the order of errors messages.
First some variables needed :
pawn Код:
new countdown_seconds,
countdown_string[40];
Under OnGameModeInit :
pawn Код:
SetTimer("countdown_timer",1000,true);
The dcmd command :
pawn Код:
dcmd_countdown(playerid, param[])
{
new seconds = strval(param);
if (countdown_seconds)
SendClientMessage(playerid,0xFF0000FF,"A countdown is already started.");
else if (seconds < 3 || seconds > 300)
SendClientMessage(playerid,0xFF0000FF,"You must enter a duration between 3 and 300.");
else
{
format(countdown_string,40,"You started a countdown of %d seconds.",seconds);
SendClientMessage(playerid,0x00FF00FF,countdown_string);
countdown_seconds = seconds+1;
}
return 1;
}
The timer:
pawn Код:
public countdown_timer()
{
if (countdown_seconds)
{
format(countdown_string,6,"~w~%d",countdown_seconds-1);
GameTextForAll(countdown_string,1100,4);
SoundForAll(1056);
countdown_seconds --;
if (!countdown_seconds)
{
GameTextForAll("~r~go !",2000,4);
SoundForAll(1057);
}
}
}
The function i used to play sounds:
pawn Код:
SoundForAll(sound)
{
for (new i = 0, j = GetMaxPlayers(); i < j; i ++)
if (IsPlayerConnected(i))
PlayerPlaySound(i,sound,0.0,0.0,0.0);
}
Thanks for pointing that boylett , i added a min and max limit and changed the order of errors messages.