Skip to main content

SetTimer

Description

Sets a 'timer' to call a function after some time. Can be set to repeat.

NameDescription
const functionName[]Name of the function to call as a string. This must be a public function (forwarded). A null string here will crash the server.
intervalInterval in milliseconds.
bool:repeatingBoolean (true/false) on whether the timer should repeat or not.

Returns

The ID of the timer that was started.

Timer IDs start at 1.

Examples

public OnGameModeInit()
{
print("Starting timer...");
SetTimer("OneSecondTimer", 1000, true); // Set a repeating timer of 1000 milliseconds (1 second)
}

forward OneSecondTimer();
public OneSecondTimer()
{
print("1 second has passed.");
}

Notes

warning

Timer intervals are not accurate (roughly 25% off) in SA-MP. There are fixes available here and here.

But it is fixed in open.mp

warning

The use of many timers will result in increased memory/cpu usage.

tip

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, meaning it has to be forwarded.

Definitions

DefinitionValue
INVALID_TIMER0