Table of Contents

Class TimbnNpc

Namespace
Timbn.GraveyardKeeperTwo.Core.Framework
Assembly
Timbn.GraveyardKeeperTwo.Core.dll

A person in the loaded save that a plugin moves, from the plugin's Npcs.Find or Npcs.Spawn. Every method does nothing and returns false once the person is gone. When the handle is disposed, the plugin unloads or the player returns to the main menu, a walk it started is stopped, its claim is let go, and a person Npcs.Spawn added is removed.

public sealed class TimbnNpc : IDisposable
Inheritance
TimbnNpc
Implements
Inherited Members

Properties

CollidesWithPlayer

Whether the person blocks the keeper like a wall. Set it to false for a crowd the keeper should be able to walk through, such as visitors who stand about the graveyard. It only changes the person's solid parts toward the keeper's body, so they are still talked to, hit and walked around by everyone else, and it carries over when the person streams out and back in. Leave it alone for someone the keeper has to be able to push against.

public bool CollidesWithPlayer { get; set; }

Property Value

bool

Examples

visitor.CollidesWithPlayer = false;

Data

The person's world object.

public WgoData Data { get; }

Property Value

WgoData

Id

The person's definition id, such as npc_larry, the one TimbnGameIds.Npcs lists. Handy for a log line.

public string Id { get; }

Property Value

string

IsGone

Whether the person is no longer in the loaded world, after a dispose, a removal or the save closing.

public bool IsGone { get; }

Property Value

bool

IsRunning

Whether a run started with RunSteps(TimbnNpcSteps, Action?) on this person, by any plugin, is still playing. A run the game takes over, by firing one of the person's events or moving them in a story scene, ends without its done callback, so a plugin that keeps a list of the people it spawned checks this to notice one the game left standing.

public bool IsRunning { get; }

Property Value

bool

IsWalking

Whether the person is on a walk.

public bool IsWalking { get; }

Property Value

bool

MinutesLeftInBlock

How many game minutes are left before the next block of their schedule starts, or 24 hours when the day has one block. It is 0 for a person no schedule drives. Use it to leave a long trip alone when the block is about to change.

public double MinutesLeftInBlock { get; }

Property Value

double

Position

Where the person stands.

public Vector3 Position { get; }

Property Value

Vector3

ReputationId

The id of the player resource that holds the player's reputation with this NPC, or null for an NPC without one.

public string? ReputationId { get; }

Property Value

string

Methods

Animate(string)

Plays an animation trigger, but only one the person has a clip of their own for, since any other makes them vanish. It keeps playing until their next walk. While they are far from the player the game unloads their animations, so the trigger waits and plays once they load, unless they walk on first.

public bool Animate(string trigger)

Parameters

trigger string

The animation, from TimbnGameIds.NpcAnimations such as TimbnGameIds.NpcAnimations.Herm.AdjustingJabbot.

Returns

bool

False when the person has no clip for it and nothing was played.

BlockedReason(string)

Why a point cannot be used by this person, such as "occupied by the player", or null when it is free.

public string? BlockedReason(string pointId)

Parameters

pointId string

Returns

string

Claim(string)

Claims a point so no other schedule, and none of the game's villagers, are sent to it, letting go of the point claimed before. A schedule lets go of it when the trip that claimed it ends, and a run lets go of a point claimed during it when it ends. A point claimed before a run, such as a seat the person walks to, stays claimed after it until they claim another, the handle is disposed or they are gone.

public bool Claim(string pointId)

Parameters

pointId string

Returns

bool

False when someone else holds a claim on it, or one of the game's villagers is at it or on the way there.

Dispose()

Stops what this handle started and lets go of its claim, and removes a person Npcs.Spawn added.

public void Dispose()

Face(Direction)

Turns the person to face a direction.

public void Face(Direction direction)

Parameters

direction Direction

Face(Vector3)

Turns the person toward a spot, such as a grave or another person, at whatever angle it lies. Does nothing when they already stand on it.

public void Face(Vector3 point)

Parameters

point Vector3

The point to look at. Its height is ignored.

Examples

npc.Face(grave.Position);

FireEvent(string)

Fires an event of the person's own game script, such as Herm's go_home. Story events start real story and trade, so only fire ones known to move or animate. The game's graphs only act while the person's busy and on_spot resources are 0, which a stopped walk or a teleport leaves wrong, so both are set to 0 first.

public void FireEvent(string eventName)

Parameters

eventName string

The event, from TimbnGameIds.NpcEvents.

IsFree(string)

Whether a point is free for this person, meaning it exists, is switched on, nobody else claimed it and nobody stands on it.

public bool IsFree(string pointId)

Parameters

pointId string

Returns

bool

RollChance(float, out double, string)

The same roll as RollChance(float, string), also handing back what was rolled for a log line of your own.

public Random? RollChance(float chance, out double rolled, string what = "a trip")

Parameters

chance float

The roll passes when it is this or lower, from 0 to 1.

rolled double

What was rolled.

what string

What the roll is for, named in the log, such as "a trip".

Returns

Random

The dice to keep choosing with, or null on a miss.

RollChance(float, string)

Rolls the person's dice for this game minute against a chance, such as whether to set off on a trip. The same minute rolls the same on a reload, and each person added with Npcs.Spawn rolls apart from the others of their kind. A miss is written to the log with the roll, so a skipped trip explains itself.

public Random? RollChance(float chance, string what = "a trip")

Parameters

chance float

The roll passes when it is this or lower, from 0 to 1.

what string

What the roll is for, named in the log, such as "a trip".

Returns

Random

The dice to keep choosing with, or null on a miss.

Examples

.Decide(npc => npc.RollChance(0.75f) is { } random ? Trips[random.Next(Trips.Length)] : null)

RunSteps(TimbnNpcSteps, Action?)

Plays a list of steps on command, such as for a quest or a cutscene, and calls back when the last one is done. A new run on the same person replaces the one before. It starts at once, even in the middle of a conversation with them. The person still stops when the player starts talking to them later in the run, but not for a story scene, since a cutscene is when you want them moving. When the game itself moves them, through a story walk, a teleport or a script event, the run ends and leaves them to it. A schedule of theirs steps aside while it plays and takes them back as soon as it ends.

public IDisposable? RunSteps(TimbnNpcSteps steps, Action? done = null)

Parameters

steps TimbnNpcSteps

What to do, in order.

done Action

Runs once after the last step. It does not run when the run is stopped or replaced, the game takes the person, the save closes or the plugin unloads.

Returns

IDisposable

The run, which stops it when disposed, or null when the person is gone.

Examples

Npcs.Find(TimbnGameIds.Npcs.Larry)?.RunSteps(new TimbnNpcSteps()
    .Walk("RT_larry_spawn")
    .WaitRealSeconds(3)
    .WalkNavmesh("npc_sim_village_right_side_road_34")
    .Face(Direction.Down), done: OnLarryArrived);

Say(string, float)

Says a line in the game's own speech bubble over the person, the one they talk in, which follows them as they walk and fades by itself after a few seconds while they mumble in their voice. It takes no control and the player cannot skip it, so it never eats a key press. A new line replaces the one they are saying.

public void Say(string text, float seconds = 0)

Parameters

text string

A text key added with Text.Add or a lang file, or the text itself. Square brackets are the game's color markup.

seconds float

How long the line stays once written out. Leave it at 0 for the game's time for its length.

Examples

customer.Npc.Say("my_mod_complaint");

StopWalking()

Ends the walk the person is on, whoever started it, and leaves them standing where they are.

public void StopWalking()

Teleport(string)

Puts the person on a point at once, facing the way it faces, and ends any walk.

public bool Teleport(string pointId)

Parameters

pointId string

The id of the point, such as npc_sim_village_right_side_03.

Returns

bool

False when the point is missing or the person is gone.

Teleport(Vector3)

Puts the person on a spot at once, keeping the way they face, and ends any walk. It takes a person through a door only the keeper can use, such as from the church's outside landing tp_RT_church_enter to its inside one tp_RT_church_exit, which are world objects and not points.

public bool Teleport(Vector3 position)

Parameters

position Vector3

Where to put them, height included.

Returns

bool

False when the person is gone.

Examples

npc.Teleport(TimbnWorld.FindAll("tp_RT_church_exit")[0].Position);

WalkTo(string, TimbnWalk, Action?, Action?)

Walks the person to a point and turns them the way it faces. A walk along the paths the paths do not reach is skipped, or tried again from the day's origin when the person has a schedule.

public bool WalkTo(string pointId, TimbnWalk walk = TimbnWalk.Paths, Action? arrived = null, Action? failed = null)

Parameters

pointId string

The id of the point to walk to, such as npc_sim_village_right_side_03.

walk TimbnWalk

Along the game's paths, or over the navmesh.

arrived Action

Runs once on arrival. It does not run when the walk is stopped or replaced, or cannot reach the point.

failed Action

Runs once when the walk started but could not reach the point, so a chain of walks can go on or give up. It does not run when the walk is stopped or replaced.

Returns

bool

False when the point is missing, the paths do not reach it, or the person is gone.

Examples

herm.WalkTo("npc_sim_village_right_side_road_34", TimbnWalk.Navmesh, () => herm.WalkTo("npc_sim_village_right_side_03"));