Spawn¶
Look up any actor in the world by spawn id or by name.
Forms¶
actor Spawn[id]¶
- Returns the
actorwith that numeric spawn id.
actor Spawn[name]¶
- Returns the
actorwhose name matchesname— case-insensitive, exact match, not a partial. Returnsnilif no loaded actor has that name.
Usage¶
local byId = mq.TLO.Spawn[12345]
local byName = mq.TLO.Spawn["a decaying skeleton"]
if byName then
eq2.print(byName.Name() .. " @ " .. byName.Distance())
end
The two forms behave differently on failure¶
This trips people up, so it's worth stating plainly:
| Form | No match |
|---|---|
Spawn[name] |
Returns nil. |
Spawn[id] |
Returns an actor table whose ID() is 0, not nil. |
The name lookup walks the loaded-actor list and can tell you it found nothing. The id lookup builds a reference to that id and resolves lazily on each member call, so it has nothing to report at index time.
The check that covers both:
local s = mq.TLO.Spawn[key]
if s and s.ID() ~= 0 then
...
end
Name matching is exact¶
Spawn["skeleton"] will not find "a decaying skeleton". For partial or
pattern matching, filter Spawns() yourself:
local function find(pattern)
for _, s in ipairs(mq.TLO.Spawns()) do
if s.Name():lower():find(pattern:lower(), 1, true) then return s end
end
end
local mob = find("skeleton")
Names are also not unique — several actors can share one. The name form returns
the first match in enumeration order, which is not a stable ordering. When you
need a specific actor across time, capture its ID() and use the id form.
References stay live¶
An actor obtained from Spawn[id] is a reference, not a snapshot. Its
members re-resolve on every call, so it keeps tracking that actor as it moves,
takes damage, and eventually despawns — at which point ID() starts returning
0. You can hold one across an eq2.delay() safely, as long as you re-check
ID().
See also¶
actor— the full member list.Spawns()— every loaded actor.SpawnCount()