Lua functions

AddTimer

Registered in this checkout as EQ2Emu_lua_AddTimer; implementation found at WorldServer/Lua/LuaFunctions.cpp:4195.

Historical signature: AddTimer(spawn, time, function, max_count, player)

Parameter and behavior details in the historical explanation are under review against the current implementation.

Function: AddTimer(spawn, time, function, max_count, player)

Description:

Schedules a named spawn script callback after an initial delay. The timer remembers the original spawn and optional actor allocation without keeping either alive for the delay. A retired spawn or a different allocation using its runtime ID cannot receive the callback. If the optional actor is no longer available in the timer's zone, the callback receives nil for that argument.

Parameters:

  • spawn (Spawn) - The original spawn that owns the timer.
  • time (uint32) - Initial delay in milliseconds. Zero is rejected; values below 10 are raised to 10.
  • function (string) - Nonempty callback name.
  • max_count (uint32, optional) - Number of callback attempts; omission or zero means one. Repeated callbacks run on subsequent timer checks after the initial delay; the delay is not restarted between attempts.
  • player (Spawn, optional) - Original optional actor. NPC spawn scripts receive (spawn, player); Player scripts receive (zone, spawn, player). Omission supplies nil for the optional actor.

Returns: None.

Dispatch and cancellation:

Callbacks run outside the timer registry lock with owned actor loans. A callback can add or stop timers. New timers wait for the next traversal. StopTimer also cancels queued callbacks that have not entered, including ones captured by the current traversal; it cannot interrupt a callback already entered. Native argument preparation failure before admission leaves the timer available for a later check. An entered callback attempt is not automatically replayed after a partial error. For Player timers, the global and zone Player scripts use the same admitted actors. See Lua actor lifetime.

Checked example

Active call in a local runtime Lua script. Argument count matches current fixed C++ readers. This is a contextual call pattern, not a tested standalone script.

AddTimer(NPC, 90000, "Camp1Reset",1,Spawn)

Evidence: server/SpawnScripts/antonica/afociofdecayA.lua:131; binding EQ2Emu_lua_AddTimer.

Current registration: WorldServer/Lua/LuaInterface.cpp. Historical explanation: EQ2Emu Lua documentation.