Lua functions

GetSpawn

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

Historical signature: GetSpawn(spawn, spawn_id)

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

Function: GetSpawn(spawn, spawn_id)

Description: Finds the nearest other active spawn with the requested database spawn definition ID in the context spawn's current zone. This ID is different from the runtime allocation ID returned by GetID. Equal distances are resolved by the lower runtime ID. The context spawn itself is excluded.

Parameters:

  • spawn (Spawn): context actor defining the zone and distance origin.
  • spawn_id (uint32): positive database spawn definition ID.

Returns: Spawn userdata for the selected actor, or no value (nil) when the context or zone is invalid, the ID is zero, or no eligible candidate is found within the engine's search bound.

Lifetime behavior: Candidate lookup acquires an actor borrow under the zone publication lock before reading distance or identity. The selected borrow is retained through the current Lua invocation. Keeping the returned userdata in a global, closure, or suspended coroutine records a weak allocation reference; it does not permanently retain the actor. Later invocations cannot resolve a retired allocation or inherit a replacement at the same address. Gameplay status still follows the engine's death and retirement rules.

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.

whelp = GetSpawn(NPC, id)

Evidence: server/SpawnScripts/Butcherblock/qsttalvraesbowl.lua:27; binding EQ2Emu_lua_GetSpawn.

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