Neverwinter Nights Community Site: www.neverwinternights.info
Home Players Dungeon Masters Module Builders Custom Content Makers Forum Get NWN
Search...


Overview of Bioware's Walk Waypoint System
By: Axe Murderer [sourcex: User's Guide and Tutorial]

Bioware has included in the game a system for making NPCs that will stand posts or walk patrol routes without any scripting required. It is known as the Walk Waypoint System and it is enabled by default for every NPC you create and add into your module. It works off of a set of waypoints that are related to the NPC using the NPC's TAG. You can set up a patrol route using waypoints, set the TAGs of the waypoints to associate them with a particular NPC TAG, and the NPC will automatically walk the route when he spawns in. Their system has evolved over the years and now allows for a daytime route and a separate route at night. You can also set up a post instead of a route so your NPCs will return to the post whenever they are not busy doing something else, or after they are involved in some combat and survive it. There can be a daytime post and another for the night. You can have a day route and night post, a day post and night route, a day post and night post, or a day route and night route. If you have multiple NPCs with the same TAG, they will all walk the same set of waypoints or stand the same posts.

To set up a daytime post for your NPC all you have to do is paint a waypoint in your area where you want him to stand. Then edit the waypoint properties and set the TAG to "POST_<NPC's TAG>". So if you have an NPC with the TAG "Guard" you make a waypoint with the TAG "POST_Guard" and your NPC will always go stand there when he isn't busy. Additionally, you can edit the waypoint's properties and set a variable of type integer on it using the name "X2_L_WAYPOINT_SETFACING" with a value of 1, to force the NPC to always face the direct the waypoint is pointing while he is at his post. For nighttime, you do the exact same thing except you set the waypoint TAG to "NIGHT_<NPC's TAG>" instead. For our "Guard" this would be "NIGHT_Guard". Now when night rolls around our guard will automatically move to his night post -- well not quite. In the NPC's OnSpawn script ("nw_c2_default9" by default) you must also flag him as someone who performs DAY_NIGHT_POSTING by enabling a spawn-in condition (see the nw_c2_default9 script for instructions how to do that). If you forget to set the DAY_NIGHT_POSTING condition for your NPC, he will ignore all the night posts and routes and always use the daytime ones regardless of the time of day.

To get patrol routes, you paint down the route using a set of waypoints. Instead of using POST_ for your TAG, you use "WP_<NPC's Tag>_XX" where XX is a two digit number that starts at 01 and goes up to 99 (or whatever the last one turns out to be). If we want our "Guard" to walk a route of 3 waypoints, we paint them down then set their TAGs to "WP_Guard_01", "WP_Guard_02", and "WP_Guard_03". Now when our NPC spawns in, he will move to whichever of the three waypoints is closest to him and start walking the route in the progression 01, 02, 03, 02, 01, 02, ... forever whenever he isn't busy. A night route is defined in a likewise manner except the waypoint TAGs use "WN_<NPC's TAG>_XX" instead. If the NPC's DAY_NIGHT_POSTING condition has been set in his OnSpawn script, he will walk the WP waypoints during the day and the WN ones at night. If you make a route and a post both, either daytime or nighttime, the NPC will ignore the post and only recognize the route waypoints -- although you can have day route and night post, or day post and night route. He will treat day/night waypoints separately.

You can place his daytime waypoints in a different area from his nighttime ones and he will change areas. Also, your patrol routes can span across areas if you like. To make this happen, there is a module switch called ENABLE_CROSSAREA_WALKWAYPOINTS that must be enabled (set to TRUE) in the module's OnModuleLoad script (by default called "x2_mod_def_load"). Look in the "x2_mod_def_load" script for instructions how to enable it. If you fail to set this module switch, the NPC will only look in the area he spawns into for both his daytime and nighttime waypoints, and he will ignore all waypoints outside the area he spawns into. Otherwise, he will consider waypoints from all other areas. The NPC must be able to find a way to get to the next area, so there must be a transition available between the areas that the NPC can find and use if you span areas in your patrol &/or daytime-nighttime waypoints. If you connect the areas using a locked door, for instance, you must make sure the NPC has the ability to unlock the door. Currently the only transitions that work are doors and area transition triggers.

Every post or patrol waypoint can make use of the X2_L_WAYPOINT_SETFACING variable to force the NPC face the waypoint direction when he arrives there. By default, the NPC will pause for 1.0 second at every waypoint on a patrol route before moving on to the next one. If the waypoint has the SETFACING flag on it, he will arrive, change facing, then perform the 1.0 second pause, and finally move to the next waypoint (unless it is a post naturally).

Bioware's Walk Waypoint system is defined in the include library called "x0_i0_walkway". In there are a bunch of useful functions related to the system. Like for finding an NPC's Walk Waypoints waypoints, which one is closest to him, how many he has on his route, etc. The function WalkWayPoints defined in that library can be called to force your NPC to return to his post or patrol at any time, and it has a couple of parameters you can use to customize it a little bit. You can tell him to run or walk, and you can change the 1.0 second delay he makes at each waypoint. Bioware's default scripts are set up to call the WalkWayPoints function in the NPC's OnSpawn, OnHeartbeat, and OnPerception events. It is also called at the end of conversations in their Normal & Abort events and whenever the DetermineCombatRound function is called from any script.

Well, that's it in a nutshell -- the Bioware default Walk Waypoint System for NPC posts and patrols.

- Back to the start...