NWN2 Scripted Waypoints
|Resources - Technical Documentation|
|Thursday, 01 April 2010 00:00|
Here's some info on a new feature called Scripted Waypoints.
Scripted waypoints builds on the current waypoints system by making the arrival at each waypoint call a script. There are no special requirements for preparing this – it will work with any NPC using the regular default scripts and any new or previously placed set of walkway points.
Quick refresher of the standard waypoint system:
Creatures will automatically walk along a sequence of waypoints that are tagged according to the following convention: “WP__##”. The NPC will begin the journey at waypoint 1 and continue traveling sequentially to waypoint n, and then back again in reverse.
In the new “scripted waypoint” system, whenever a creature reaches a waypoint, it calls a script that is named very similarly to the tag used for the waypoints, like this: “wp_”. Notice there is just one script for the entire set of waypoints. If the script does not exist, then nothing additional happens and the NPC simply walks back and forth through the set of waypoints.
Below are some examples of “scripted waypoints” scripts:
This script tells the NPC to stop at every waypoint and face in the direction the waypoint is facing and pause 1 second before continuing to the next waypoint.
Notice the inclusion of “ginc_wp” which has a number of helpful functions such as FaceAndPause().
Note how we call GetCurrentWaypoint() which returns the waypoint we have just reached. This will typically always be the first thing called in a “scripted waypoints” script.
This is a more complex script that completely overrides the normal waypoint behavior and demonstrates how each waypoint can be individually scripted. It accomplishes the following:
If there are more than 3 waypoints in the set, then when the NPC reaches one of those he will behave in the default way.
Note in this example the use of SetNextWaypoint(). The “next” waypoint is the one the NPC is enroute to. SetNextWaypoint() allows us to override this and redirect the NPC to an alternate waypoint.
The script template “wp_tag” is available in the script templates directory in source safe. Simply copy and paste it with the proper script name, replacing the word “tag” with the tag of the creature that will be walking waypoints.
How to have two or more creatures walk the same waypoints:
To override the initial waypoint set a creature uses, simply set a local string variable “WP_TAG” on the creature with the value of the desired waypoint set to use. So, if you have a bear waypoint set for a creature tagged “bear”, you could get a chicken to also walk these waypoints by setting the chicken's local variable WP_TAG to “bear”.
Note that this variable is only checked when the creature is first spawned, so changing this value via script will have no effect.
How to dynamically change the waypoint set a creature walks:
You can change the set of waypoints a creature walks at any time via script using this function: object SetWWPController(string sWalkWayPointsTag, object oCreature=OBJECT_SELF);
So from the previous example, we could have our chicken walk the bear’s waypoints by calling this function in script:
How to pause/restart a creature walking waypoints:
To stop a creature from walking waypoints, use:
You may also want to clear all actions, otherwise, the creature will still complete his pending actions which will take him to whatever the next waypoint is.
To Restart a creature walking waypoints, use:
The creature should get started on his next heartbeat.
How to create a road network:
The basic outline for a script like this is available in the script template “wp_road_walker” and reads as follows:
Where can I learn more about other things I can do?
Many useful functions are listed in the prototypes of the include file “ginc_wp”.
|Last Updated on Wednesday, 14 July 2010 08:47|