VoidVOID
DocsNPCs

NPCs

Non-Player-Characters exist in the game for Players to interact with, talk to for quests, information or shops, and fight in combat although these are typically referred to as Monsters.

While NPCs have a lot of similarities with Players as both are Characters, NPCs have a lot data due to not being connected to a Client and thus having no concept of Interfaces or Inventories.

Configuration

NPCs have two types of config files which store information which doesn't exist in the cache.

  • .npc.toml files store additional information such as combat stats, animations and examines.
  • .npc-spawns.toml files store spawn information
[cow_default]
id = 81
hitpoints = 80
attack_bonus = -15
wander_radius = 12
immune_poison = true
slayer_xp = 8.0
combat_def = "cow"
respawn_delay = 45
drop_table = "cow"
categories = ["cows"]
height = 30
examine = "Converts grass to beef."

This information can be obtained using npc.def["examine", ""] see definition extras for more info.

Spawns

Permanent and respawning npcs are configured in /data/*.npc-spawn.toml files organised by location.

spawns = [
  { id = "cow_default", x = 2936, y = 3274 },
  { id = "cow_brown", x = 2921, y = 3287 },
  { id = "cow_brown", x = 2933, y = 3274 },
  { id = "cow_light_spots", x = 2924, y = 3288 },
]

One-off npc spawns (like for quests or bosses) can be added using NPCs:

val cow = NPCs.add("cow_brown", Tile(3200, 3200), Direction.NORTH)

Finding NPCs

Much like Players NPCs can be found using the world NPCs and can be searched for by id, index, Tile or Zone:

val npc = NPCs.indexed(42) // Get npc at an index
val npc = NPCs.find(tile, "chicken") // Get a specific npc by id
val npcsUnder = NPCs.at(Tile(3200, 3200)) // Get all npcs under a tile
val npcsNearby = NPCs.at(Zone(402, 403)) // Get all npcs in 8x8 area

Adding NPCs

Scripts can subscribe to npc spawns with:

npcSpawn("cow*") {
    softTimers.start("eat_grass")
}

Removing NPCs

NPCs can be removed easily with:

npcs.remove(cow)

And Scripts can subscribe to despawns using:

npcDespawn {
    softTimers.stopAll()
}

NPC options

NPC interactions can be subscribed to as well:

npcApproach("Talk-to", "banker*") { }
npcOperate("Talk-to", "zeke") { }

Tip

See interactions for more info including the difference between operate and approach interactions.

NPC data

DataDescription
IdThe type of npc as a String identifier.
IndexThe number between 1-32768 a particular npc is in the current game world.
TileThe current position of the npc represented as an x, y, level coordinate.
LevelsFixed levels used in Combat calculations.
ModeThe npcs current style of movement.
DefinitionDefinition data about this particular type of npc.
ActionQueueList of Queues currently in progress for the npc.
Soft TimerThe one Timer that is currently counting down for the npc.
VariablesProgress and tracking data for different types of content.
StepsList of tiles the player plans on walking to in the future.
CollisionStrategy for how the npc can move about the game world.
VisualsThe npcs general appearance.