SA-MP Forums Archive
How To KillTimer - 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: How To KillTimer (/showthread.php?tid=454869)



How To KillTimer - RandomDude - 30.07.2013

pawn Код:
SetTimer("HideTextDraw",8500,1);
What does the 1 stand for after the ,
and also how do I kill that timer...


Re: How To KillTimer - Richie© - 30.07.2013

The 1 at the end tells you if the timer is repeated or not.
All your answers is available on the wiki..
https://sampwiki.blast.hk/wiki/KillTimer


Re: How To KillTimer - CrazyChoco - 30.07.2013

1st question: It stands for repeating.
2nd question: Example made in SAMP Wiki
pawn Код:
new connect_timer[MAX_PLAYERS];
 
public OnPlayerConnect(playerid)
{
    print("Starting timer...");
    connect_timer[playerid] = SetTimerEx("WelcomeTimer", 5000, true, "i", playerid);
    return 1;
}
 
public OnPlayerDisconnect(playerid)
{
    KillTimer(connect_timer[playerid]);
    return 1;
}
 
forward WelcomeTimer(playerid);
public WelcomeTimer(playerid)
{
    SendClientMessage(playerid, -1, "Welcome!");
}
Source: https://sampwiki.blast.hk/wiki/SetTimer
Source: https://sampwiki.blast.hk/wiki/KillTimer


Re: How To KillTimer - Facerafter - 30.07.2013

You can kill it with
pawn Код:
KillTimer(timerid)
And the 1 means its repeating.
Quote:

SetTimer(funcname[], interval, repeating)
funcname[] Name of the function to call as a string. Needs to be a public!
interval Interval in milliseconds.
repeating Boolean if the timer should occur repeatedly or only once




Re: How To KillTimer - MP2 - 30.07.2013

To kill a timer you have to pass it's ID to KillTimer(). This ID is returned by SetTimer(Ex), so you need to store it in a variable (or an array).

pawn Код:
new TIMER_HideTextDraw;

SomeFunction()
{
    TIMER_HideTextDraw = SetTimer("HideTextDraw",8500,1);
}

// To kill it:
KillTimer(TIMER_HideTextDraw);
Something worth noting is that timer IDs are one-time only. Timers will never re-use IDs, like how objects/vehicles/textdraws etc. do.

EDIT: CrazyChoco has a better example using an array.


Re: How To KillTimer - RandomDude - 30.07.2013

Quote:
Originally Posted by MP2
Посмотреть сообщение
To kill a timer you have to pass it's ID to KillTimer(). This ID is returned by SetTimer(Ex), so you need to store it in a variable (or an array).

pawn Код:
new TIMER_HideTextDraw;

SomeFunction()
{
    TIMER_HideTextDraw = SetTimer("HideTextDraw",8500,1);
}

// To kill it:
KillTimer(TIMER_HideTextDraw);
Something worth noting is that timer IDs are one-time only. Timers will never re-use IDs, like how objects/vehicles/textdraws etc. do.

EDIT: CrazyChoco has a better example using an array.
Thank You