Skip to content

Spawns

Every actor currently loaded in your zone.

Forms

array Spawns

Returns an array of actor for every currently-loaded actor. Capped at 4096.

Usage

for _, s in ipairs(mq.TLO.Spawns()) do
  eq2.print(("%s @ %.1fm"):format(s.Name(), s.Distance()))
end

This is the spawn-search substitute

EverQuest II has no extended-target window, and clockwork has no MacroQuest-style spawn-search syntax (${NearestSpawn[2,npc radius 50]}). Spawns() plus a Lua filter is how you build any "what's around me" list.

Nearest hostile:

local function nearest_hostile(max)
  local best, bestd = nil, max or math.huge
  for _, s in ipairs(mq.TLO.Spawns()) do
    local d = s.Distance()
    if d > 0 and d < bestd and s.Attackable() and not s.IsPlayer() then
      best, bestd = s, d
    end
  end
  return best, bestd
end

Note the d > 0 guard — Distance() returns 0.0 on a failed read, so without it every unresolvable actor sorts to the front as "closest".

Everything already fighting:

local combat = {}
for _, s in ipairs(mq.TLO.Spawns()) do
  if s.Attackable() and s.HasAggro() then combat[#combat + 1] = s end
end

...bearing in mind HasAggro() is an attacker-cache read that can false-negative.

Cost

Every call re-enumerates and builds a fresh Lua table per actor. In a busy zone that is thousands of table allocations. Call it once per pass, not once per member you want to test:

-- good
local all = mq.TLO.Spawns()
for _, s in ipairs(all) do ... end

-- bad: re-enumerates on every iteration
for i = 1, mq.TLO.SpawnCount() do ... mq.TLO.Spawns()[i] ... end

And keep eq2.delay() in the loop around it — a full sweep plus per-actor work is exactly the kind of pass that can trip the 500 ms watchdog.

See also