Group of Npc following a player

Hello everyone!

I’m trying to do a quest where a bunch on npcs follows a player to a place, then they get ambushed and all die.

I created a custom follow function since the ActionForceFollowObject() teleports npcs after some time if they get too far, they are 6 npcs and that caused in some places that they block the player surrounding him.

The custom function its simple:

void FollowNPC(object oTarget)

It works fine, they do follow the player all arround. I set it on the heartbeat of the NPCs like this:

if(!GetIsInCombat() && GetObjectSeen(GetLocalObject(OBJECT_SELF,“master”)))

I store the master object so they can call it every time, did this to recover the following after npcs engage combat.

The big issue I’m having it’s in transitions, either way triggers or clickable custom doors(not actual doors transitions). When a player uses the custom door, this script its attachet to teleport “in theory” everyone inside:

void main()

// Get the creature who triggered this event.
object oPC = GetLastUsedBy();

// Find the location to which to teleport.
object oTarget = GetWaypointByTag("LV426023inter001away");

// Teleport the PC.
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, JumpToObject(oTarget));

location oDestination = GetLocation(oTarget);

int iFollow =GetLocalInt(oPC,"Following");
object oMarine1 =  GetObjectByTag("Drake");
object oMarine2 =  GetObjectByTag("CplHicks");
object oMarine3 =  GetObjectByTag("Frost");
object oMarine4 =  GetObjectByTag("Hudson");
object oMarine5 =  GetObjectByTag("SergApone");
object oMarine6 =  GetObjectByTag("Vasquez");












At area transition triggers a similar script its writen. The Issue? NPCs are not traveling between areas :frowning: the tags are unique

Anyone experienced with this kind of script before?

You also need to issue CAA for each NPC. I suggest you use this on each of them so that both functions are called one after another in the same context:

void ClearAllActionsAndJump(object oTarget)
    ClearAllActions(); JumpToObject(oTarget);

Then business as usual:

DelayCommand(0.5, AssignCommand(oNPC, ClearAllActionsAndJump(oTarget)));

If party goes out of sync and somebody ends up in wrong area, you can modify your FollowNPC() to force a jump to the master.


I also see some possible improvements to this code:

  1. Your FollowNPC() will keep overflowing the creature’s action queue. You may want to follow only if NPC is not doing anything (ACTION_INVALID).
  2. You can store destination tag (LV426023inter001away) in local variable to make the jump script universal.
  3. Since there is no PC->NPC link here, assuming this is a single-player module, you can move all current follower NPCs to a custom, PC-friendly faction. This way you can iterate them via Get*FactionMember instead of using tags.
1 Like

Have you considered making the followers henchmen? That way, following, getting out of the PC’s way, and transitions are all handled for you. Unwanted radical commands (e.g. inventory) can be blocked OnConversation.

Just a thought.


Oh I see… didnt though about the the overflow in actions. I’ll try that CAA

The action invalid condition can be nice too, I’ll try it. Would be something like this?

if(ACTION_INVALID() && GetObjectSeen(GetLocalObject(OBJECT_SELF,“master”)))
Preformatted text`FollowNPC(GetLocalObject(OBJECT_SELF,“master”));

Actually im working on a server that may open soon, so it will be a persistent world. This is one optional quest with a bit of ambientation :stuck_out_tongue:

I’ll reply back after my tests since now i’m at work. Thanks Shacker!!

Hello Proleric!

I have considered it, but don’t really know how they work. Is there a limit on how many henchmans can a player have? This are 6 npcs. I’ll give it a try and investigate as well.

Thanks for your reply!!

I initially understood that those NPCs are only meant to simply follow you somewhere and get killed. I see now that you want actual party for them.

Like @Proleric said - henchmen are the way to go. Baseline assoc scripts take care of everything you mentioned (sans intra-area jumps) and you can tailor the details to your needs (i.e. ignore some AI callbacks to make the NPCs less submissive).

SetMaxHenchmen(6);      // set once anywhere in the module
AddHenchman(oPC, oNPC); // see 'hench' functions in the toolset

You will need to setup NPCs with assoc script set. You can copy it from inbox NPCs in the toolset (Linu, Daelan, etc) or from summoned creatures.

Script names start with nw_ch_.

GetCurrentAction() == ACTION_INVALID

But you won’t need this if you use henchmen scripts.

So, CplHicks isn’t going to be killed off-screen by crappy_script_3.nss? (:poop:-post).

1 Like

I have up to 12 associates working routinely in some of my modules, so 6 henchmen will be fine.

On the script tab in the toolset you can load a script set for XP2 henchmen, which is the latest, but probably no better than the NW ser for your purposes.


WEll i may have expresed my self wrong, but yeah those npc just follow the player to one place then all die tigreringt the quest event.

I’ll take a look into henchman scripts and test tonight. Thanks both for your replies!!

Okey Guys, tested with henchman scripts, all worked fine :smiley: thanks both really!! can only select 1 as solution tho >.<

Maybe the NPCs aren’t friendly enough? I recall that neutral NPCs won’t move out of the way for you. But I haven’t been doing NWN in a long time.