Can someone edit this command
#1

Can someone take this command and add a countdown to it?

Код:
 if (strcmp("/moon", cmdtext, true, 10) == 0 && IsPlayerAdmin(playerid) == 1)
	{
	SendPlayerFormattedText(playerid,"All get in a car!",0);
	SetGravity(0);
	return 1;
	}
So before it says "All get in a car" it says

"All players about to be sent to the moon in 5 secounds!" and a 5 secound timer comes on

thanks
Reply
#2

Anyone? please help
Reply
#3

bump
Reply
#4

Countdowns in Pawn require a callback to be made. You would have to keep a server wide variable (or you could include the variable in the callback's parameters) to keep track of the countdown. Your command would start the countdown by setting the variable to a specific number, then starting the callback with no timer really being necessary. You would use 'if' conditionals to make it send the correct message for it's respective time, then subtract the countdown variable by 1 or however many, until it reached 0 where you would have it send the correct message alongside with haulting the timers.

Example:
pawn Код:
new countdown;
forward Timer();

OnPlayerCommandText(playerid,cmdtext)
{
    if(!strcmp(cmdtext,"/countdown",true))
    {
        countdown = 3;
        Timer();
    }
}


Timer()
{
    if(countdown==3)
    {
        SendClientMessage(playerid,0xFF0000FF,"3");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==2)
    {
        SendClientMessage(playerid,0xFF0000FF,"2");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==1)
    {
        SendClientMessage(playerid,0xFF0000FF,"1");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==0)
    {
        SendClientMessage(playerid,0xFF0000FF,"Blast Off!");
        return 1;
    }
}
Reply
#5

Quote:
Originally Posted by Joe Staff
Countdowns in Pawn require a callback to be made. You would have to keep a server wide variable (or you could include the variable in the callback's parameters) to keep track of the countdown. Your command would start the countdown by setting the variable to a specific number, then starting the callback with no timer really being necessary. You would use 'if' conditionals to make it send the correct message for it's respective time, then subtract the countdown variable by 1 or however many, until it reached 0 where you would have it send the correct message alongside with haulting the timers.

Example:
pawn Код:
new countdown;
forward Timer();

OnPlayerCommandText(playerid,cmdtext)
{
    if(!strcmp(cmdtext,"/countdown",true))
    {
        countdown = 3;
        Timer();
    }
}


Timer()
{
    if(countdown==3)
    {
        SendClientMessage(playerid,0xFF0000FF,"3");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==2)
    {
        SendClientMessage(playerid,0xFF0000FF,"2");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==1)
    {
        SendClientMessage(playerid,0xFF0000FF,"1");
        countdown-=1;
        SetTimer("Timer",1000,0);
        return 1;
    }
    if(countdown==0)
    {
        SendClientMessage(playerid,0xFF0000FF,"Blast Off!");
        return 1;
    }
}
But how do i make it so my command is working with this countdown timer? i want it so when the timer is done, it sets the gravity to what ever my command had it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)