Countdown help
#1

How would I go about scripting a countdown using gametext showing something along the lines of "Ready? - 3 - 2 - 1 - Go!" (- being an interval) that is only shown to players in an event (using something like if(InEvent == 1)). One other thing that is required is that something happens to all players in the event when it hits "Go!". Such as unfreezing everyone in the event once the countdown ends.
Reply
#2

It's easy. Generaly, you should use timer.

At the beginning of gamemode declare two variables and forward our public timer.
Код:
new iCountdownStep, tCountdownTimer;
forward Countdown();
then in code that should write first ready, you must display first phrase("Ready?") and start timer.
Код:
GameTextForAll("Ready?", 1000, 4); //time=1000, style=4
iCountdownStep = 0;
tCountdownTimer = SetTimer("Countdown", 1000, true); //repeat=true
of course, if you want to display this text only to racers, you should use GameTextForPlayer(...);

and then you should declare your countdown function.
Код:
public Countdown()
{
	switch(iCountdownStep)
	{
		case 0:
		{
			GameTextForAll("3", 1000, 4);
		}
		case 1:
		{
			GameTextForAll("2", 1000, 4);
		}
		case 2:
		{
			GameTextForAll("1", 1000, 4);
		}
		default:
		{
			GameTextForAll("~g~GO!", 3000, 4);
			KillTimer(tCountdownTimer);
		}
	}
	iCountdownStep++
}
You've done it!
Reply
#3

Ahh thanks man. Where should I put my if(InEvent[playerid] == 1)? Here's what I changed your provided code to.
pawn Код:
public Countdown(playerid)
{
    switch(iCountdownStep)
    {
        case 0:
        {
            GameTextForPlayer(playerid, "3", 2000, 4);
        }
        case 1:
        {
            GameTextForPlayer(playerid, "2", 2000, 4);
        }
        case 2:
        {
            GameTextForPlayer(playerid, "1", 2000, 4);
        }
        default:
        {
            GameTextForPlayer(playerid, "~g~GO!", 3000, 4);
            TogglePlayerControllable(playerid, 1);
            KillTimer(tCountdownTimer);
        }
    }
    iCountdownStep++;
}
Reply
#4

It's not good way to create timers for each player. It's better to use my code, but use GameTextEvent(...), for example:
pawn Код:
stock GameTextEvent(const str[], time, style)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && InEvent[i])
        {
            GameTextForPlayer(i, str, time, style);
        }
    }
}
Reply
#5

Thanks man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)