Map NPCs¶
The NPCs of the loaded map: where each one spawns, what it’s called, what it can be clicked for, and what it looks like.
The game cache doesn’t say where NPCs spawn, the server places them, so the spawns come from the
files/npcspawns.txt asset. Everything else is read out of the game cache, so it’s always in step
with the game, and the NPCs of a region are only read once that region is part of the map.
Example:
{$I WaspLib/main.simba}
var
bankers: TEntityArray;
begin
Map.Setup([EChunk.VARROCK]);
bankers := TEntityArray.Create(Map.Walker, MapNPCs.GetByAction('Bank'));
end.
TMapNPCData¶
One kind of NPC and every place it spawns on the loaded map.
IDis the id it spawns as.Name,Level,Category,ActionsandMinimapDotcome from the definition it’s shown as, which for an NPC that changes form is the first form with a name.Actionsare the ones its right-click menu shows, in menu order, andMinimapDotsays whether it has a dot on the minimap.Coordinatesare where it spawns, as Global Points.Sizeis how many tiles it covers on each side andHeighthow tall it is, in the game’s units: a tile is128.Colorsare the colours it is drawn in, most common first.
Height and Colors come from the NPC’s models, which are only built when the NPC is asked for -
see MapNPCs.Build.
TMapNPCs¶
Record holding the TMapNPCData of every NPC on the loaded map.
Definitionsare the definitions ofData, in the same order, for building their models.Lookupturns an NPC id into its place inData, stored one higher so0means none.Loadedholds the chunks already read, asx, ywith the plane packed in with them.SpawnIDs,SpawnTilesandSpawnPlanesare every line of the spawns file, andSpawnChunksthe chunks they’re in, packed likeLoaded.SpawnStartsis where the run of lines of each ofSpawnChunksstarts, with one extra entry closing the last run.
MapNPCs.LoadSpawns¶
procedure TMapNPCs.LoadSpawns();
Internal method that reads the spawns file into the Spawn fields, once.
The file holds one id plane x y line per spawn, sorted so the spawns of each chunk are one run
of lines, which is what lets a chunk’s spawns be found without searching them all.
MapNPCs.Add¶
procedure TMapNPCs.Add(id, plane: Integer; tile: TPoint);
Internal method that records one spawn of NPC id on tile, adding the NPC if it’s the first
one. NPCs without a name, or that can’t be interacted with, are left out.
MapNPCs.Load¶
procedure TMapNPCs.Load(var loader: TMapLoader);
procedure TMapNPCs.Load(); overload;
Reads the NPCs of every chunk loader has loaded that hasn’t been read yet. Without a loader it
reads Map’s. The getters below call this, so it rarely needs calling directly.
MapNPCs.Build¶
procedure TMapNPCs.Build(idx: Integer);
Internal method that builds the models of Data[idx] with TNPCModel to fill in its
Height and Colors.
Only the colours that cover most of the NPC make it into Colors: the most common ones, until
COVERAGE of its faces are accounted for. The rest are slivers and rarely lit corners that would
only widen what a colour finder looks for.
MapNPCs.GetByName¶
function TMapNPCs.GetByName(name: String; amount: Integer = 0): TMapNPCDataArray;
Every NPC called name. Pass amount to stop after that many NPCs.
Example:
WriteLn MapNPCs.GetByName('Banker');
MapNPCs.GetByID¶
function TMapNPCs.GetByID(id: Integer): TMapNPCData;
The NPC with the id id. It has no Coordinates if there is no such NPC on the map.
MapNPCs.GetByAction¶
function TMapNPCs.GetByAction(action: String; amount: Integer = 0): TMapNPCDataArray;
Every NPC with action in its right-click menu. Pass amount to stop after that many NPCs.
Example:
WriteLn MapNPCs.GetByAction('Bank');
MapNPCs.GetByAllActions¶
function TMapNPCs.GetByAllActions(actions: TStringArray; amount: Integer = 0): TMapNPCDataArray;
Every NPC with all of actions in its right-click menu. Pass amount to stop after that many
NPCs.
MapNPCs.Clear¶
procedure TMapNPCs.Clear();
Forgets every NPC read so far, so the next getter reads the map again from scratch.