SA-MP Forums Archive
Can someone edit this command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Can someone edit this command (/showthread.php?tid=88039)



Can someone edit this command - killdahobo99 - 23.07.2009

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


Re: Can someone edit this command - killdahobo99 - 23.07.2009

Anyone? please help


Re: Can someone edit this command - killdahobo99 - 24.07.2009

bump


Re: Can someone edit this command - Joe Staff - 24.07.2009

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



Re: Can someone edit this command - killdahobo99 - 24.07.2009

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