Any best practices for moving NPCs from one area to another?

I’m doing a quest where you rescue an NPC from a cave and later meet that NPC at an inn, which in essence requires me to move the NPC from the cave into the inn. I simply destroyed the NPC in the cave and then added an onEnter script to the inn that spawns a new NPC with the same template into the inn once certain conditions have been met.

Then I got thinking; I’m going to do something akin to this plenty of times in the module I’m making, and this particular NPC is going to appear often and in different places. Is there a better way of doing this? Should I use the same NPC or should I make multiple templates for the NPC to correspond to the different areas he’s going to spawn in? Is there a way simply move the NPC to a different area without destroying him and thus retaining any local variables I may have stored on him along with potential inventory changes?

So essentially I’m asking for opinions of those who have more experience with this, and hopefully avoid any pitfalls by adopting a sound strategy early on rather than having to rework major parts afterwards. Any personal experiences and recommendations will do.

There’s no reason to have more than one template / instance of the NPC.

Indeed, I find that having just one instance makes bug-free coding much easier, because there’s no ambiguity when looking for the object by tag, and it’s possible to store the NPC status and history as local variables on the NPC itself.

ActionJumpToLocation() will move them instantly to a new location.

If they are not in the PC’s area at the time, use SetAILevel() to a high value first.

If you want them to walk to an exit before jumping, you can use SetCommandable() to prevent the PC from disturbing them in the process. I also use EffectCutsceneGhost() to prevent them being blocked, though it does make the NPC walk through any blockers, which some might consider odd.


Why the SetAILevel()? What does it do in this context, why is it necessary?

I’d make the NPC plot and use JumpToLocation instead of the action type (this should skip any actions they might be doing and I don’t think can be interrupted), but the SetAILevel helps with the AI running scripts and their action queue when no PCs are present, which otherwise may mean the object is delayed getting to the location you want if not set to a higher value.

1 Like