2 Countdown Timers in one script
#1

Are you able to put 2 countdown timers in one script cause mine is sure not letting me. If so could i get an example :

Код:
new time = 61;
new timer1;

forward timer();
public timer()
{
    new string[128];
    if(time > 0)
    {
        time--;
        format(string, sizeof(string), "~r~%d", time - 0);
    }
    else
    {
        new playerid;
        time = 61;
        format(string, sizeof(string), "~r~GAME OVER");
        KillTimer(timer1);
        SetPlayerHealth(playerid, 0);
    }
    GameTextForAll(string, 1000, 4);
    return 1;
}
How could i make another the same, but make it as a second timer that happens Via command
Reply
#2

Couldn't you just use the same timer like so?:

pawn Код:
CMD:countdown(playerid, params[])
{
    if(!IsPlayerConnected(playerid)) return 1;
    time = 61;
    SetTimer("timer", 100, false);
    return 1;
}
Where is the other countdown going to happen?

Else, just simply copy/paste the current timer, change the name of the new timer, and then call it like I did through the command.
Reply
#3

Or simply use SetTimerEx
pawn Код:
forward Countdown(id, count, extra);
forward CountdownFinished(id, extra);
forward CountdownProceed(id, count, extra);
pawn Код:
public Countdown(id, count, extra) {
    if(count <= 0) {
        CallLocalFunction("CountdownFinished", "ii", id, extra);
    } else {
        CallLocalFunction("CountdownProceed", "iii", id, count, extra);
        SetTimerEx("Countdown", 1000, false, "iii", id, count - 1, extra);
    }
}
So if you want to use two countdowns
pawn Код:
enum { // all countdowns should be in one enum
    cdOne,
    cdTwo
}
pawn Код:
Countdown(cdOne, 61, playerid); // first countdown with 61 seconds, passes playerid as extra parameter
Countdown(cdTwo, 32, 0); // second countdown with 32 seconds, no extra parameter (just a 0)
pawn Код:
public CountdownProceed(id, count, extra) {
    switch(id) {
        case cdOne: {
            new
                string[16] = "~r~"
            ;
            valstr(string[3], time, false);
            GameTextForAll(string, 1000, 4);
        }
        case cdTwo: {
            // Do something here
        }
    }
}
pawn Код:
public CountdownFinished(id, extra) {
    switch(id) {
        case cdOne: {
            SetPlayerHealth(extra, 0.0);
            GameTextForAll("~r~GAME OVER", 1000, 4);
        }
        case cdTwo: {
            // Do something here
        }
    }
}
As I already put all your code from the first countdown at the right place you only need to add the second one
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)