No categories assigned

LUA:AddTimer

Revision as of 12:08, 30 January 2021 by Cynnar (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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.