The NPC Stalker script can be put made the OnHeartbeat event handler of a non-player character, causing that NPC to follow literally at the heels of the nearest player character.
- This was an experiment with the AngleToVector command, originally posted in the BioWare forums by Cheiron the Centaur.
- The original post included a "CorrectDirection" function that was used as a work-around for a bug that existed before NWN patch 1.23.
The Script Edit
object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
object oArea = GetArea(oTarget);
vector vPosition = GetPosition(oTarget);
float fOrientation = GetFacing(oTarget);
vector vNewPos = AngleToVector(fOrientation);
float vX = vPosition.x - vNewPos.x;
float vY = vPosition.y - vNewPos.y;
float vZ = vPosition.z;
vNewPos = Vector(vX, vY, vZ);
ActionMoveToLocation( Location( oArea, vNewPos, fOrientation) ); // go stand right behind the PC (if he's still there)
ActionDoCommand(SetFacing(fOrientation)); // turn towards PC