SA-MP Forums Archive
Countdown help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Countdown help (/showthread.php?tid=461415)



Countdown help - Finn707 - 01.09.2013

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.


Re: Countdown help - Borg - 02.09.2013

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!


Re: Countdown help - Finn707 - 02.09.2013

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++;
}



Re: Countdown help - Borg - 02.09.2013

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);
        }
    }
}



Re: Countdown help - Finn707 - 02.09.2013

Thanks man