Author Sticky: Post Working Scripts Here
Uthoroc Posted: Tuesday, 23 July 07:37AM
Script name: Nightwatchman

What it does: Makes a patrolling watchman close open doors and hail/interrogate PCs at night

Notes:
- This script goes into the OnUserDefinedEvent position of the NPC.
- This will work even better when your watchman uses Rhone11's Hour-based waypoint walker.
See: Click Here
Simply set up the NPC using his instructions, replace WalkWayPoints() in my script with HourWayPoints(), and change the include file at the top to the one for the new waypoint script (usually MY_I0_GENERIC).
- Make sure to call WalkWayPoints() when your watchman's conversation ends.
- The watchman is easily distractible by open doors. A good way for evil PCs to cover their sinister activities.

The script:
NWScript:
//::///////////////////////////////////////////////

//:: User Defined Event for Caer Camlin Nightwatch

//:: user_nightwatch.nss

//:://////////////////////////////////////////////

/*

  This makes a nightly patrolman close doors and hail/interrogate PCs

*/

//:://////////////////////////////////////////////

//:: Created By: Ralf Schemmann

//:: Created On: 23rd July 2002

//:://////////////////////////////////////////////

#include "NW_I0_GENERIC"

void main()

{

    int nUser = GetUserDefinedEventNumber();

    if(nUser == 1001) //HEARTBEAT

    {

      //Only patrol and close doors at night and in town

      if (GetIsNight())

      {

       //Get nearest door

       object oDoor = GetNearestObject(OBJECT_TYPE_DOOR);

       //if door is open, close it

       if (GetIsOpen(oDoor))

       {

         //if not already closing the door, start doing it

         if (GetLocalInt(OBJECT_SELF, "nClosingDoor") != 1)

         {

           SetLocalInt(OBJECT_SELF, "nClosingDoor", 1);

           SpeakString("Who left that door open? Hm.");

           ClearAllActions();

           ActionCloseDoor(oDoor);

         //else just mumble a bit

         }

         else

           SpeakString("Irresponsible!");

       }

       //if door is closed and not already patrolling start walking waypoints

       else

         SetLocalInt(OBJECT_SELF, "nClosingDoor", 0);

         if (GetCurrentAction() == ACTION_INVALID && !IsInConversation(OBJECT_SELF))

           WalkWayPoints();

      }

      //if nothing to do and not in conversation, start patrolling

      else if (GetCurrentAction() == ACTION_INVALID && !IsInConversation(OBJECT_SELF))

        WalkWayPoints();

    }

    else if(nUser == 1002) // PERCEIVE

    {

      //Only hail people at night

      if (GetIsNight())

      {

       //only do something when not closing a door

       if (GetLocalInt(OBJECT_SELF, "nClosingDoor") != 1)

       {

         //get the last object seen

         object oSeen = GetLastPerceived();

         //if object was a PC, hail it

         if (GetIsPC(oSeen))

         {

           if (GetLastPerceptionSeen())

             SpeakString("Who goes there? I see you!");

           else

             SpeakString("Who goes there? I heard you!");

           //if watchman actually sees the PC, interrogate him

           if (GetObjectSeen(oSeen))

           {

             ClearAllActions();

             ActionStartConversation(oSeen);

           }

           //else wait a moment, then continue walking waypoints

           else

           {

             ClearAllActions();

             DelayCommand(2.0f, WalkWayPoints());

           }

         }

       }

      }

    }

    else if(nUser == 1003) // END OF COMBAT

    {

    }

    else if(nUser == 1004) // ON DIALOGUE

    {

    }

    else if(nUser == 1005) // ATTACKED

    {

    }

    else if(nUser == 1006) // DAMAGED

    {

    }

    else if(nUser == 1007) // DEATH

    {

    }

    else if(nUser == 1008) // DISTURBED

    {

    }

}