I've found the built in WalkWayPoints()
function lacking, so I edited some code and wrote some new code and heres
what I came up with.
The new function, ATS_WalkWayPoints() extends the original code. Used with
no parameters, it works just like WalkWayPoints(). However, with parameters,
it will allow the NPC to walk either back-and-forth (1,2,3,4,3...) or
circular (1,2,3,4,1,2,3,4...), or randomly among waypoints.
Not only that, but by creating a script with the same name as a waypoint,
that script will be executed when the NPC reaches that waypoint.
So, if you have waypoint WP_GUARD_04, create a script called "wp_guard_04",
and when the guard hits waypoint 4, the script will be run for the guard
(note that in that waypoint script, the commands must all be actions... see
my notes in the script).
This, I think, is really quite handy. You could make a town drunk that
wanders randomly among waypoints, taking a drink at some, talking to himself
at others. Or a nurse that wanders among patients, casting spells. Or a
patrolling guard, reporting "All Clear" at a certain waypoint. Or a hundred
other things.
Hope you like it and find it useful!
Adam
NWScript:
void RunCircuit2(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, int nWalkType = 1);
void WalkWayPoints2(int nRun = FALSE, float fPause = 1.0, int nWalkType = 1);
void RunNextCircuit2(int nRun = FALSE, float fPause = 1.0, int nWalkType = 1);
/
void WalkWayPoints2(int nRun = FALSE, float fPause = 1.0, int nWalkType = 1)
{
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);
}
string sWayTag = GetTag( OBJECT_SELF );
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 ) == GetTag( OBJECT_SELF ) )
{
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);
}
}
RunCircuit2(nTens, nNum, nRun, fPause, nWalkType); /
void RunCircuit2(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, int nWalkType = 1)
{
string sWay = GetLocalString(OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX");
object oTargetPoint;
if ( nWalkType >= 3 )
{
int nRand = Random(nWalkType) + 1;
nTens = nRand/10;
nNum= nRand - (nTens * 10);
oTargetPoint = GetWaypointByTag(sWay + GetTag(OBJECT_SELF) + "_" + IntToString(nTens) +IntToString(nNum));
ActionMoveToObject(oTargetPoint, nRun);
ActionWait(fPause);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
return;
}
oTargetPoint = GetWaypointByTag(sWay + GetTag(OBJECT_SELF) + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionMoveToObject(oTargetPoint, nRun);
ActionWait(fPause);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
oTargetPoint = GetWaypointByTag(sWay + GetTag(OBJECT_SELF) + "_" + IntToString(nTens) +IntToString(nNum));
}
if ( nWalkType == 2 )
return;
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
oTargetPoint = GetWaypointByTag(sWay + GetTag(OBJECT_SELF) + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionMoveToObject(oTargetPoint, nRun);
ActionWait(fPause);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
oTargetPoint = GetWaypointByTag(sWay + GetTag(OBJECT_SELF) + "_" + IntToString(nTens) +IntToString(nNum));
}
}
|