Taking and releasing an NPC
This is the full list of what the API gives you, one section for each part. Every call takes modId, the id of your mod. The framework uses it to remember which mod holds which NPC (see Owner in the glossary).
NpcControl take and release NPCs
Call Take with your mod’s id and the NPC’s id to hold it, and Release to give it back. IsTaken and TakenBy tell you whether another mod holds it.
public static class NpcControl
{
public static bool IsAvailable { get; }
public static bool Take(string modId, int npcId, NpcControlFlags flags = NpcControlFlags.All);
public static bool Release(string modId, int npcId);
public static int ReleaseAll(string modId);
public static bool IsTaken(int npcId);
public static string TakenBy(int npcId);
}
| Method | Returns | What it does |
|---|---|---|
Take(modId, npcId, flags) | bool | Takes the NPC and switches off the parts named in flags. true on success. |
Release(modId, npcId) | bool | Gives the NPC back. false when your mod holds nothing on that NPC. |
ReleaseAll(modId) | int | Gives back every NPC your mod holds, and returns how many. |
IsTaken(npcId) | bool | true while any mod holds the NPC. |
TakenBy(npcId) | string | The id of the mod that holds the NPC. null when it is free. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the NPC control feature was turned off. |
NpcControlFlags which parts of the NPC to switch off
Take takes one of these to choose which parts of the NPC to switch off. Leave it out and every part is switched off.
[Flags]
public enum NpcControlFlags
{
None = 0,
Sight = 1,
Talk = 2,
Barks = 4,
Fade = 8,
Movement = 16,
All = Sight | Talk | Barks | Fade | Movement
}
| Value | Meaning |
|---|---|
None | Hold the NPC but change nothing. |
Sight | The NPC stops noticing anything around it. |
Talk | The player can no longer start a conversation with it. |
Barks | The game’s own comments from it stop. |
Fade | It is no longer hidden when you are far away or look away. |
Movement | It stops walking and stays where it is. |
All | Every part above. |
Things to know
Takeswitches off every part by default, or only the parts you name inflags.- Only one mod can hold an NPC at a time. Another mod’s
Takeon the same NPC returnsfalseuntil the mod that holds it releases it. - Calling
Takeagain with the same mod changes the parts you hold. A flag that is no longer in the set is put back. A new flag is switched on at once. It returnstrue. TakewithNoneholds the NPC without changing anything about it. Other mods can’t take it while you hold it.Releaseputs back each thing your mod changed.ReleaseAllreturns how many NPCs it released.TakenBytells you which mod holds the NPC.IsAvailableisfalsewhen the feature group was turned off.Releaseand the reads keep working, so a mod can still give back an NPC it took earlier.
Limits
Takereturnsfalsewhen it can’t take the NPC. That happens when another mod already holds it, when the NPC is unknown, dead or in a different scene, when it is switched off for any other reason than being far away, while a save is loading or being written, and when the feature group is turned off.