Timer Won't Stop! [+VIDEO]
#1

Help, this timer never does stop!

I want it to go 10,9,8,7,6, etc. but it counts down 9 7 5 3 1 and does Go! infinite times...

Please help!

[ame]http://www.youtube.com/watch?v=DLGtBpJu6QU[/ame]

pawn Код:
new countdowntimer;
new count = 11;
pawn Код:
if(!strcmp(cmdtext, "/start", true, 8))
    {
        if(isclanwarstarted == 0)
        {
            new string[128];
            format(string, sizeof(string), "** Prepare yourself, a round is about to start!");
            SendClientMessageToAll(COLOR_MESSAGE, string);
            SetTimer("startcw", 5000, false);
            isclanwarstarted = 1;
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                PlayerPlaySound(i, 1139, 0.0, 0.0, 0.0);
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_ERROR, "ERROR: A round is currently running active!");
            PlayerPlaySound(playerid, 1053, 0.0, 0.0, 0.0);
        }
        return 1;
    }
pawn Код:
forward startcw(i);
public startcw()
{
    if(IsPlayerConnected(i))
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(gTeam[i] == TEAM_HOME || gTeam[i] == TEAM_AWAY)
            {
                count = 11;
                countdowntimer = SetTimer("Countdown", 1000, true);
                iDM[i] = 0;
                First[i] = 0;
                ResetPlayerWeapons(i);
                SetPlayerInterior(i, 10);
                GivePlayerWeapon(i, 31, 9999);
                GivePlayerWeapon(i, 27, 9999);
                GivePlayerWeapon(i, 24, 9999);
                SetPlayerHealth(i, 100);
                SetPlayerArmour(i, 100);
                TogglePlayerControllable(i,0);

                if(gTeam[i] == TEAM_HOME)
                {
                    SetPlayerPos(i, -1131.9910,1057.6470,1346.4126);
                    SetPlayerFacingAngle(i, 270);
                }
                else if(gTeam[i] == TEAM_AWAY)
                {
                    SetPlayerPos(i, -973.9210,1061.2968,1345.6729);
                    SetPlayerFacingAngle(i, 90);
                }
             }
         }
    }
}
forward Countdown();
public Countdown()
{
    new str[128];
    count--;
    if(count < 1)
    {
        for(new i=0; i<MAX_PLAYERS;++i)
        {
            if(IsPlayerConnected(i))
            {
                KillTimer(countdowntimer);
                GameTextForPlayer(i,"~g~~h~GO!",1000,3);
                PlayerPlaySound(i, 1057, 0, 0, 0);
                TogglePlayerControllable(i, 1);
                if(gTeam[i] == TEAM_HOME)
                {
                    SendClientMessage(i, TEAM_HOME_COLOR, "** The round has been started, good luck!");
                }
                else if(gTeam[i] == TEAM_AWAY)
                {
                    SendClientMessage(i, TEAM_AWAY_COLOR, "** The round has been started, good luck!");
                }
            }
        }
        return 1;
    }
    format(str, sizeof str, "~r~Round Begins in: ~h~~h~~h~%d", count);
    for(new i=0; i<MAX_PLAYERS;++i)
    {
        GameTextForPlayer(i,str,1000,3);
        PlayerPlaySound(i, 1056, 0, 0, 0);
    }
    return 1;
}
Reply
#2

I suggest you to use "SetTimerEx" Function , and you are just "looping",

Код:
for(new i=0; i<MAX_PLAYERS; i++)
it's useless here if it is 1 vs 1 duel, try to be more specific in your code, like loop, but on the players who are in only!! not every one
Reply
#3

It's not a 1v1 duel, it's a TDM. Like 4-5 players on one team vs 4-5 on the other!

I don't understand when you say the timer is running in a loop, I see no timer running in a loop..
Reply
#4

Quote:
Originally Posted by (_AcE_)
Посмотреть сообщение
I don't understand when you say the timer is running in a loop, I see no timer running in a loop..
He mostly meant that you start the timer inside a loop
Quote:
Originally Posted by (_AcE_)
Посмотреть сообщение
pawn Код:
//startcw
    for(new i=0; i<MAX_PLAYERS; i++) // Loop
    {
            //
            countdowntimer = SetTimer("Countdown", 1000, true); // Timer
            //
    }
Lets think what will happen
You loop through all players, for every player who is either in TEAM_HOME or in TEAM_AWAY will start a timer
So you start now X timers and override the variable countdowntimer x times

Problem
We got now x timers but only one variable which stores the last timer
Therefore the other timers are still running and cant be stopped anymore

Just put the timer outside the loop, the same if you kill the timer
Reply
#5

pawn Код:
forward countdown(amount);
public countdown(amount)
{
    new l_2[2];
    format(l_2, 2,"%i",amount);
    if(amount > 0)
    {
        GameTextForAll(l_2, 1000, 5);
        SetTimerEx("countdown",1000, false, "i", amount-1);
    }
    else GameTextForAll("Go Go Go !!!", 1000, 5);
}

//usage

countdown(99); // it gonna count til 0.
Reply
#6

And what do I do with that? You just pasted a code, I need some explanation please....
Reply
#7

Read my post.. it's telling how to use, just put like in the example i've made in your gm, it gonna make a countdown, it can't have more than 2 cells otherwise it won't work.

//countdown(howmanysecondsyouwant);
Reply
#8

Check this code I explained the changes in comments.
Reply
#9

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
Check this code I explained the changes in comments.
Nice, just that you forgot to put the KillTimer part outside the loop.
It could happen that all player leave while the countdown is running and therefore the timer could never stop
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)