SetTimer
From SA-MP Wiki
(Difference between revisions)
Revision as of 09:22, 17 February 2019 OstGot (Talk | contribs) ← Previous diff |
Revision as of 10:18, 25 February 2019 RoboN1X (Talk | contribs) (There is never need of url shortener) Next diff → |
||
Line 10: | Line 10: | ||
{{Returns|The ID of the timer that was started. Timer IDs start at 1.}} | {{Returns|The ID of the timer that was started. Timer IDs start at 1.}} | ||
- | {{Notes| | + | {{Notes|1= |
- | * Timer intervals are not accurate (roughly 25% off). There are fixes available [http://goo.gl/gPJJU5 here] and [https://bit.ly/2trV0t4 here]. | + | * Timer intervals are not accurate (roughly 25% off). There are fixes available [https://forum.sa-mp.com/showthread.php?t=289675 here] and [https://forum.sa-mp.com/showthread.php?t=650736 here]. |
* Timer IDs are never used twice. You can use KillTimer() on a timer ID and it won't matter if it's running or not. | * Timer IDs are never used twice. You can use KillTimer() on a timer ID and it won't matter if it's running or not. | ||
* The function that should be called, must be [[Public functions|public]], meaning it has to be [[Public functions#Forwarding|forwarded]]. | * The function that should be called, must be [[Public functions|public]], meaning it has to be [[Public functions#Forwarding|forwarded]]. |
Revision as of 10:18, 25 February 2019
Description:
Sets a 'timer' to call a function after some time. Can be set to repeat.
(funcname[], interval, repeating)
funcname[] | Name of the function to call as a string. This must be a public function (forwarded). A null string here will crash the server. |
interval | Interval in milliseconds. |
repeating | Boolean (true/false) on whether the timer should repeat or not. |
Return Values:
The ID of the timer that was started. Timer IDs start at 1.
Notes | * Timer intervals are not accurate (roughly 25% off). There are fixes available here and here. |
Example Usage:
forward message(); public OnGameModeInit() { print("Starting timer..."); SetTimer("message", 1000, false); // Set a timer of 1000 miliseconds (1 second) } public message() { print("1 second has passed."); }
Related Functions
The following functions may be useful, as they are related to this function in one way or another.
- SetTimerEx: Set a timer with parameters.
- KillTimer: Stop a timer.