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 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 );
void WalkAnyWayPoints( string sWayTag = "", int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0 )
{
ClearAllActions();
string DayWayString;
string NightWayString;
string DayPostString;
string NightPostString;
string sWay;
string sPost;
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" );
if( GetSpawnInCondition( NW_FLAG_STEALTH ) )
{
ActionUseSkill( SKILL_HIDE, OBJECT_SELF);
}
if( GetSpawnInCondition( NW_FLAG_SEARCH))
{
ActionUseSkill( SKILL_SEARCH, OBJECT_SELF);
}
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 ))
{
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);
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 ));
}
void RunAnyCircuit(int nTens, int nNum, int nLoop = FALSE, int nRun = FALSE, float fPause = 1.0)
{
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)
{
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
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
|