25.10.2018, 17:43
How to make a countdown in TD?
5, 4, 3, 2, 1, START
5, 4, 3, 2, 1, START
new timer; timercount = 0, str[100];
//On Your Function
timercount = 5; // 5 seconds
timer = SetTimer("CountDown", 1000, true); // CountDown
forward CountDown()
public CountDown()
{
timercount--;
if(timercount == 0)
{
format(str, sizeof(str), "~r~START!");
KillTimer(timer);
}
else
{
format(str, sizeof(str), "~b~STARTS in: %i SECONDS.", timercount);
}
TextDrawSetString(textdrawname, str);
return true;
}
#define COUNT_DOWN_TIMER 5 // 5 seconds countdown, edit this value as you wish
// Global Variables
new timer, str[64];
// Start the countdown, command or whatever
timer = COUNT_DOWN_TIMER; // Seconds to countdown, define above
SetTimerEx("CountDown", 250, false, "i", playerid); // Be sure to pass playerid to CountDown callback, you will need it
forward CountDown(playerid); // You always need to forward custom callbacks before calling them
public CountDown(playerid){
timer--;
if(timer > 1){ // 2 3 4 5 etc
format(str, sizeof(str), "Starting in %i seconds.", timer);
// GameTextForPlayer or
// SendClientMessage or
// TextDrawSetString
}
if(timer == 1){ // value 1 only
format(str, sizeof(str), "Starting in %i second.", timer); // 1 second IS NOT 1 secondS
// GameTextForPlayer or
// SendClientMessage or
// TextDrawSetString
}
if(timer <= 0){ // Count down ended!
format(str, sizeof(str), "Count down ended! Starting...");
// GameTextForPlayer or
// SendClientMessage or
// TextDrawSetString
return 1; // Don't call the count down anymore
}
return SetTimerEx("CountDown", 1000, false, "i", playerid);
}