Timers module
Ovo je kratak pogled na jedan od poboljšanih modula koje smo uradili, za tajmere u open.mp:
native SetTimer(const func[], msInterval, bool:repeat) = SetTimerEx;
native SetTimerEx(const func[], msInterval, bool:repeat, const params[], GLOBAL_TAG_TYPES:...);
native KillTimer(timer) = Timer_Kill;
// CreateTimer
native Timer:Timer_Create(const func[], usDelay, usInterval, repeatCount, const params[] = "", GLOBAL_TAG_TYPES:...);
// KillTimer
native bool:Timer_Kill(Timer:timer);
// Return time till next call.
native Timer_GetTimeRemaining(Timer:timer);
// Get number of calls left to make (0 for unlimited).
native Timer_GetCallsRemaining(Timer:timer);
// Get `repeatCount` parameter.
native Timer_GetTotalCalls(Timer:timer);
// Get `usInterval` parameter.
native Timer_GetInterval(Timer:timer);
// Reset time remaining till next call to `usInterval`.
native bool:Timer_Restart(Timer:timer);
Prva dva služe samo za kompatibilnost unatrag, a ostala su poboljšani API:
native Timer:Timer_Create(const func[], usDelay, usInterval, repeatCount, const params[] = "", GLOBAL_TAG_TYPES:...);
func
- Fairly obvious; what to call.usDelay
- Again obvious, the delay before the call (in microseconds).usInterval
- What to resetusDelay
to after the first call. So if you wanted a timer on the hour every hour, but it was 8:47am right now, the call would beTimer_Create("OnTheHour", 780 SECONDS, 3600 SECONDS, 0);
repeatCount
- Unlike the old functions, which are just "once" or "forever", this instead takes the number of times to call the function. "once" would be1
,500
would stop after 500 calls, and (backwards from the old API)0
means "forever".GLOBAL_TAG_TYPES
- Like{Float, ...}
, but with more tags.