25.03.2014, 21:03
So hai guys, today I'll teach you guys how to make a simple countdown system
to begin we'll create a variable:
We forward the countdown
Then we'll create the public function for the countdown
and inside the countdown() we'll put:
and then go to
and we'll create the command /countdown by:
and heres the full code:
I hope you like this very simple tutorial and it's helpful for some players
to begin we'll create a variable:
pawn Код:
new CountDown = -1;
pawn Код:
forward countdown();
Then we'll create the public function for the countdown
pawn Код:
public countdown()
{
return 0;
}
and inside the countdown() we'll put:
pawn Код:
public countdown()
{
if(CountDown == 6) GameTextForAll("~w~Starting...",1000,6); // Sends a message saying Countdown is starting
CountDown--; // And make sure to decrease its value by using '--'
if(CountDown==0) // Here we check if Countdown reaches 0 Seconds
{
GameTextForAll("~g~GO~ r~!",1000,6); // Sends a gametext for all saying GO
CountDown = -1; // and setting the CountDown to -1
for(new i; i < MAX_PLAYERS; i++) // Here we make a Loop
{
PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0); // and on the countdown we give a sound
}
return 0;
}
else
{
new text[7]; // Here we create a variable of 7 size
format(text,sizeof(text),"~w~%d",CountDown); // Format the countdown message
for(new i; i < MAX_PLAYERS; i++) // We Loop again
{
PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0); // Plays sounds on Countdown
}
GameTextForAll(text,1000,6); // And displays Countdown for everyone
}
SetTimer("countdown",1000,0); // and here we set the timer of countdown
return 0;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
pawn Код:
if(!strcmp(cmdtext, "/countdown", true))
{
if(CountDown == -1) // When countdown is on -1
{
CountDown = 6; // We set 6 on Countdown variabel
SetTimer("countdown", 1000, 0); // and we set Timer for every second of the countdown
}
return 1;
}
pawn Код:
new CountDown = -1;
forward countdown();
public countdown()
{
if(CountDown == 6) GameTextForAll("~w~Starting...",1000,6);
CountDown--;
if(CountDown==0)
{
GameTextForAll("~g~GO~ r~!",1000,6);
CountDown = -1;
for(new i; i < MAX_PLAYERS; i++)
{
PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
}
return 0;
}
else
{
new text[7];
format(text,sizeof(text),"~w~%d",CountDown);
for(new i; i < MAX_PLAYERS; i++)
{
PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
}
GameTextForAll(text,1000,6);
}
SetTimer("countdown",1000,0);
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/countdown", true))
{
if(CountDown == -1)
{
CountDown = 6;
SetTimer("countdown", 1000, 0);
}
return 1;
}
return 0;
}