Delay after writing a command
#5

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
It's easy. Read the comments carefully and if something needs more explanation, feel free to ask:

pawn Код:
// To get this to work, you gotta declare a per-player global variable to use it for counting down
new CountDown[MAX_PLAYERS];
// You will also need a variable to hold the player timer, so we can use it on KillTimer()
new PlayerTimer[MAX_PLAYERS];

// The following code should be placed under your command or where the action begins
CountDown[playerid] = 5; // set the count down variable to 5, so it counts down from 5 to 0
PlayerTimer[playerid] = SetTimerEx("ExecuteCommand", 1000, true, "i", playerid); // creating a repeatedly timer with an interval of 1 second, and passing the playerid that we will execute the cmd on
// As SetTimerEx returns the timer id, so we made the PlayerTimer var hold the timerid so we can kill it later.
// -
// Now, let's forward the function that the timer is gonna call
forward ExecuteCommand(playerid);

public ExecuteCommand(playerid)
{
    CountDown[playerid] --; // decreases the CountDown variable by 1
    if(CountDown[playerid] == 0) // (IF) the CountDown variable reached 0
    {
        KillTimer(PlayerTimer[playerid]); // kill the timer, so it won't call this function again.
        // Execute your command here
        // Example: GivePlayerWeapon(playerid, 24, 300);
        return 1;
    }
    else // (ELSE) if the CountDown variable hasn't reached 0 yet.
    {
        // Tell the player how many seconds left
        // Example:
        new str[20];
        format(str, sizeof str, "%i second(s) left", CountDown[playerid]);
        GameTextForPlayer(playerid, str, 1000, 3);
    }
    return 1;
}
I will check it tomorrow THANKS MAN
Reply


Messages In This Thread
Delay after writing a command - by BoomShnizel - 05.11.2012, 14:28
Re: Delay after writing a command - by sampreader - 05.11.2012, 14:30
Re: Delay after writing a command - by BoomShnizel - 05.11.2012, 14:35
Re: Delay after writing a command - by [KHK]Khalid - 05.11.2012, 15:07
Re: Delay after writing a command - by BoomShnizel - 05.11.2012, 16:16
Re: Delay after writing a command - by BoomShnizel - 05.11.2012, 17:16
Re: Delay after writing a command - by Abreezy - 05.11.2012, 18:22
Re: Delay after writing a command - by cosbraa - 05.11.2012, 20:22
Re: Delay after writing a command - by BoomShnizel - 06.11.2012, 03:37

Forum Jump:


Users browsing this thread: 1 Guest(s)