NPCs - GregHib/void GitHub Wiki

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
max_hit_melee = 10
style = "crush"
respawn_delay = 45
drop_table = "cow"
combat_anims = "cow"
combat_sounds = "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 list which can be accessed by any scripts class constructor:

class MyContent(
    val npcs: NPCs
) : Script {

Or with:

val npcs: NPCs by inject()

Or in functions with:

val npcs: NPCs = get()

And the also can be searched for by id, index, Tile or Zone:

val npc = npcs.get(42) // Get npc at an index

val npc = npcs.get("chicken") // Get a specific npc by id

val npcsUnder = npcs[Tile(3200, 3200)] // Get all npcs under a tile

val npcsNearby = npcs[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

Data Description
Id The type of npc as a String identifier.
Index The number between 1-32768 a particular npc is in the current game world.
Tile The current position of the npc represented as an x, y, level coordinate.
Levels Fixed levels used in Combat calculations.
Mode The npcs current style of movement.
Definition Definition data about this particular type of npc.
ActionQueue List of Queues currently in progress for the npc.
Soft Timer The one Timer that is currently counting down for the npc.
Variables Progress and tracking data for different types of content.
Steps List of tiles the player plans on walking to in the future.
Collision Strategy for how the npc can move about the game world.
Visuals The npcs general appearance.