Lua functions

GetTarget

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

Historical signature: GetTarget(spawn)

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

Function: GetTarget(spawn)

Description: Gets the current target of the Spawn.

Parameters:

  • spawn (Spawn) - Spawn object representing spawn.

Returns: The selected Spawn reference, or no value (evaluates as nil) when the source or selected target is unavailable.

Selected target lifetime: The function borrows the selected actor once and transfers its custody to the active protected callback before creating Lua userdata. Reentry or collection cannot free that accepted allocation while the callback uses it. Saved userdata remains weak; a later callback cannot revive a retired actor or follow a replacement at the same address or runtime ID. See Lua actor lifetime.

Selection identity: The stored selection remembers the actor allocation chosen when the target was set. Retiring that actor and publishing another with the same runtime ID cannot redirect GetTarget before its first read. When a lookup clears an unavailable selection, it clears only the revision it observed, preserving a newer explicit selection. 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.

target = GetTarget(Spawn)

Evidence: server/ItemScripts/AutomaticBook.lua:14; binding EQ2Emu_lua_GetTarget.

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