Hi All,
Just a quick update ... but a question first ...
QUESTION: Does anybody else have problems with waypoints? (Or is it just me?)
E.g. Does anybody have issues with creatures not following them as planned?
I am trying to ascertain if anybody else will be interested in my "code fixes" for the
WalkWayPoints function or not?
=======================================================================================
So far, I have written a script that is far smaller than the original, and currently works alongside the original code, but takes over the WalkWayPoints function. i.e. I now use my own
LBWalkWayPoints instead of the original, and my own function does work as I expected it to. That is, the creatures follow the path of the way points that I have placed down and do not wander back along the path in the wrong direction at random.
I am just adding some finishing touches to the script that make it work like the Scripted Waypoints. I need to write one or two new functions to make use of my own main script code as opposed to rely on the original official code, which appears broken in my usage of it. In my tests so far, my scripted waypoint system works, but I need to make sure some other functions used by the original scripted waypoints have my system equivilents.
As an example of change, my own system uses LBGetCurrentWaypoint, which simply uses the following:
return GetNearestObject(OBJECT_TYPE_WAYPOINT);
This is because the original system appeared overly complicated in its application in my opinion and had some code that seemed superfluous to requirements. I scanned the scripts to see if there was much calling of these other functions, but they were mainly used with the WalkWayPoints function, and so as long as I ensure these functions work in relation to my own version, all should be good. Furthermore, in the event that another area of code should make reference to the original cod from somewhere, well I have not atered it or changed the include and so it will work as originally intended anyway. My own version of the WalkWayPoints function (and accompanying functions) all still make reference to the original const ints (E.g. const int NW_WALK_FLAG_CONSTANT = 0x00000002;) where I have felt they may still be useful, but I have circumvented other areas of the code, like that which makes a "controller". (Does anybody recognise any use of this part?)
For those interested, I did encounter some issues with functions NOT returning waypoint objects, which may have explained why a "controller" was introduced, but I simply changed the functions to return a string (tag of the object) and used that instead. In practice (so far), my own system seems more reliable for less code! (Maybe I am missing something?)
Below is a copy of my first function that starts the whole process (with comment and debug still intact), which shows how I am approaching the code.
Cheers,
Lance.
//////////////////////////////////////////////////////////////////////////////////////
// LBWalkWayPoints starts the creatures walking habits for time of day. (DAY OR NIGHT)
// iForceResume will force a WALKER to restart WALKING.
//////////////////////////////////////////////////////////////////////////////////////
void LBWalkWayPoints(int iForceResume=FALSE, string Source = "");
void LBWalkWayPoints(int iForceResume=FALSE, string Source = "")
{
SendMessageToPC(GetFirstPC(), " SOURCE >>> " + Source);
// REASONS WALK WAYPOINTS CANNOT BE DONE
object oNearestEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY);
if(oNearestEnemy != OBJECT_INVALID && GetObjectSeen(oNearestEnemy) == TRUE){return;}
if(GetIsFighting(OBJECT_SELF) || IsInConversation(OBJECT_SELF)){return;}
if(GetCurrentAction(OBJECT_SELF) != ACTION_INVALID && iForceResume == FALSE){return;}
if(iForceResume == TRUE){LBSetWalkCondition(NW_WALK_FLAG_PAUSED, FALSE, OBJECT_SELF);}
if(LBGetWalkCondition(NW_WALK_FLAG_PAUSED) == TRUE){return;}
// ELSE MOVE CREATURE TO NEXT WAYPOINT
ClearAllActions(TRUE);
/////////////////////////////////////////////////////////////////////////////////////////////
// INITIALIZE WALKWAYPOINT CONTROLLER FOR THIS CREATURE (START THEM IN STEALTH OR SEARCH MODE)
/////////////////////////////////////////////////////////////////////////////////////////////
if (GetLocalInt(OBJECT_SELF, "WP_SETUP") == 0)
{
SetLocalInt(OBJECT_SELF, "WP_SETUP", 1);
// START WITH APPROPRIATE SKILLS (ONLY HAPPENS ON START OR POSSIBLE RESET)
if(GetSpawnInCondition(NW_FLAG_STEALTH)){SetActionMode(OBJECT_SELF, ACTION_MODE_STEALTH, TRUE);}
if(GetSpawnInCondition(NW_FLAG_SEARCH)){SetActionMode(OBJECT_SELF,ACTION_MODE_DETECT,TRUE);}
}
/////////////////////////////////////////////////////////////////////////////////////////////
// DETERMINE WAYPOINT TO USE FOR POST OR TO FOLLOW (USE BaseTagToFollow TO OVERRIDE OWN TAGE DEFAULT)
/////////////////////////////////////////////////////////////////////////////////////////////
string sTagSelf = GetTag(OBJECT_SELF);
string sWPTag = GetLocalString(OBJECT_SELF, "WP_Tag");
if(sWPTag == ""){sWPTag = sTagSelf;}
SetLocalString(OBJECT_SELF, "WP_Tag", sWPTag);
// DETERMINE IF A GUARD - STAND AT THEIR POST
object oPost = GetWaypointByTag("POST_" + sWPTag);
if (oPost != OBJECT_INVALID){ActionMoveToObject(oPost); ActionDoCommand(SetFacing(GetFacing(oPost))); return;}
// DETERMINE IF A WALKER - DAY OR NIGHT - MOVE TO THEIR NEXT WAYPOINT (ACCORDING TO TIME)
string sPrefix = "WP_"; if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && !GetIsDay()){sPrefix = "WN_";}
object oWalker = GetWaypointByTag(sPrefix + sWPTag + "_01");
SendMessageToPC(GetFirstPC(), GetTag(OBJECT_SELF) + " STILL FIRING >>> ");
if(oWalker != OBJECT_INVALID)
{
//object oNextWayPoint = LBGetNextWalkWayPoint(OBJECT_SELF);
object oNextWayPoint = GetWaypointByTag(LBGetNextWalkWayPointTag(OBJECT_SELF));
SendMessageToPC(GetFirstPC(), GetTag(OBJECT_SELF) + " MOVING TOWARDS (*) >>> " + GetTag(oNextWayPoint));
LBSetWalkCondition(NW_WALK_FLAG_CONSTANT, TRUE, OBJECT_SELF);
ActionForceMoveToObject(oNextWayPoint);
ActionDoCommand(LBWalkWayPoints(FALSE, "WALKQ"));
}
}
Modifié par Lance Botelle, 22 octobre 2012 - 12:41 .