Skip to content

SpawnCount

How many actors are currently loaded in your zone.

Forms

number SpawnCount

Returns the number of currently-loaded actors.

Usage

eq2.print("spawns nearby: " .. mq.TLO.SpawnCount())

Not an index range

SpawnCount() counts actors; it is not an id range and not an index into anything. There is no Spawn[1]-style ordinal access — Spawn[n] treats a number as a spawn id. To iterate, use Spawns():

-- wrong: 1..N are spawn ids, almost none of which exist
for i = 1, mq.TLO.SpawnCount() do
  local s = mq.TLO.Spawn[i]
end

-- right
for _, s in ipairs(mq.TLO.Spawns()) do
  ...
end

Its real use is as a cheap "has the zone finished streaming in" check, since it avoids building the full table:

while mq.TLO.SpawnCount() == 0 do eq2.delay(250) end

See also