NPCQuery

Group
Queries
Methods
17
Fields
None

Getting one

scene:npcs()

Methods

MethodReturnsDescription
named(string)NPCQueryKeep only those whose whole name matches, ignoring case and markup: | separates alternatives and * is any run of characters, so `"Gobli…
containing(string)NPCQueryKeep only those whose name contains the text, ignoring case and markup: | separates alternatives, so "goblin" is a Goblin and a Hobgobl…
ids({ number })NPCQueryKeep only these ids.
within(number)NPCQueryKeep only those within a radius of the local player.
withinArea(WorldArea)NPCQueryKeep only those inside an area.
withinPath(number)NPCQueryKeep only those a walk of at most steps reaches from the local player.
combatLevelAbove(number)NPCQueryKeep only those above a combat level.
combatLevelBelow(number)NPCQueryKeep only those below a combat level.
combatLevelBetween(number, number)NPCQueryKeep only those between two combat levels, both ends included.
reachable()NPCQueryKeep only those the local player can walk to.
interactable()NPCQueryKeep only those the local player can act on right now: a tile beside the NPC's footprint, on any side, can be walked to.
interactableWithin(number, boolean)NPCQueryKeep only those actable from within a range of their footprint.
exclude(NPC | { NPC })NPCQueryDrop an NPC -- the one already being fought, say -- or several. Takes the handles, not ids: an id is not unique in a scene full of the same…
hasLineOfSight()NPCQueryKeep only those with a clear line of sight to the local player.
count()numberHow many survived the narrowing. Consumes the query.
nearest()NPC?The nearest survivor. Consumes the query.
collect(){ NPC }Every survivor, nearest first. Consumes the query.

Returned by

MethodReturnsDescription
SceneDomain.npcsNPCQueryA query over every NPC in the scene, whose terminals hand out NPC handles.

Method details

named

named: (NPCQuery, string) -> NPCQuery

Keep only those whose whole name matches, ignoring case and markup: | separates alternatives and * is any run of characters, so "Goblin" is not a Hobgoblin and "Guard|*goblin" is a guard, a goblin and a Hobgoblin. Alternative to walking the NPCs with an if on each getName() to find the ones of a name each tick: the host narrows the scene by name, one crossing for the set.

names
The name pattern.

containing

containing: (NPCQuery, string) -> NPCQuery

Keep only those whose name contains the text, ignoring case and markup: | separates alternatives, so "goblin" is a Goblin and a Hobgoblin.

text
The text to look for.

within

within: (NPCQuery, number) -> NPCQuery

Keep only those within a radius of the local player.

radius
Chebyshev distance in tiles.

withinPath

withinPath: (NPCQuery, number) -> NPCQuery

Keep only those a walk of at most steps reaches from the local player.

steps
The longest path to allow.

combatLevelBetween

combatLevelBetween: (NPCQuery, number, number) -> NPCQuery

Keep only those between two combat levels, both ends included.

low
The lowest level to keep.
high
The highest level to keep.

interactable

interactable: (NPCQuery) -> NPCQuery

Keep only those the local player can act on right now: a tile beside the NPC's footprint, on any side, can be walked to.

Example
-- The nearest goblin the player can act on now: a tile beside it, on any
-- side, can be walked to. Not one behind a fence.
local goblin = scene:npcs():named("Goblin"):interactable():nearest()
if goblin then
    goblin:interact("Attack")
end

interactableWithin

interactableWithin: (NPCQuery, number, boolean) -> NPCQuery

Keep only those actable from within a range of their footprint.

range
How far away to allow, in tiles.
requireLineOfSight
Whether the line of sight must be clear.

exclude

exclude: (NPCQuery, NPC | { NPC }) -> NPCQuery

Drop an NPC -- the one already being fought, say -- or several. Takes the handles, not ids: an id is not unique in a scene full of the same monster.

npcs
The NPC or NPCs to leave out.

count

count: (NPCQuery) -> number

How many survived the narrowing. Consumes the query.

nearest

nearest: (NPCQuery) -> NPC?

The nearest survivor. Consumes the query.

Returns
nil when none survived.