Name:Improved Waypoint Walking Code
What it does: Extends the basic waypoint walking code, by specifying
additional parameters you can change how people walk waypoints and even what
waypoints they walk. The default behaviour is exactly the same as Bioware's
WalkWayPoints, but with this you can specify the inner part of the series of
waypoints to walk. The function is documented so if you load it up in the
script editor and type the name IWalkWayPoints into the name filter the
documentation of how to use it will appear down the bottom of the editor.
Here is that documentation
Causes the calling object to walk a set of way points that are in the format
WP_somestring_XX where somestring is the name of the set of WayPoints and XX
is a number from 01 - 99. If there is a script with the same name as the
waypoint it will be executed as the NPC gets to the waypoint.
Parameters:
- sSeries: the name of the series of way points. Defaults to the calling
object's tag
- nTimes: the number of times to walk the set of way points. One traversal
is defined as going from one end of a series to the other. So to go back and
forth once requires you to go along the set twice. For circular way points
it is the number of times to go around and come to the start point again.
- nTraversal:The type of traversal to use:
WAYPOINT_STANDARD, WAYPOINT_ASCENDING - Go up through the way points
(01,02,03,etc)
WAYPOINT_DESCENDING - Go down through the way points (03,02,01)
WAYPOINT_CIRCULAR - Go to each of the waypoints in turn ending at the first
one. (01,02,03,01)
void IWalkWayPoints(int nRun = FALSE, float fPause = 1.0, string sSeries =
"", int nTimes = 0, int nTraversal = 1);
Notes on use:
To use this, save the script as whatever you like (I use improved_waypt) and
then #include "IMPROVED_WAYPT" in the scripts you want to use it.
For default behaviour just use IWalkWayPoints(); if you wanted someone to go
to work using this code and you had some waypoints set up going from 01 at
the NPC's home and 12 at their work, you would use IWalkWayPoints(FALSE,
0.1, GetTag(OBJECT_SELF) + "_work", 1, WAYPOINT_ASCENDING); At the end of
the day if you wanted the NPC to walk home you could use
IWalkWayPoints(FALSE, 0.1, GetTag(OBJECT_SELF) + "_work", 1,
WAYPOINT_DESCENDING); and the NPC will walk back down the series.
NWScript:
int INW_FLAG_SHOUT_ATTACK_MY_TARGET = 0x00000002;
int INW_FLAG_STEALTH = 0x00000004;
int INW_FLAG_SEARCH = 0x00000008;
int INW_FLAG_ESCAPE_RETURN = 0x00000020;
int INW_FLAG_TELEPORT_LEAVE = 0x00000100;
int INW_FLAG_AMBIENT_ANIMATIONS = 0x00080000;
int INW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS = 0x00200000;
int INW_FLAG_DAY_NIGHT_POSTING = 0x00400000;
int WAYPOINT_STANDARD = 1;
int WAYPOINT_ASCENDING = 2;
int WAYPOINT_DESCENDING = 3;
int WAYPOINT_CIRCULAR = 4;
void IRunCircuit(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void IRunCircuitD(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void IRunCircuitC(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void IWalkWayPoints(int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0, int nTraversal = 1);
void IRunNextCircuit(int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void IRunNextCircuitD(int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void IRunNextCircuitC(int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0);
void ISetSpawnInCondition(int nCondition, int bValid = TRUE);
int IGetSpawnInCondition(int nCondition);
void ISetSpawnInLocals(int nCondition);
void ISetSpawnInCondition(int nCondition, int bValid = TRUE)
{
int nPlot = GetLocalInt(OBJECT_SELF, "NW_GENERIC_MASTER");
if(bValid == TRUE)
{
nPlot = nPlot | nCondition;
ISetSpawnInLocals(nCondition);
SetLocalInt(OBJECT_SELF, "NW_GENERIC_MASTER", nPlot);
}
else if (bValid == FALSE)
{
nPlot = nPlot & ~nCondition;
SetLocalInt(OBJECT_SELF, "NW_GENERIC_MASTER", nPlot);
}
}
int IGetSpawnInCondition(int nCondition)
{
int nPlot = GetLocalInt(OBJECT_SELF, "NW_GENERIC_MASTER");
if(nPlot & nCondition)
{
return TRUE;
}
return FALSE;
}
void ISetSpawnInLocals(int nCondition)
{
if(nCondition == INW_FLAG_SHOUT_ATTACK_MY_TARGET)
{
SetListenPattern(OBJECT_SELF, "NW_ATTACK_MY_TARGET", 5);
}
else if(nCondition == INW_FLAG_ESCAPE_RETURN)
{
SetLocalLocation(OBJECT_SELF, "NW_GENERIC_START_POINT", GetLocation(OBJECT_SELF));
}
else if(nCondition == INW_FLAG_TELEPORT_LEAVE)
{
SetLocalLocation(OBJECT_SELF, "NW_GENERIC_START_POINT", GetLocation(OBJECT_SELF));
}
}
/
void IWalkWayPoints(int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0, int nTraversal = 1)
{
string DayWayString;
string NightWayString;
string DayPostString;
string NightPostString;
string sWay;
string sPost;
string sWpSeries;
if (sSeries == "")
{
sWpSeries = GetTag(OBJECT_SELF);
}
else
{
sWpSeries = sSeries;
}
if(IGetSpawnInCondition(INW_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(IGetSpawnInCondition(INW_FLAG_STEALTH))
{
ActionUseSkill(SKILL_HIDE, OBJECT_SELF);
}
if(IGetSpawnInCondition(INW_FLAG_SEARCH))
{
ActionUseSkill(SKILL_SEARCH, OBJECT_SELF);
}
string sWayTag = sWpSeries;
sWayTag = sWay + sWayTag + "_01";
object oWay1 = GetNearestObjectByTag(sWayTag);
if(!GetIsObjectValid(oWay1))
{
oWay1 = GetObjectByTag(sWayTag);
}
if(GetIsObjectValid(oWay1) && IGetSpawnInCondition(INW_FLAG_AMBIENT_ANIMATIONS))
{
ActionDoCommand(ISetSpawnInCondition(INW_FLAG_AMBIENT_ANIMATIONS, FALSE));
ActionDoCommand(ISetSpawnInCondition(INW_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 ) == sWpSeries )
{
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);
}
}
switch (nTraversal)
{
case 1:
IRunCircuit(nTens, nNum, nRun, fPause, sWpSeries, nTimes); /
void IRunCircuit(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0)
{
PrintString(GetTag(OBJECT_SELF) + " Run Circuit");
if (sSeries == "")
{
sSeries = GetTag(OBJECT_SELF);
}
string sWay = GetLocalString(OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX");
object oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
if (nTimes == 1)
{
return;
}
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
}
void IRunCircuitC(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0)
{
PrintString(GetTag(OBJECT_SELF) + " IRunCircuitC");
if (sSeries == "")
{
sSeries = GetTag(OBJECT_SELF);
}
string sWay = GetLocalString(OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX");
object oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
nTens = 0;
nNum = 1;
while(!GetIsObjectValid(oTargetPoint))
{
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
}
if (nTimes == 1)
{
return;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
nTens = 0;
nNum = 1;
while(!GetIsObjectValid(oTargetPoint))
{
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum++;
if (nNum > 9)
{
nTens++;
nNum = 0;
}
}
}
void IRunCircuitD(int nTens, int nNum, int nRun = FALSE, float fPause = 1.0, string sSeries = "", int nTimes = 0)
{
PrintString(GetTag(OBJECT_SELF) + " IRunCircuitD");
if (sSeries == "")
{
sSeries = GetTag(OBJECT_SELF);
}
string sWay = GetLocalString(OBJECT_SELF, "NW_GENERIC_WALKWAYS_PREFIX");
object oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
nNum--;
if (nNum < 0)
{
nTens--;
nNum = 9;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
if (nTimes == 1)
{
return;
}
nNum++;
if (nTens < 0)
{
nTens = 0;
nNum = 1;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
while(GetIsObjectValid(oTargetPoint))
{
ActionWait(fPause);
ActionMoveToObject(oTargetPoint, nRun);
ExecuteScript(GetStringLowerCase(GetTag(oTargetPoint)), OBJECT_SELF);
if (nNum > 9)
{
nTens++;
nNum = 0;
}
oTargetPoint = GetWaypointByTag(sWay + sSeries + "_" + IntToString(nTens) +IntToString(nNum));
}
nNum--;
if (nNum < 0)
{
nNum = 9;
nTens--;
}
SetLocalInt(OBJECT_SELF, "CurWPSeriesMaxTens", nTens);
SetLocalInt(OBJECT_SELF, "CurWPSeriesMaxNum", nNum);
}
- winternight
|