The API
This is API version 6, shipped in RunicNPC v1.0.0. RunicNPC works without Runic Gateway, and so does everything on this page.
Calling it
Section titled “Calling it”RunicNPC is called by name through Call, like any Oxide or Carbon plugin API. Every call is
prefixed RunicNpc_, so no hook of another plugin is ever matched by accident.
[PluginReference] private Plugin RunicNPC;
int api = RunicNPC?.Call<int>("RunicNpc_ApiVersion") ?? 0;if (api < 6) { /* too old for this caller: say so */ }
BasePlayer npc = RunicNPC.Call("RunicNpc_Spawn", position, "warden", "plugin:MyPlugin", null) as BasePlayer;The API version moves when a call or a raised hook changes shape, not on every release. The release’s manifest carries it too, so an installer can refuse a RunicNPC too old for its caller before it is loaded. Check it before relying on a call.
A call that cannot do what it was asked returns null, 0 or false, and says why in the server log. Calls that change data return the reason as a string instead, and null means success.
Owners
Section titled “Owners”Every NPC has an owner, and the owner decides how long it lives.
| Owner | Who uses it | Lifetime |
|---|---|---|
run:<id> | An event run, through the bridge | Never saved. Removed by its caller, or by RunicNpc_DespawnOwner |
plugin:<name> | Any other plugin — use your own plugin’s name | Never saved. Removed when that plugin unloads |
placement:<id> | RunicNPC itself, for a placement. A caller cannot spawn with this owner | The NPC is never saved; the placement is, and spawns a fresh one at boot |
Spawning and removing
Section titled “Spawning and removing”RunicNpc_ApiVersion
Section titled “RunicNpc_ApiVersion”int RunicNpc_ApiVersion()The API version: 6.
RunicNpc_Spawn
Section titled “RunicNpc_Spawn”BasePlayer RunicNpc_Spawn(Vector3 at, string profile, string owner, JObject overrides)Spawns one NPC now, or returns null.
ownermust berun:<id>orplugin:<name>.overridesmay change any profile field for this NPC only, in the profile’s own shape, or be null. For example:{"health": 500, "names": ["Captain"], "movement": {"mode": "route:gate", "radius": 0}}. Arrays are replaced, not merged, and the merged profile is checked like a saved one.- A roamer must stand on Rust’s navmesh, within 3 m across and 2 m up or down of
at. A sentry may stand anywhere. - It is refused until the map’s navmesh is built, which takes 8–10 minutes on a map’s first boot.
It is refused for an unknown or refused profile, a bad owner, an override that fails, a spot off the navmesh, a cap an admin has set, or a navmesh not built yet.
RunicNpc_Despawn
Section titled “RunicNpc_Despawn”int RunicNpc_Despawn(ulong netId)Removes one NPC by its net id, and returns 1, or 0 if it is not one of RunicNPC’s. A placement’s NPC comes back after its respawn delay. For a boss, it also removes the adds that boss summoned, even once the boss is dead, and counts them in what it returns: whoever placed the boss knows only the boss’s net id.
RunicNpc_DespawnOwner
Section titled “RunicNpc_DespawnOwner”int RunicNpc_DespawnOwner(string owner)Removes every NPC of owner, and returns how many it removed.
RunicNpc_IsRunicNpc
Section titled “RunicNpc_IsRunicNpc”bool RunicNpc_IsRunicNpc(BaseEntity entity)Whether entity is one of RunicNPC’s NPCs.
RunicNpc_ProfileOf
Section titled “RunicNpc_ProfileOf”string RunicNpc_ProfileOf(BaseEntity entity)The name of its profile, or null.
RunicNpc_CostWarning
Section titled “RunicNpc_CostWarning”string RunicNpc_CostWarning(int adding)The cost warning for the NPCs the server plans, plus
adding: what they add to a server frame, idle and fighting, and how slowly each then reacts. A
caller that adds NPCs should show it to whoever added them.
Listing NPCs
Section titled “Listing NPCs”RunicNpc_List
Section titled “RunicNpc_List”List<Dictionary<string, object>> RunicNpc_List(string owner)The live NPCs of owner, or of every owner when it is null. Each row has:
| Key | Type | What it is |
|---|---|---|
netId | ulong | Its net id, which RunicNpc_Despawn and the orders take |
profile | string | Its profile’s name |
name | string | The name it was given from its profile’s names |
owner | string | Its owner |
kit | string | The kit picked for it |
placement | string | Its placement’s id, or null |
position | {x, y, z} | Where it is |
home | {x, y, z} | Where it spawned: what it wanders around, and walks back to before it sleeps |
health | float | Its health now |
maxHealth | float | Its full health |
movement | string | wander, monument or route:<name> |
rest | string | Awake, GoingHome or Asleep |
state | string | Rust’s own AI state: Idle, Roam, Chase, Combat and so on |
leashes | int | How many times it has given up a chase at its chase range |
regrounded | int | How many times the ground went from under it and it was put on the nearest navmesh |
faction | string | Its faction, or profile:<name> when its profile has none |
target | string | The prefab of the NPC, animal or turret it is fighting, or null. Players are not reported here |
engaged | bool | Whether it is fighting that target now — Rust fights players first |
escort | string | Whom it escorts: a player’s Steam id, or an entity’s prefab; null for none |
ally | string | clan:<id>, team:<id> or player:<steam id>, or null |
tether | string | The ZoneManager zone it is held in, or null |
shotsMarked | int | Shots it made at an NPC target; each marks the target hostile for that shot only |
kitUsed | object | heals, throws, rockets and meleeHits: how much of its kit’s extras it has used |
role | string | Its profile’s role: roamer, sentry, guard or passive |
boss | object | For a boss, phase (0 before the first, then 1, 2 …) and damagers, how many players have hurt it; null for any other NPC |
Orders for one NPC
Section titled “Orders for one NPC”RunicNpc_Escort
Section titled “RunicNpc_Escort”string RunicNpc_Escort(ulong netId, BaseEntity target)One of RunicNPC’s NPCs escorts target: a player, or any other entity — a crate it guards, a
vehicle. It keeps within a few metres, never targets it, and fights whoever damages it. When the
target dies, is destroyed or, for a player, leaves the server, it walks back to its spot,
carries on as its profile does there, and OnRunicNpcEscortEnded is raised. A null target
stops it. Null on success; refused for a sentry, which never moves, and for a player who is not on
the server.
RunicNpc_Ally
Section titled “RunicNpc_Ally”string RunicNpc_Ally(ulong netId, string kind, string id)Allies one NPC to clan (the game’s own clan id), team (a Rust team id) or player (a Steam
id: that player, and their team if they have one), or to nobody with none. It never targets
the ally’s people, and defends them and what they own — building blocks, doors, deployables:
whoever damages one of them within its leash is fought. Rust’s own clans and teams only. Null on
success; refused for a clan or team the server does not have.
RunicNpc_Tether
Section titled “RunicNpc_Tether”string RunicNpc_Tether(ulong netId, string zone)Holds one NPC inside a ZoneManager zone: it never chases or wanders out, and if it ends up outside
— pushed, or the zone moved — it forgets the fight and walks home. A null zone frees it. Refused
for a sentry, on a server without ZoneManager, for a zone the server does not have, and for a zone
that does not hold the NPC.
Profiles and factions
Section titled “Profiles and factions”RunicNpc_Profiles
Section titled “RunicNpc_Profiles”JObject RunicNpc_Profiles(){"managed": bool, "profiles": {name: profile, …}, "factions": [pair, …], "refused": {name: reason, …}}.
managed is whether a site manages this server. A refused profile is kept in the file but never
spawns — a kit the server lacks, for example. factions is the faction table. Every field of a
profile is on Profile fields.
RunicNpc_SetProfiles
Section titled “RunicNpc_SetProfiles”Dictionary<string, string> RunicNpc_SetProfiles(JObject all)Replaces the whole profile set with all ({name: profile, …}), as a site does on every push,
and marks the server managed: from then on, the console commands that edit profiles are
refused. It returns the profiles refused and why; the rest are in use at once. A placement whose
profile has gone waits, and spawns again when the profile returns.
RunicNpc_Factions
Section titled “RunicNpc_Factions”JArray RunicNpc_Factions()The faction table: [{"a": "bandits", "b": "guards", "relation": "hostile"}, …], one row per
pair, meaning both ways. A pair not listed is neutral, and a faction is always allied to itself.
RunicNpc_SetFactions
Section titled “RunicNpc_SetFactions”string RunicNpc_SetFactions(JArray pairs)Replaces the faction table, as a site does with every push, and marks the server managed.
Null on success; otherwise the first problem, and the old table is kept. Refused: a pair of one
faction with itself; a pair of scientists and animals, because RunicNPC does not change how
Rust’s own NPCs treat each other; a relation other than hostile, neutral or allied; and a
pair given twice, in either order.
Placements
Section titled “Placements”A placement is a spot where a profile’s NPCs stand and come back after they die. It is saved; its NPCs never are. Its keys:
| Key | What it is |
|---|---|
profile | The profile its NPCs are made from |
position | {x, y, z}. Through RunicNpc_AddPlacement, a position without y is a point on the map, put on the ground there |
yaw | Which way they face, in degrees |
count | How many NPCs stand there. All but the first are scattered within 3 m of the spot |
respawn | Seconds after a death before an NPC comes back; at least 1 |
respawnMode | each: every NPC comes back respawn after its own death. group: none comes back until all are dead, then all together |
movement | Optional. {mode, radius}, overriding the profile’s |
tether | Optional. A ZoneManager zone its NPCs never leave. A zone the server lacks, or one that does not hold the spot, is refused |
{ "profile": "warden", "position": { "x": 100.0, "y": 12.5, "z": -340.0 }, "yaw": 90, "count": 3, "respawn": 300, "respawnMode": "each", "movement": { "mode": "route:gate", "radius": 0 }}A placement whose profile or zone has gone waits, and spawns again when it returns. If the ground under a placement goes later — a player-built floor destroyed — a live NPC is put on the nearest navmesh within 2 s, and the placement respawns its NPCs on the nearest navmesh until its spot is walkable again. Rust itself would leave such an NPC standing in the air.
RunicNpc_Placements
Section titled “RunicNpc_Placements”List<Dictionary<string, object>> RunicNpc_Placements()Each placement as {id, placement, alive, waiting, lastError, note}: placement is its JSON,
alive how many of its NPCs are alive, and waiting why it cannot spawn now, or null. note is
set while its NPCs stand somewhere other than its spot because the ground there went, and null
otherwise.
RunicNpc_AddPlacement
Section titled “RunicNpc_AddPlacement”Dictionary<string, object> RunicNpc_AddPlacement(JObject placement)Creates a placement and names it as /rnpc place does: the profile’s name and the first free
number, warden-3. It is checked and refused exactly as /rnpc place is, with the same
sentences, so a placement made by another plugin or a website and one made in game never disagree.
placementhas no id. Apositionwithoutyis a point on the map: it is put on the ground there by a ray down onto terrain and rock, never a building or a tree, then checked against the navmesh like any other. A point off the map, or under water, is refused.- The answer is
{id, position, built, cost}— the name given, where it landed, whether that spot is on something players built, and the cost warning — or{error}, the sentence/rnpc placewould have said.
RunicNpc_SetPlacement
Section titled “RunicNpc_SetPlacement”string RunicNpc_SetPlacement(string id, JObject placement)Adds or replaces a placement with the id you give. Null on success, or the reason. Replacing one removes its NPCs and spawns them again from the new values. Every set logs the cost warning.
A roamer’s spot must be on Rust’s navmesh, within 2 m up or down, when it is set; otherwise the answer says how far off it is. The check is skipped while the map’s navmesh is still being built, and for a profile that does not exist yet.
RunicNpc_RenamePlacement
Section titled “RunicNpc_RenamePlacement”string RunicNpc_RenamePlacement(string from, string to)Renames a placement, as /rnpc rename does: its live NPCs keep living under the new name. Null on
success, or why not — no such placement, the name taken, or not a name.
RunicNpc_RespawnPlacement
Section titled “RunicNpc_RespawnPlacement”int RunicNpc_RespawnPlacement(string id)Removes a placement’s NPCs and spawns them again at once, as /rnpc respawn does. Returns how
many, or -1 if there is no such placement.
RunicNpc_RemovePlacement
Section titled “RunicNpc_RemovePlacement”bool RunicNpc_RemovePlacement(string id)Removes a placement and its NPCs.
Routes
Section titled “Routes”A route is a line of points an NPC walks. An NPC joins a route at its nearest point.
| Key | What it is |
|---|---|
points | At least two {x, y, z} points, each on Rust’s navmesh |
loop | True: the last point leads back to the first. False: the route is walked back and forth |
{ "points": [ { "x": 1, "y": 2, "z": 3 }, { "x": 4, "y": 2, "z": 6 } ], "loop": true }RunicNpc_Routes
Section titled “RunicNpc_Routes”JObject RunicNpc_Routes()Every route, as {name: route, …}.
RunicNpc_SetRoute
Section titled “RunicNpc_SetRoute”string RunicNpc_SetRoute(string name, JObject route)Adds or replaces a route. Every point must be on Rust’s navmesh. Null on success, or the reason.
Unlike /rnpc path, it does not check that an NPC can walk from each point to the next: a leg
Rust cannot path leaves the NPC standing at the last point it reached, so a caller that builds
routes should check its own legs.
RunicNpc_RemoveRoute
Section titled “RunicNpc_RemoveRoute”bool RunicNpc_RemoveRoute(string name)Removes a route. Placements that walk it wait until it exists again.
Hooks it raises
Section titled “Hooks it raises”Every hook is called on every plugin, and none of them answers: a return value is ignored.
| Hook | When |
|---|---|
OnRunicNpcSpawned(BasePlayer npc, string profile, string owner) | After an NPC spawns and is equipped. |
OnRunicNpcHealth(BasePlayer npc, string profile, float threshold) | The first time its health falls to one of its profile’s healthThresholds. |
OnRunicNpcDied(BasePlayer npc, string profile, string owner, HitInfo info, Dictionary<ulong, float> contributors) | When it dies. contributors maps each player’s Steam id to the health that player took from it, the killing blow included, after Rust’s protection — never more than its health in all. |
OnRunicNpcDespawned(BasePlayer npc, string owner) | When it is removed without dying. Not raised while RunicNPC itself unloads. |
OnRunicNpcPlacementChanged(string id, string change, string previous) | A placement was set, removed or renamed, through the API or in game. change is set, removed or renamed; previous is the old name for a rename, and null otherwise. |
OnRunicNpcEscortEnded(BasePlayer npc, string profile, string owner) | Whom it escorted died, was destroyed or left the server, and it is walking back to its spot. |
OnRunicNpcBossSpawned(BasePlayer npc, string profile, string owner) | After OnRunicNpcSpawned, for a profile with a boss block, once its spawn line has been said. |
OnRunicNpcBossPhase(BasePlayer npc, string profile, string owner, int phase, float at) | It entered a phase. phase counts from 1 and at is the phase’s health fraction. Raised once the phase’s changes apply and its line is said; a hit that crosses two thresholds raises both, highest first. |
OnRunicNpcBossDied(BasePlayer npc, string profile, string owner, HitInfo info, Dictionary<ulong, float> contributors) | After OnRunicNpcDied, for a boss, with the same contributors, once its death line has been said. RunicNPC gives no reward itself. |
OnRunicNpcUsed(BasePlayer npc, string profile, BasePlayer player) | A player pressed E on a passive NPC and was answered. At most once a second per player. |
Its files
Section titled “Its files”data/RunicNPC/profiles.json (the profiles, the faction table and whether a site manages them),
placements.json and routes.json, under oxide/ or carbon/. From a plugin, change them
through the calls above rather than the files. See Install RunicNPC
for every file and who writes it.