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:
= LUA Functions: AddTimer() =
+
{{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
==== Syntax ====
+
|Param1Desc = is the spawn to add a timer to
AddTimer(param1, param2, param3, [param4], [param5])
+
|Param2 = int32
 
+
|Param2Desc = is the time in milli seconds to wait before calling the given function
==== Parameters ====
+
|Param3 = string
; Required - ''param1'' (Spawn), ''param2'' (int32), ''param3'' (string)
+
|Param3Desc = is the lua function to call
: ''param1'' is the spawn to add a timer to
+
|OptionalParam1 = int32
: ''param2'' is the time in milli seconds to wait before calling the given function
+
|OptionalParam1Desc = is the total number of times the timer will run, will default to 1 if not included
: ''param3'' is the lua function to call
+
|OptionalParam2 = Spawn
; Optional - ''param4'' (int32), ''param5'' (Spawn)
+
|OptionalParam2Desc = is a spawn to be sent as a second param to the given function
: ''param4'' is the total number of times the timer will run
+
|Example =
: ''param5'' is a spawn to be sent as a second param to the given function
 
 
 
 
 
==== Usage ====
 
 
<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)).
  
Will wait 1 second before talking to the player.
 
 
 
== Notes ==
 
''param4'' will default to 1 if not included.
 
 
''param5'' 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 their spawn script, not this one.
+
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.