Timers are used to call a custom callback after the inputted amount of milliseconds.
For example:
pawn Код:
main()
{
print("Incoming message in 5 seconds!");
SetTimer("OurFunction", 5000, false);
}
forward OurFunction();
public OurFunction()
{
print("I told you!");
return 1;
}
After "OurFunction", you might notice the 5000. Those are milliseconds.
One second is equivalent to 1000 milliseconds.
Twenty-two seconds is equivalent to 22000 milliseconds.
Basically, it's seconds x 1000.
Function: SetTimer(funcname[], ms, bool:repeat);
funcname[] - Name of the function (must be a public defined in the script)
ms - Milliseconds funcname will be called in (example: 2000 for 2 seconds)
bool:repeat - Can be boolean (false/true) or integer (0/1). If set to true or 1, the timer will repeat every time for the amount of ms entered.
However, if you wish to create a timer that will repeat 5 times then stop, try this:
pawn Код:
new spamtimer;
new times;
main()
{
print("Incoming spam!");
spamtimer = SetTimer("Spam", 1000, true);
}
forward Spam();
public Spam()
{
times++;
if(times >= 5) return KillTimer(spamtimer);
return print("SPAM");
}
There is a function too, called SetTimerEx, that will call a function & it's parameters after the amount of ms entered (similar to SetTimer).
More can be read here:
SetTimer
SetTimerEx