Difference between revisions of "LUA:AddTimer"
(Created page with "= LUA Functions: AddTimer() = Adds a timer to the given spawn that will call the given function when the time runs out. ==== Syntax ==== AddTimer(param1, param2, param3, [param...") |
|||
| Line 1: | Line 1: | ||
| − | = | + | {{LUAFunction |
| − | Adds a timer to the given spawn that will call the given function when the time runs out. | + | |Name = AddTimer |
| − | + | |Description = Adds a timer to the given spawn that will call the given function when the time runs out. | |
| − | + | |Param1 = Spawn | |
| − | + | |Param1Desc = is the spawn to add a timer to | |
| − | + | |Param2 = int32 | |
| − | + | |Param2Desc = is the time in milli seconds to wait before calling the given function | |
| − | + | |Param3 = string | |
| − | + | |Param3Desc = is the lua function to call | |
| − | + | |OptionalParam1 = int32 | |
| − | + | |OptionalParam1Desc = is the total number of times the timer will run, will default to 1 if not included | |
| − | + | |OptionalParam2 = Spawn | |
| − | + | |OptionalParam2Desc = is a spawn to be sent as a second param to the given function | |
| − | + | |Example = | |
| − | |||
| − | |||
| − | |||
| − | |||
<pre> | <pre> | ||
function hailed(NPC, Spawn) | function hailed(NPC, Spawn) | ||
| Line 26: | Line 22: | ||
end | end | ||
</pre> | </pre> | ||
| + | |ExampleDesc = Will wait 1 second before talking to the player. | ||
| + | |Notes = opt param2 is an optional spawn to be sent as the second param to the function given by param3, usually a player but doesn't have to be. If not set the function in the above example would only have 1 param (function delayed_speak(NPC)). | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | If the spawn receiving the timer is not the same spawn using this script the function must be in | + | If the spawn receiving the timer is not the same spawn using this script, the function must be in the other spawns script, not the original spawn. |
| + | }} | ||
Latest revision as of 12:08, 30 January 2021
LUA:AllFunctions - AddTimer
Return to: LUA:AllFunctions | Tutorials | Portal | Forum | Project Manager | Bug Tracker
Adds a timer to the given spawn that will call the given function when the time runs out.
Syntax
AddTimer(param1, param2, param3, [opt param1], [opt param2])
Parameters
- Required - param1 (Spawn), param2 (int32), param3 (string)
- param1 is the spawn to add a timer to
- param2 is the time in milli seconds to wait before calling the given function
- param3 is the lua function to call
- Optional - opt param1 (int32), opt param2 (Spawn)
- opt param1 is the total number of times the timer will run, will default to 1 if not included
- opt param2 is a spawn to be sent as a second param to the given function
Example
function hailed(NPC, Spawn)
AddTimer(NPC, 1000, "delayed_speak", 1, Spawn)
end
function delayed_speak(NPC, Spawn)
Say(NPC, "Hello " .. GetName(Spawn) .. ".")
end
Will wait 1 second before talking to the player.
Notes
opt param2 is an optional spawn to be sent as the second param to the function given by param3, usually a player but doesn't have to be. If not set the function in the above example would only have 1 param (function delayed_speak(NPC)).
If the spawn receiving the timer is not the same spawn using this script, the function must be in the other spawns script, not the original spawn.