How To KillTimer
#1

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

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
Reply
#3

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
Reply
#4

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

Reply
#5

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)