No categories assigned

LUA:AddTimer

Revision as of 20:41, 15 October 2012 by Jabantiz (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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, [param4], [param5])

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 - param4 (int32), param5 (Spawn)
param4 is the total number of times the timer will run
param5 is a spawn to be sent as a second param to the given function


Usage

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

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.