SA-MP Forums Archive
Timer won't stop - 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)
+--- Thread: Timer won't stop (/showthread.php?tid=628996)



Timer won't stop - PeanutButter - 18.02.2017

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
    
}




Re: Timer won't stop - Misiur - 18.02.2017

Do you see your "start" gametext message?


Re: Timer won't stop - PeanutButter - 18.02.2017

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


Re: Timer won't stop - Shaheen - 18.02.2017

post the codes of stop CountDownID[playerid];

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


Re: Timer won't stop - PeanutButter - 18.02.2017

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.


Re: Timer won't stop - X337 - 18.02.2017

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)



Re: Timer won't stop - Macronix - 18.02.2017

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;




Re: Timer won't stop - AmigaBlizzard - 18.02.2017

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.


Re: Timer won't stop - PeanutButter - 18.02.2017

Thanks for the help