SetTimerEx
From SA-MP Wiki
(Difference between revisions)
Revision as of 14:25, 10 March 2013 Smithy (Talk | contribs) ← Previous diff |
Revision as of 20:01, 4 February 2014 Connor Mead (Talk | contribs) Next diff → |
||
Line 1: | Line 1: | ||
{{Scripting}} | {{Scripting}} | ||
- | {{Title}} | ||
{{Description|Sets a timer to call a function after the specified interval. This variant ('Ex') can pass parameters (such as a player ID) to the function.}} | {{Description|Sets a timer to call a function after the specified interval. This variant ('Ex') can pass parameters (such as a player ID) to the function.}} | ||
Line 88: | Line 87: | ||
[[Category:Scripting Functions]] | [[Category:Scripting Functions]] | ||
+ | [[fr:SetTimerEx]] | ||
[[ru:SetTimerEx]] | [[ru:SetTimerEx]] |
Revision as of 20:01, 4 February 2014
Description:
Sets a timer to call a function after the specified interval. This variant ('Ex') can pass parameters (such as a player ID) to the function.
(funcname[], interval, repeating, const format[], {Float,_}:...)
funcname[] | Name of the public function to call. |
interval | Interval in milliseconds (1 second = 1000 MS). |
repeating | Boolean (true/false (or 1/0)) that states whether the timer should be called repeatedly (can only be stopped with KillTimer) or only once. |
format[] | Special format indicating the types of values the timer will pass. |
{Float,_}:... | Indefinite number of arguments to pass (must follow format specified in previous parameter). |
Return Values:
The ID of the timer that was started. Timer IDs start at 0. Timer IDs are never re-used.
Format Syntax
Placeholder | Meaning |
---|---|
i | Stands for an integer parameter. |
d | Exactly the same as i. |
a | Passes an array, the next parameter must be an integer ("i") with the array's size. [CURRENTLY UNUSABLE] |
s | Stands for a string parameter. [CURRENTLY UNUSABLE] |
f | Stands for a float parameter. |
b | Stands for a boolean parameter. |
Example:
SetTimerEx("EndAntiSpawnKill", 5000, false, "i", playerid); // EndAntiSpawnKill - The function that will be called // 5000 - 5000 MS (5 seconds). This is the interval. The timer will be called after 5 seconds. // false - Not repeating. Will only be called once. // "i" - I stands for integer (whole number). We are passing an integer (a player ID) to the function. // playerid - The value to pass. This is the integer specified in the previous parameter.
Implementation:
// The event callback (OnPlayerSpawn) - we will start a timer here public OnPlayerSpawn(playerid) { // Anti-Spawnkill (5 seconds) // Set their health very high so they can't be killed SetPlayerHealth(playerid, 999999); // Notify them SendClientMessage(playerid, -1, "You are protected against spawn-killing for 5 seconds."); // Start a 5 second timer to end the anti-spawnkill SetTimerEx("EndAntiSpawnKill", 5000, false, "i", playerid); } // Forward (make public) the function so the server can 'see' it forward EndAntiSpawnKill(playerid); // The timer function - the code to be executed when the timer is called goes here public EndAntiSpawnKill(playerid) { // 5 seconds has passed, so let's set their health back to 100 SetPlayerHealth(playerid, 100); // Let's notify them also SendClientMessage(playerid, -1, "You are no longer protected against spawn-killing."); return 1; }
Related Functions
The following functions may be useful, as they are related to this function in one way or another.
- SetTimer: Set a timer.
- KillTimer: Stop a timer.
- CallLocalFunction: Call a function in the script.
- CallRemoteFunction: Call a function in any loaded script.