Following the player
These two calls start and stop an NPC walking after the player.
NpcActions following the player
Call FollowPlayer to make the NPC follow the player, and StopFollowing to end it.
public static class NpcActions
{
public static bool FollowPlayer(int npcId, bool run, bool untilStopped);
public static bool StopFollowing(int npcId);
}
| Method | Returns | What it does |
|---|---|---|
FollowPlayer(npcId, run, untilStopped) | bool | Makes the NPC follow the player. |
StopFollowing(npcId) | bool | Makes the NPC stop following. |
Things to know
FollowPlayermakes the NPC walk after the player, or run whenrunistrue. Always passfalseforuntilStopped. Then the follow can be interrupted, and the NPC’s own routine can take over again when it needs to.- With
untilStoppedset totrue, the follow cannot be interrupted. It lasts until you callStopFollowingor the game ends it. It is saved with the NPC, so it can come back in a later session even after your mod is removed. Usetrueonly when your mod must hold the NPC. (untilStoppedis the game’scanBeInterruptedargument turned around. The saved state keeps the activity, andNPCDirectorloads the savedNPCDataState.) StopFollowingmakes the NPC stop whatever follow it is doing, and givesfalsewhen it is not following. This includes a follow that the game, a quest or a conversation started, such as a chase, and not only one your mod started. (It callsNPCController.ForceStopActivitywhen the current activity is anAct_Follow.)
Limits
FollowPlayergivestrueonly when following is now what the NPC is doing. The game sometimes refuses to start it, for example when the NPC is doing something more important or something that cannot be interrupted. Then you getfalse. (The game’sFollowPlayerreturns the new activity even when it refuses, so the framework checks the current activity instead. It checksDataandData.characterfirst, because the game’s follow logsData.character.FullName.)- NPC 107 can have its follow stopped by the game after a load. When you load a save, the game stops that NPC’s follow in some conditions, so a follow on it can end without you calling
StopFollowing. (NPCDirectorforce-stopsAct_Followon NPC 107 (theResident/Crazy Neighboractor) at load when that tenement resident is rented and the Dialogue System’sLastVisitDayfor that actor is 4 or less.)