SA-MP Forums Archive
/countdown bug - 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: /countdown bug (/showthread.php?tid=111098)



/countdown bug - shoru93 - 29.11.2009

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!



Re: /countdown bug - LarzI - 29.11.2009

if(counter == 0)

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


Re: /countdown bug - shoru93 - 29.11.2009

Where exactely, correct what did I posted.


Re: /countdown bug - LarzI - 29.11.2009

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



Re: /countdown bug - Outbreak - 29.11.2009

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


Re: /countdown bug - diesulke - 29.11.2009

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



Re: /countdown bug - LarzI - 29.11.2009

Oh, I'm abit tired, sorry:P


Re: /countdown bug - shoru93 - 29.11.2009

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


Re: /countdown bug - lolumadd - 29.11.2009

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



Re: /countdown bug - Outbreak - 29.11.2009

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