Author Sticky: Post Working Scripts Here
Ratbert_CP Posted: Tuesday, 25 June 12:22AM
Script name: WalkAnyWayPoints
Purpose: To provide a more flexible version of WalkWayPoints.
Usage: Replace WalkWayPoints in your OnSpawn script with WalkAnyWayPoints, with the appropriate parameters.
Notes: The first parameter is a string denoting the new "base" for the waypoint path. WalkWayPoints uses the tag as the base (and WAWP will do the same if you pass an empty string or no parameters). It also provides a method to effectively walk in circles. If you pass TRUE in the second parameter, the creature/NPC will walk in circles, rather than back and forth. (1-2-3-1-2-3 instead of 1-2-3-2-1).

You need the RunAnyCircuit and RunAnyNextCircuit as well. I put these into a script, and #include that script in the places I need it. Compiling a "raw" include file is a pain, since I've found it best to compile each "real" script by hand in the script tool, and turn *off* compiling when saving or building the module.

NWScript:
#include "NW_I0_Generic"

// void main() {}

void RunAnyCircuit( int nTens, int nNum, int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0 );

void RunAnyNextCircuit( int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0 );

void WalkAnyWayPoints( string sWayTag = "", int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0 );

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

//:: Walk Any Way Point Path

//:: Copyright (c) 2001 Bioware Corp.

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

/*

    Allows specified person walk a waypoint path

    Modified to allow an arbitrary path, not just

    based on the Creature's tag

*/

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

//:: Created By: Aidan Scanlan

//:: Created On: July 10, 2001

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

//:: Modified By: Kenneth Cummins

//:: Created On: June 24,, 2002

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

void WalkAnyWayPoints( string sWayTag = "", int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0 )  //Run first circuit

{

    ClearAllActions();

    string DayWayString;

    string NightWayString;

    string DayPostString;

    string NightPostString;

    string sWay;

    string sPost;

    //The block of code below deals with night and day cycle for postings and walkway points.

    if( GetSpawnInCondition( NW_FLAG_DAY_NIGHT_POSTING ) )

    {

        DayWayString = "WP_";

        NightWayString = "WN_";

        DayPostString = "POST_";

        NightPostString = "NIGHT_";

    }

    else

    {

        DayWayString = "WP_";

        NightWayString = "WP_";

        DayPostString = "POST_";

        NightPostString = "POST_";

    }

    if(GetIsDay() || GetIsDawn())

    {

        SetLocalString( OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX", DayWayString);

        SetLocalString( OBJECT_SELF, "NW_GENERIC_POSTING_PREFIX", DayPostString);

    }

    else

    {

        SetLocalString( OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX", NightWayString);

        SetLocalString( OBJECT_SELF, "NW_GENERIC_POSTING_PREFIX", NightPostString);

    }



    sWay = GetLocalString( OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX" );

    sPost = GetLocalString( OBJECT_SELF, "NW_GENERIC_POSTING_PREFIX" );

    //I have now determined what the prefixs for the current walkways and postings are and will use them instead

    // of POST_ and WP_

    if( GetSpawnInCondition( NW_FLAG_STEALTH ) )

    {

        ActionUseSkill( SKILL_HIDE, OBJECT_SELF);

    }

    if( GetSpawnInCondition( NW_FLAG_SEARCH))

    {

        ActionUseSkill( SKILL_SEARCH, OBJECT_SELF);

    }

    //Test if OBJECT_SELF has waypoints to walk

    if (sWayTag == "")

    {

        sWayTag = GetLocalString( OBJECT_SELF, "ratb_WayBase");

        if (sWayTag == "")

        {

            sWayTag = GetTag( OBJECT_SELF );

        }

    }

    SetLocalString(OBJECT_SELF, "ratb_WayBase", sWayTag);

    sWayTag = sWay + sWayTag + "_01";

    object oWay1 = GetNearestObjectByTag( sWayTag);

    if( !GetIsObjectValid( oWay1 ))

    {

        oWay1 = GetObjectByTag( sWayTag );

    }

    if( GetIsObjectValid( oWay1 ) && GetSpawnInCondition( NW_FLAG_AMBIENT_ANIMATIONS ))

    {

        //turn off the ambient animations if the creature should walk way points.

        SetSpawnInCondition( NW_FLAG_AMBIENT_ANIMATIONS, FALSE);

        SetSpawnInCondition( NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS, FALSE);

    }

    if( GetIsObjectValid( oWay1))

    {

        int nNth = 1;

        int nTens;

        int nNum;

        object oNearest = GetNearestObject( OBJECT_TYPE_WAYPOINT, OBJECT_SELF, nNth);

        while (GetIsObjectValid( oNearest))

        {

           string sNearestTag = GetTag(oNearest);

           //removes the first 3 and last three characters from the waypoint's tag

           //and checks it against his own tag.  Waypoint tag format is WP_MyTag_XX.

           if( GetSubString( sNearestTag, 3, GetStringLength( sNearestTag ) - 6 ) == GetLocalString( OBJECT_SELF, "ratb_WayBase" ) )

           {

                string sTens = GetStringRight( GetTag( oNearest), 2);

                nTens = StringToInt( sTens )/10;

                nNum= StringToInt( GetStringRight( GetTag( oNearest),1));

                oNearest = OBJECT_INVALID;

           }

           else

           {

               nNth++;

               oNearest = GetNearestObject( OBJECT_TYPE_WAYPOINT, OBJECT_SELF, nNth );

           }

        }

        RunAnyCircuit(nTens, nNum, nLoop, nRun, fPause); 

        ActionWait(fPause);

        ActionDoCommand( RunAnyNextCircuit( nLoop, nRun, fPause) );

    }

    else

    {

        sWayTag = GetLocalString( OBJECT_SELF, "ratb_WayBase");

        if (sWayTag == "")

        {

            sWayTag = GetTag( OBJECT_SELF );

        }

        sWayTag = sPost + sWayTag;

        oWay1 = GetNearestObjectByTag( sWayTag);

        if( !GetIsObjectValid( oWay1))

        {

            oWay1 = GetObjectByTag(sWayTag);

        }

        if( GetIsObjectValid( oWay1))

        {

            ActionForceMoveToObject( oWay1, nRun, 1.0, 60.0);

            float fFacing = GetFacing(oWay1);

            ActionDoCommand( SetFacing( fFacing));

        }

    }

    if( GetIsObjectValid( oWay1) && GetSpawnInCondition( NW_FLAG_AMBIENT_ANIMATIONS ))

    {

        SetSpawnInCondition( NW_FLAG_AMBIENT_ANIMATIONS, FALSE );

        SetSpawnInCondition( NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS, FALSE );

    }

}

void RunAnyNextCircuit(int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0)

{

    RunAnyCircuit(0,1, nLoop, nRun, fPause);  

    ActionWait(fPause);

    ActionDoCommand( RunAnyNextCircuit( nLoop, nRun, fPause ));

}

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

//:: Run Any Circuit

//:: Copyright (c) 2001 Bioware Corp.

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

/*

    Calculates the proper path to follow along a

    predetermined set of way points

*/

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

//:: Created By: Aidan Scanlan

//:: Created On: July 10, 2001

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

//:: Modified By: Kenneth Cummins

//:: Created On: June 24, 2002

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

void RunAnyCircuit(int nTens, int nNum, int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0)

{

    // starting at a given way point, move sequentialy through incrementally

    // increasing points until there are no more valid ones.

    string sWay = GetLocalString( OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX" );

    string sWayBase = GetLocalString( OBJECT_SELF, "ratb_WayBase" );

    if (sWayBase == "") {

      sWayBase = GetTag(OBJECT_SELF);

    }

    object oTargetPoint = GetWaypointByTag ( sWay + sWayBase + "_" + IntToString ( nTens ) + IntToString ( nNum ));

    while( GetIsObjectValid( oTargetPoint ) )

    {

        ActionWait(fPause);

        ActionMoveToObject( oTargetPoint, nRun);

        nNum++;

        if (nNum > 9)

        {

            nTens++;

            nNum = 0;

        }

        oTargetPoint = GetWaypointByTag ( sWay + sWayBase + "_" + IntToString( nTens) + IntToString( nNum));

    }

    if (!nLoop)

    {

        // once there are no more waypoints available, decriment back to the last

        // valid point.

        nNum--;

        if (nNum < 0)

        {

            nTens--;

            nNum = 9;

        }

        // start the cycle again going back to point 01

        oTargetPoint = GetWaypointByTag( sWay + sWayBase + "_" + IntToString(nTens) + IntToString(nNum));

        while ( GetIsObjectValid ( oTargetPoint ) )

        {

            ActionWait ( fPause );

            ActionMoveToObject ( oTargetPoint, nRun );

            nNum--;

            if (nNum < 0)

            {

                nTens--;

                nNum = 9;

            }

            oTargetPoint = GetWaypointByTag( sWay + sWayBase + "_" + IntToString( nTens ) + IntToString( nNum ));

        }

    }

}



I just realized that I need to check if the NPC will return to WAWP after combat, of if it's going to try to go back to the unmodified WalkWayPoints. May need *another* modified script...

_________________
Ratbert #CP#
For FUN and HONOR!
Neverwinter Nexus