Countdown
#1

How can I make a countdown system with gametextforall? :0
Reply
#2

With timer's.
Quote:

public OnPlayerSpawn(playerid)
{
SetTimer("Five", 1000, 0);
SetTimer("Four", 2000, 0);
SetTimer("Three", 3000, 0);
SetTimer("Two", 4000, 0);
SetTimer("One", 5000, 0);
SetTimer("Gooooo", 6000, 0);

}

public Five()
{
GameTextForAll("~r~5", 2000, 4);
}

public Four()
{
GameTextForAll("~r~4", 2000, 4);
}

public Three()
{
GameTextForAll("~r~3", 2000, 4);
}

public Five()
{
GameTextForAll("~r~5", 2000, 4);
}

public Two()
{
GameTextForAll("~r~2", 2000, 4);
}

public One()
{
GameTextForAll("~r~1", 2000, 4);
}

public Gooooo()
{
GameTextForAll("~r~Gooooo", 2000, 4);
}

Reply
#3

And with a command?
Reply
#4

Quote:
Originally Posted by McCarthy
Посмотреть сообщение
And with a command?
Just put the timers under your command instead of OnPlayerSpawn ? Come on , think.
Anyway. I think this is a better way , you don't want too many timers and especially when there is an easier way:

https://sampforum.blast.hk/showthread.php?tid=169023

On top
pawn Код:
new CountDownVar = 4;
command to start the timer
pawn Код:
if(!strcmp(cmdtext, "/countdown", true))
{
CountDownTimer = SetTimer("CountDown", 1000, false);
return 1;
}
somewhere(out of callbacks).

pawn Код:
forward CountDown();
public CountDown()
{
     CountDownVar--; //Thanks for the fix.
     new str[128];
     if(CountDownVar == 0)
     {
            KillTimer(CountDownTimer);
            CountDownVar = 4; //Edit thanks to Hiddos...i was sleepy :S
     }
     else
     {
           format(str, sizeof(str), "Count Down: %d", CountDownTimer);
           GameTextForAll(str, 1000, 1);
     }
     return 1;
}
Reply
#5

Here you go:
Quote:

public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/cdown", true) == 0)
{
SetTimer("Five", 1000, 0);
SetTimer("Four", 2000, 0);
SetTimer("Three", 3000, 0);
SetTimer("Two", 4000, 0);
SetTimer("One", 5000, 0);
SetTimer("Gooooo", 6000, 0);
}
return 1;
}

public Five()
{
GameTextForAll("~r~5", 2000, 4);
}

public Four()
{
GameTextForAll("~r~4", 2000, 4);
}

public Three()
{
GameTextForAll("~r~3", 2000, 4);
}

public Five()
{
GameTextForAll("~r~5", 2000, 4);
}

public Two()
{
GameTextForAll("~r~2", 2000, 4);
}

public One()
{
GameTextForAll("~r~1", 2000, 4);
}

public Gooooo()
{
GameTextForAll("~r~Gooooo", 2000, 4);
}

You might get a warning for loose indentitation ..
Reply
#6

Quote:
Originally Posted by dLu
Посмотреть сообщение
With timer's.
What if he wants to do a countdown to 30? 30 timers? That would be a big mistake.
You could use this function:
pawn Код:
public CountDown(seconds)
{
     new msg[64];
     if(seconds == 0)
     {
          //time's up - your code
     }
     else
     {
          //To display how much seconds left:
          format(msg,64,"Time left: %i",seconds);
          GameTextForAll(msg,1000,3);
          seconds --;
          SetTimerEx("CountDown",1000,0,"i",seconds); //countdown continues
     }
}
Reply
#7

The countdown above kinda sucks, because you need 6 timers for just 1 countdown.
In my example you just need 1 timer
pawn Код:
new SCount = 11;
new SStart = 0;
new Timer;

CMD:start(playerid, cmdtext)
{
    if(SStart == 0)
    {
        Timer = SetTimer("Counter", 1000, true); // Creates a timer that doesnt stop untill you say
        SStart = 1;
    } else return SendClientMessage(playerid, -1, " ** Theres already a countdown going on! ");
    return 1;
}

forward Count();
public Count()
{
    SCount --; // Removes 1 from SCount
    switch(SCount)
    {
        case 11:{} // if SCount == 11, then do this
        case 10:{ GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~10", 2000, 3); } // if SCount == 10, then do this
        case 9: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~9", 2000, 3); }// if SCount == 9, then do this
        case 8: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~8", 2000, 3); } // etc
        case 7: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~7", 2000, 3); }
        case 6: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~6", 2000, 3); }
        case 5: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~5", 2000, 3); }
        case 4: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~4", 2000, 3); }
        case 3: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~3", 2000, 3); }
        case 2: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~2", 2000, 3); }
        case 1: { GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~y~1", 2000, 3); }
        case 0: {
            GameTestForAll("~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~ ] GO GO GO ]", 4000, 3);
            KillTimer(Timer); // Kills the timer so it stops counting
            SStart = 0; // You can use the command again
            SCount = 11; // Resets the variable to 11
        }
    }
    return 0;
}
Edit: Oh duh, late
Reply
#8

Thank you...just one thing

E:\SAMP\gamemodes\FStudios.pwn(14987) : warning 203: symbol is never used: "countdown"
Reply
#9

I Get it From SA-MP Forum

pawn Код:
/*---------------------------------
--             :)                --
--                               --
--       Made By V1ceC1ty        --
--     anti countspam by Radi    --
--                               --
--             :)                --
---------------------------------*/




#include <a_samp>

#define COLOR_BLUE 0x0259EAFF

forward One();
forward Two();
forward Three();
forward Four();
forward Five();
forward GoGoGo();
forward countspam2();
new countspam[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/count", cmdtext, true, 10) == 0)
    {
        if(countspam[playerid]==0)
        {
            SetTimer("Five", 1000, 0);
            SetTimer("Four", 2000, 0);
            SetTimer("Three", 3000, 0);
            SetTimer("Two", 4000, 0);
            SetTimer("One", 5000, 0);
            SetTimer("GoGoGo", 6000, 0);
            countspam[playerid]=1;
            SetTimer("countspam2",120000,0);
        }
        else
        {
            SendClientMessage(playerid,COLOR_BLUE, "Please wait before using this Command again.");
        }
        return 1;
    }
    return 0;
}

public Five()
{
    GameTextForAll("~h~~h~~h~5",2000,3);
    return 1;
}

public Four()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4",2000,3);
    return 1;
}

public Three()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3",2000,3);
    return 1;
}

public Two()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2",2000,3);
    return 1;
}

public One()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2~n~~r~1",2000,3);
    return 1;
}

public GoGoGo()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2~n~~r~1~n~~n~~>~~g~GO ~b~GO ~r~GO~y~!~<~",3000,3);
    return 1;
}
Reply
#10

Quote:
Originally Posted by McCarthy
Посмотреть сообщение
Thank you...just one thing

E:\SAMP\gamemodes\FStudios.pwn(14987) : warning 203: symbol is never used: "countdown"
Just delete this line, your script isnt using the variable "countdown": thats why your compiler says this

Quote:
Originally Posted by SmileyForCheat
Посмотреть сообщение
I Get it From SA-MP Forum

pawn Код:
/*---------------------------------
--             :)                --
--                               --
--       Made By V1ceC1ty        --
--     anti countspam by Radi    --
--                               --
--             :)                --
---------------------------------*/




#include <a_samp>

#define COLOR_BLUE 0x0259EAFF

forward One();
forward Two();
forward Three();
forward Four();
forward Five();
forward GoGoGo();
forward countspam2();
new countspam[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/count", cmdtext, true, 10) == 0)
    {
        if(countspam[playerid]==0)
        {
            SetTimer("Five", 1000, 0);
            SetTimer("Four", 2000, 0);
            SetTimer("Three", 3000, 0);
            SetTimer("Two", 4000, 0);
            SetTimer("One", 5000, 0);
            SetTimer("GoGoGo", 6000, 0);
            countspam[playerid]=1;
            SetTimer("countspam2",120000,0);
        }
        else
        {
            SendClientMessage(playerid,COLOR_BLUE, "Please wait before using this Command again.");
        }
        return 1;
    }
    return 0;
}

public Five()
{
    GameTextForAll("~h~~h~~h~5",2000,3);
    return 1;
}

public Four()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4",2000,3);
    return 1;
}

public Three()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3",2000,3);
    return 1;
}

public Two()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2",2000,3);
    return 1;
}

public One()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2~n~~r~1",2000,3);
    return 1;
}

public GoGoGo()
{
    GameTextForAll("~h~~h~~h~5~n~~b~4~n~~y~3~n~~p~2~n~~r~1~n~~n~~>~~g~GO ~b~GO ~r~GO~y~!~<~",3000,3);
    return 1;
}
Again an un-efficient countdown
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)