/countdown bug
#1

new counter;
new countTimer;
forward timer();

if(!strcmp(cmdtext, "/count", true) || !strcmp(cmdtext, "/countdown", true))
{
if(counter != 0)
return SendClientMessage(playerid, COLOR_YELLOW, "Wait 5 seconds,then try again!");
countTimer = SetTimer("timer", 1000, true);
return true;
}

public timer()
{
counter++;
if(counter == 0)
GameTextForAll("3", 500, 3);
else if(counter == 1)
GameTextForAll("2", 500, 3);
else if(counter == 2)
GameTextForAll("1", 500, 3);
else if(counter == 3)
GameTextForAll("1", 500, 3);
else if(counter == 4)
{
GameTextForAll("GO!", 500, 3);
counter = 0;
KillTimer(countTimer);
}
return true;
}



If it done 2 times in maximum 2 second the countdown will repeat for ever, it stops only if I close/restart server, Need help!
Reply
#2

if(counter == 0)

Increase with 1
And do the same at the else if(counter == 1) etc lines
Reply
#3

Where exactely, correct what did I posted.
Reply
#4

pawn Код:
new counter;
new countTimer;
forward timer();

  if(!strcmp(cmdtext, "/count", true) || !strcmp(cmdtext, "/countdown", true))
{
    if(counter != 0)
    return SendClientMessage(playerid, COLOR_YELLOW, "Wait 5 seconds,then try again!");
    countTimer = SetTimer("timer", 1000, true);
    return true;
}

public timer()
{
    counter++;
    else if(counter == 1)
        GameTextForAll("3", 500, 3);
    else if(counter == 2)
        GameTextForAll("2", 500, 3);
    else if(counter == 3)
        GameTextForAll("1", 500, 3);
    else if(counter == 4)
    {
        GameTextForAll("GO!", 500, 3);
        counter = 0;
        KillTimer(countTimer);
    }
    return true;
}
Reply
#5

Nah, this one is way better... i use it in sLK clan server.

pawn Код:
forward CountDown(num);

new CountRunning =0;
pawn Код:
dcmd_cd(playerid, params[])
{
    if (!strlen(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cd [time]");
    else if(CountRunning) return SendClientMessage(playerid, COLOR_RED, "There is already a countdown running.");
    else if(!IsNumeric(params)) return SendClientMessage(playerid, COLOR_RED, "The [amount] param must be numerical");
    else if (strval(params) < 1) return SendClientMessage(playerid, COLOR_RED, "The count has to be greater than zero");
    else if (strval(params) > 10) return SendClientMessage(playerid, COLOR_RED, "The count can't be higher than 10!");
    else
    {
        CountRunning = 1;

        new ii = strval(params);

        do
        {
            SetTimerEx("CountDown", (strval(params) - ii) * 1000, false, "i", ii);

            ii --;
        }
        while (ii != -1);

        SendClientMessage(playerid, COLOR_WHITE, "***CountDown Started***");
    }
    return 1;
}

pawn Код:
public CountDown(num)
{
    new str[2];

    if (num)
    {
        format(str, sizeof(str), "%i", num);

        GameTextForAll(str, 1001, 5);
    }
    else
    {
        GameTextForAll("~g~Go", 3000, 5);

        CountRunning = 0;
    }
}
I think it was written by Donny_K
Reply
#6

Quote:
Originally Posted by lrZ^ aka LarzI
pawn Код:
public timer()
{
    counter++;
    else if(counter == 1)
        GameTextForAll("3", 500, 3);
    else if(counter == 2)
        GameTextForAll("2", 500, 3);
    else if(counter == 3)
        GameTextForAll("1", 500, 3);
    else if(counter == 4)
    {
        GameTextForAll("GO!", 500, 3);
        counter = 0;
        KillTimer(countTimer);
    }
    return true;
}
That wrong. You started with else if but it has to be else.

pawn Код:
public timer()
{
    counter++;
    if(counter == 1)
        GameTextForAll("3", 500, 3);
    else if(counter == 2)
        GameTextForAll("2", 500, 3);
    else if(counter == 3)
        GameTextForAll("1", 500, 3);
    else if(counter == 4)
    {
        GameTextForAll("GO!", 500, 3);
        counter = 0;
        KillTimer(countTimer);
    }
    return true;
}
Reply
#7

Oh, I'm abit tired, sorry:P
Reply
#8

Ive changed it but nothing, same.
If I press repeadeatly /count it doesnt stop coundwon, it repeats until i close windows server.
Reply
#9

I am very suprised no one thought about this:

pawn Код:
new Count=5;
new Countertimer;

-----
Command: /countdown:
SendClientMessage(playerid, COLOR, "You started the count down!");
Countertimer = SetTimer("Countdown", 1000, 1);
GameTextForAll("5 Seconds", 1000, 4);

-----

forward Countdown();
public Countdown()
{
Count--;
new string[128];
format(string, sizeof(string), "%d Seconds", Count);
GameTextForAll(string, 1000, 4);

if(Count == 0)
{
GameTextForAll("GO GO GO", 2000, 4);
KillTimer(CounterTimer);
Count=5;
}
Reply
#10

I'm surprised the method i posted is being ignored. I have used it for a long time its flawless.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)