Class TimbnPluginNpcs
Gives people a day on the game clock, moves them and adds new ones for a plugin. Everything is owned by the plugin, so walks it started stop, claims are let go and added people are removed when it unloads. People, groups, events and animations come from the generated TimbnGameIds.Npcs, TimbnGameIds.Groups, TimbnGameIds.NpcEvents and TimbnGameIds.NpcAnimations, and points are named by their id. Reach it through the plugin's Npcs property.
public sealed class TimbnPluginNpcs
- Inheritance
-
TimbnPluginNpcs
- Inherited Members
Methods
AddVillager(string)
Adds one more of a kind of villager, who lives exactly like the ones the game placed. They join the same life simulator group, go out to its points by day and home at night. They start at their home and go straight out when the rest of their group is out. They are removed when the handle is disposed, the plugin unloads or the player returns to the main menu, and are left out of every save the game writes.
public TimbnNpc? AddVillager(string npcId)
Parameters
npcIdstringThe kind of villager, from TimbnGameIds.Npcs or GroupMemberIds(string).
Returns
- TimbnNpc
The handle, or null when the kind has no group or home, the group has no point left for one more, or at the main menu.
Examples
Npcs.AddVillager(TimbnGameIds.Npcs.Villager03);
CloseTradeWhen(string, Func<bool>, string?)
Keeps a vendor's trade window shut while a check says they are away, with the vendor saying a line in its place, such as outside the hours of their schedule.
public IDisposable CloseTradeWhen(string vendorId, Func<bool> isClosed, string? lineKey = null)
Parameters
vendorIdstringThe vendor, from TimbnGameIds.Npcs.
isClosedFunc<bool>True while the window should stay shut.
lineKeystringA text key added with Text.Add, said by the vendor in their speech bubble, or null for none.
Returns
- IDisposable
A handle that lets trade open again when disposed. It is also removed when the plugin unloads.
Examples
Npcs.CloseTradeWhen(TimbnGameIds.Npcs.Herm, () => TimbnClock.Weekday == TimbnWeekday.Pride, "my_mod_herm_resting");
Find(string)
Gets a handle to move a person in the loaded save outside a schedule, such as in a quest. Asking again in the same save gives the same handle. People added with Spawn are left out, so use the handle Spawn gave.
public TimbnNpc? Find(string npcId)
Parameters
npcIdstringThe person, from TimbnGameIds.Npcs.
Returns
- TimbnNpc
The handle, or null when they are not in the loaded world or at the main menu.
Examples
Npcs.Find(TimbnGameIds.Npcs.Herm)?.WalkTo("npc_sim_village_right_side_03");
Preload(IEnumerable<string>, int)
Loads the look of some kinds of people in the background, so the first Spawn of each kind in a session doesn't stall a frame for 10 to 30 ms while the game loads it. Call it when a save is ready, with every kind the mod may spawn. Copies count the ones the game already shows, so a kind out in the village with copies at 1 gets nothing ready, and a second one spawned then still stalls. Ask for 2 when the game's own may be about.
public void Preload(IEnumerable<string> npcIds, int copies = 1)
Parameters
npcIdsIEnumerable<string>The kinds of people, from TimbnGameIds.Npcs or GroupMemberIds(string).
copiesintHow many of each kind to have ready, counting the ones already shown.
Examples
Events.SaveReady(() => Npcs.Preload(TimbnNpcs.GroupMemberIds(TimbnGameIds.Groups.VillagersDayAll), copies: 2));
Schedule(string, TimbnNpcDay)
Gives a person a day on the game clock that follows every save the player loads. Set it up once in OnAwake.
public TimbnNpcSchedule Schedule(string npcId, TimbnNpcDay day)
Parameters
npcIdstringThe person, from TimbnGameIds.Npcs.
dayTimbnNpcDayThe day to follow.
Returns
- TimbnNpcSchedule
The schedule, for its status. Dispose it to stop early. It also stops when the plugin unloads.
Examples
Npcs.Schedule(TimbnGameIds.Npcs.Herm, HermsDay());
Spawn(string, string)
Adds a person to the loaded save at a point, such as one more villager. The game's life simulator leaves them alone, so walk them yourself. They are removed again when the handle is disposed, the plugin unloads or the player returns to the main menu, and are left out of every save the game writes.
public TimbnNpc? Spawn(string npcId, string pointId)
Parameters
npcIdstringThe kind of person, from TimbnGameIds.Npcs.
pointIdstringThe id of the point to put them at, such as npc_sim_village_left_side_road_01.
Returns
- TimbnNpc
The handle, or null when the point or the person is missing or at the main menu.
Examples
Npcs.Spawn(TimbnGameIds.Npcs.Villager03, "npc_sim_village_left_side_road_01")?.WalkTo("npc_sim_village_tavern_03");