Timer doesnt get killed
#1

Hey guys,

I got some problems with KillTimer. It doesnt kill my timer when i want it to. Its just a normal countdown, and when the variable goes down to 0, it should kill the timer, but it doesnt; it just keeps going, going and going

pawn Код:
// timer getting started:
CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, true, "i", playerid );

forward Cameraback(playerid);
public Cameraback(playerid)
{
    print( "Cameraback: call" );
    new string[20];
    format( string, sizeof string, "%i", CameraBackTicks[playerid] );
    GameTextForPlayer( playerid, string, 999, 3 );
   
    printf( "CameraBackTicks[%i]: %i", playerid, CameraBackTicks[playerid] );
   
    CameraBackTicks[playerid] --;
   
    if( CameraBackTicks[playerid] == 0 )
    {
        print( "kill timer" );
        KillTimer( CameraBack[playerid] );
        print( "succeed" );
        SetCameraBehindPlayer( playerid );
        TogglePlayerSpectating( playerid, false );
        TogglePlayerControllable( playerid, true );
        SpawnPlayer( playerid );
        CameraBackTicks[playerid] = 10;
        GameTextForPlayer( playerid, "~n~~n~~n~~n~~n~~n~~n~~n~You have been spawned!", 2000, 3 );
    }
    print( "Cameraback: end" );
    return 1;
}
Код:
[19:38:46] Cameraback: call
[19:38:46] CameraBackTicks[0]: 10
[19:38:46] Cameraback: end
[19:38:47] Cameraback: call
[19:38:47] CameraBackTicks[0]: 9
[19:38:47] Cameraback: end
[19:38:49] Cameraback: call
[19:38:49] CameraBackTicks[0]: 8
[19:38:49] Cameraback: end
[19:38:50] Cameraback: call
[19:38:50] CameraBackTicks[0]: 7
[19:38:50] Cameraback: end
[19:38:51] Cameraback: call
[19:38:51] CameraBackTicks[0]: 6
[19:38:51] Cameraback: end
[19:38:52] Cameraback: call
[19:38:52] CameraBackTicks[0]: 5
[19:38:52] Cameraback: end
[19:38:53] Cameraback: call
[19:38:53] CameraBackTicks[0]: 4
[19:38:53] Cameraback: end
[19:38:54] Cameraback: call
[19:38:54] CameraBackTicks[0]: 3
[19:38:54] Cameraback: end
[19:38:55] Cameraback: call
[19:38:55] CameraBackTicks[0]: 2
[19:38:55] Cameraback: end
[19:38:56] Cameraback: call
[19:38:56] CameraBackTicks[0]: 1
[19:38:56] kill timer
[19:38:56] succeed
[19:38:56] Cameraback: end
Anyone knows a solution?

~Wesley
Reply
#2

CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, true, "i", playerid ); - wrong .. repeating is true ( that true means the timer will be callled again, you must set it to false


CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, false, "i", playerid );

read carefully https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

I want it to repeat, untill i call KillTimer. I need the true, otherwise it wont repeat, and only will show me '10'
Reply
#4

Quote:
Originally Posted by [V]PawnFox
Посмотреть сообщение
CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, true, "i", playerid ); - wrong .. repeating is true ( that true means the timer will be callled again, you must set it to false


CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, false, "i", playerid );

also, read at wiki https://sampwiki.blast.hk/wiki/SetTimerEx
Wrong. He is trying to create a countdown. A COUNTDOWN. A COUNTDOWN.

Wesley, your log doesn't show anything wrong as far as I can see. Could you be more specific or maybe the variables used are getting modified somewhere out of the function you posted?
Reply
#5

Variables arent used anywhere else but in this timer. Its only used in OnPlayerDisconnect, just to reset it back to 10. Though that wouldnt make any difference since im not disconnecting while the countdown is going on

Edit:
Ive just made a command to kill the timer, it actually kills the timer. (stops the countdown, etc)
Reply
#6

Bumpythebump
Reply
#7

Can you post the rest of the variables? for me, it's seems ok...
Reply
#8

All the variables that i use in here are global, but only used in this callback (also printing them in here to check the values)
Reply
#9

It seems fine to me. Timer works for 10 times.
If you do not want it to do anything after KillTimer, add a return 1 after Kill Timer;
Reply
#10

i have made in a different way, it should, just call the public once, by the way, i didn't found any probably bug in the script.

pawn Код:
new CameraBackTicks[MAX_PLAYERS] = 10;
new CameraBack[MAX_PLAYERS];
forward Cameraback(playerid);
public Cameraback(playerid)
{
    print( "Cameraback: call" );
    new string[3];
    format( string, sizeof string,"%i", CameraBackTicks[playerid] );
    GameTextForPlayer( playerid, string, 999, 3 );
    printf( "CameraBackTicks[%i]: %i", playerid, CameraBackTicks[playerid] );
    CameraBackTicks[playerid] --;
    if( CameraBackTicks[playerid] == 0 )
    {
        print( "kill timer" );
        KillTimer( CameraBack[playerid] );
        print( "succeed" );
        SetCameraBehindPlayer( playerid );
        TogglePlayerSpectating( playerid, false );
        TogglePlayerControllable( playerid, true );
        SpawnPlayer( playerid );
        CameraBackTicks[playerid] = 10;
        GameTextForPlayer( playerid, "~n~~n~~n~~n~~n~~n~~n~~n~You have been spawned!", 2000, 3 );
    }
    else
    {
        CameraBack[playerid] = SetTimerEx( "Cameraback", 1000, true, "i", playerid );
    }
    print( "Cameraback: end" );
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)