Recent changes Random page
GAMING
Gaming
 
WoWWiki
Halopedia
FFXIclopedia
Age of Conan
Warhammer Online
Grand Theft Wiki
See more...

NPC Stalker

From NWNWiki

Jump to: navigation, search

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.

[edit] Notes

  • 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.

[edit] The Script

void main() 
{
   object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
   ClearAllActions();
   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
}
Rate this article:
Share this article: