Timer won't stop
#1

I am making a countdown, but I cant stop the timer. I tried it with normal timers and y_timers.

PHP код:
new Timer:CountDownID[MAX_PLAYERS];
new 
counter[MAX_PLAYERS]; 
PHP код:
StartCounter()
{
    foreach(
Playersi)
    {
        
counter[i] = 4;
        
CountDownID[i] = repeat CountDown(i);
    }

PHP код:
timer CountDown[1000](playerid)
{
    
SendClientMessage(playerid, -1"timer tick"); // This just keeps going
    
if(counter[playerid] != 0)
    {
        
// counting down
    
}
    else
    {
        
GameTextForPlayer(playerid"~g~START!"10004);
        
stop CountDownID[playerid]; // this wont stop the timer
    
}

Reply
#2

Do you see your "start" gametext message?
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Do you see your "start" gametext message?
Yes and it keeps saying it every second
Reply
#4

post the codes of stop CountDownID[playerid];

and also
see this : CountDownID[i] = repeat CountDown(i);
Reply
#5

Quote:
Originally Posted by Shaheen
Посмотреть сообщение
post the codes of stop CountDownID[playerid];

and also
see this : CountDownID[i] = repeat CountDown(i);
I don't get it. I already showed everything.
Reply
#6

CountDownID[playerid] might be overwritten while it's running. Why don't you use one global timer and use GameTextForAll to show the gametext instead of per-player timer?
And also, can you post codes under this statement?
Код:
    if(counter[playerid] != 0)
Reply
#7

So you want a countdown which shows for every player?

PHP код:
new counter 5;

forward CountDown();
public 
CountDown()
{
    if(
counter 0)
    {
        new 
str[1];
        
format(strsizeof(str), "%d"counter);
        
GameTextForAll(str20006);
        
        
counter--;
        
        
SetTimer("CountDown"1000false);
    }
    else
    {
        
GameTextForAll("Go!"20006);
        
counter 5;
    }
    return 
1;

Reply
#8

Slightly modified code posted by Macronix:
PHP код:
new counter = -1;
// OnGameModeInit
SetTimer("CountDown"1000true);
forward CountDown();
public 
CountDown()
{
    if(
counter 0)
    {
        new 
str[1];
        
format(strsizeof(str), "%d"counter);
        
GameTextForAll(str20006);
        
counter--;
        return 
1;
    }
    if (
counter== 0)
    {
        
GameTextForAll("Go!"20006);
        
counter = -1;
        return 
1;
    }
    return 
1;

This way, the timer will run forever and it won't do anything for now because the counter is set to -1.

If you need the timer to countdown, just set the "counter" variable to the value you require.
The timer will automatically see the new value and will start to count down.
When it reaches 0, it will send "Go" to all players and it will set the counter back to -1 to prevent it from spamming you with the "Go" signal.

This way, you never need to kill timers and you never have to start one either (except starting it under OnGameModeInit).
Just set the counter variable and it works automatically.
Reply
#9

Thanks for the help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)