Games Support Forums BioWare Info My Account Login Community Sign Up Store
Neverwinter Nights 2 Forums

NWN2: Builders - NWN2 Scripting

New Topic    Post Reply

Go to Page ( 1 , 2 , 3 , 4 , 5 , 6 Next )

    Add this To My Topics

   Go To Bottom

Author Sticky: Scripted Waypoints
Charles Mead
Gameplay Scripter


Joined: 17 Feb 2005
Posted: Monday, 06 November 2006 06:04PM
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_<creature’s tag>_##”. The NPC will begin the journey at waypoint 1 and continue traveling sequentially to waypoint n, and then back again in reverse.

Basic Useage:
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_<creature’s tag>”. 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:

Example 1.
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().
Code:

View Post/Code in separate window


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.


Example 2.
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:
When the NPC reaches waypoint 1, he will sit down for a few seconds, and then randomly travel to one of the other waypoints in the set other than the first.
When the NPC reaches waypoint 2, he will play a “get low” animation, and then proceed to waypoint 1.
When the NPC reaches waypoint 3, he will simply head back to waypoint 1.
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.
Code:

View Post/Code in separate window


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.


*Advanced Usage*
How to have two or more creatures with different tags walk the same set of 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 change the set of waypoints a creature walks dynamically:
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:
SetWWPController(“bear”);


How to pause/restart a creature walking waypoints.
To stop a creature from walking waypoints, use:
SetWalkCondition(NW_WALK_FLAG_PAUSED, TRUE);

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:
SetWalkCondition(NW_WALK_FLAG_PAUSED, TRUE);

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:
Code:

View Post/Code in separate window



Where can I learn more about other thing I can do?
Many useful functions are listed in the prototypes of the include file “ginc_wp”.
  Profile: Charles Mead   Send Message To: Charles Mead
Thagon
Game Owner
Profile: ThagonNWN
NWN: SoU
NWN: HotU
SW: KotOR PC
NWN 2
NWN 2: MotB
NWN 2: SoZ
Mass Effect


Joined: 18 Jun 2002
From: Toronto, ON
Posted: Monday, 06 November 2006 06:20PM
Great info! Very useful stuff here. Many thanks.
  Profile: Thagon   Send Message To: Thagon
johnbgardner
Game Owner
Profile: johnbgardnerNWN
SW: KotOR PC
NWN 2


Joined: 19 Jul 2002
Posted: Wednesday, 08 November 2006 09:12AM
Are you sure the flag to restart walking waypoints is TRUE? Logically it should be set to FALSE, i.e. the caller is NOT pausing.
  Profile: johnbgardner   Send Message To: johnbgardner
tuerceviolines
Game Owner
Profile: tuerceviolinesNWN
NWN: SoU
NWN: HotU
NWN 2
NWN 2: MotB


Joined: 10 Nov 2005
Posted: Wednesday, 08 November 2006 04:34PM
Great info indeed!
  Profile: tuerceviolines   Send Message To: tuerceviolines
Charles Mead
Gameplay Scripter


Joined: 17 Feb 2005
Posted: Wednesday, 08 November 2006 05:56PM
Quite right johnbgardner. That is a typo.
It should read:

To Restart a creature walking waypoints, use:
SetWalkCondition(NW_WALK_FLAG_PAUSED, FALSE);
  Profile: Charles Mead   Send Message To: Charles Mead
Horathh
Game Owner
Profile: HorathhNWN
NWN: SoU
NWN: HotU
Jade Empire
NWN 2


Joined: 19 Jul 2002
From: Los Angeles, California.
Posted: Thursday, 09 November 2006 01:53AM
I wonder if:

A.NPC activities script will just flat out work in NWN2 or
B.The author of that script is still around and will rewrite it for NWN2.

His way waypoint code was far easier to execute then what you have asked me to do here.
Since I am no script writer by any means.

Digiartst
  Profile: Horathh   Send Message To: Horathh
Grinning Fool
Moderator

Joined: 26 Nov 2003
From: Khalidine
Posted: Friday, 10 November 2006 05:49PM
This is a great setup, thanks for the info.
_________________
NWN2 Creature/NPC Wizard, Toolset Enhancements, and More
NWN2 Chat
  Profile: Grinning Fool   Send Message To: Grinning Fool
Charles Mead
Gameplay Scripter


Joined: 17 Feb 2005
Posted: Friday, 10 November 2006 06:46PM
Deva Winblood's NPC Activities was actually a big inspiration for me, and I used that system rather extensively for my own NWN1 modules.

Scripted Waypoints isn't designed to be easier to use than NPC Activities or to replace it - it's designed to be more flexible.
  Profile: Charles Mead   Send Message To: Charles Mead
wanthipha
Game Owner
Profile: wanthiphaNWN
NWN: SoU
NWN: HotU
NWN 2


Joined: 27 Jun 2002
Posted: Friday, 10 November 2006 11:44PM
Did FaceAndPause() break with this last patch? also why do NPC's continue to use the WP_ at night when there are WN_ along with NIGHT_ waypoints.

Anyone else having these problems?
  Profile: wanthipha   Send Message To: wanthipha
Kastion2000
Game Owner
Profile: Kastion2000NWN
NWN: SoU
NWN: HotU
NWN 2
NWN 2: MotB


Joined: 23 Jul 2005
Posted: Saturday, 11 November 2006 02:30PM
Is it possible to get this stickied so it's easy to find for old and new scripters alike?
  Profile: Kastion2000   Send Message To: Kastion2000
rtrifts
Game Owner
Profile: rtriftsNWN
NWN: SoU
NWN: HotU
SW: KotOR Xbox
SW: KotOR PC
Jade Empire
Jade Empire:SE
NWN 2
NWN 2: MotB
NWN 2: SoZ
Mass Effect
Mass Effect PC
Sonic DS


Joined: 01 Apr 2002
From: Toronto, ON
Posted: Saturday, 11 November 2006 11:20PM
Quote: Posted 11/09/06 01:53 (GMT) by Horathh

I wonder if:

A.NPC activities script will just flat out work in NWN2 or
B.The author of that script is still around and will rewrite it for NWN2.

Deva is lead scripter at DLA. He's still around, thank-you-very-much.

I imagine he'll get a chance to revisit this - or something like it - in the fullness of time.
_________________
.Robert (Steel_Wind)
DLA/roXidy Games Inc.
  Profile: rtrifts   Send Message To: rtrifts
futurewavecs
Game Owner
Profile: futurewavecsNWN
NWN: SoU
NWN: HotU
NWN 2
NWN 2: MotB
NWN 2: SoZ
Mass Effect PC


Joined: 19 Jun 2002
From: Denver, CO area
Posted: Saturday, 11 November 2006 11:34PM
I am the author of NPC ACTIVITIES and I was waiting to see how Scripted Waypoints actually looked. I knew it had been inspired partially by my script. So, I was hoping NPC ACTIVITIES would not be necessary.

Scripted Waypoints appears to be a step forward from WalkWayPoints(). Had it existed when I started making stuff for NPC ACTIVITIES, it is very likely I never would have made the script. It is good stuff.

With that said it looks as though making NPC ACTIVITIES 7.0 for NWN2 is feasible. A big part of my target audience for NPC ACTIVITIES was the non-scripter.

It appears this audience will still need my scripts.

In addition, NPC ACTIVITIES could do these same things in addition so truly was just as flexible. It was a bit cryptic though. It also had a very large manual... So, it may have been missed.

With that said...
In NPC ACTIVITIES you could do @<scriptname> to execute a script upon reaching a waypoint. You could also do @<scriptname>. @<scriptname>. @<scriptname> to execute 3 different scripts.

So, I think it could do this. I may have missed something as is I can say Scripted Waypoints is a big step forward.

Unfortunately, I am currently the Lead Technical Designer for DLA and I am not sure how much time I will have to make NPC ACTIVITIES 7.0 for NWN2. I will try to squeeze it through the cracks of my time somewhere. I should be able to complete such a task over a weekend soon I would think.
_________________
DLA - Technical Designer
NPC ACTIVITIES Harvest of Souls [Ron Paul 2008!!]

Edited By futurewavecs on 11/11/06 23:57

  Profile: futurewavecs   Send Message To: futurewavecs
futurewavecs
Game Owner
Profile: futurewavecsNWN
NWN: SoU
NWN: HotU
NWN 2
NWN 2: MotB
NWN 2: SoZ
Mass Effect PC


Joined: 19 Jun 2002
From: Denver, CO area
Posted: Saturday, 11 November 2006 11:52PM
Also, Charles... very cool to see you at Obsidian. I remember chatting with you in the past.
_________________
DLA - Technical Designer
NPC ACTIVITIES Harvest of Souls [Ron Paul 2008!!]

Edited By futurewavecs on 11/11/06 23:58

  Profile: futurewavecs   Send Message To: futurewavecs
futurewavecs
Game Owner
Profile: futurewavecsNWN
NWN: SoU
NWN: HotU
NWN 2
NWN 2: MotB
NWN 2: SoZ
Mass Effect PC


Joined: 19 Jun 2002
From: Denver, CO area
Posted: Saturday, 11 November 2006 11:59PM
Quote: Posted 11/09/06 01:53 (GMT) by Horathh

A.NPC activities script will just flat out work in NWN2 or

I haven't tried it. It might work.
_________________
DLA - Technical Designer
NPC ACTIVITIES Harvest of Souls [Ron Paul 2008!!]
  Profile: futurewavecs   Send Message To: futurewavecs
Charles Mead
Gameplay Scripter


Joined: 17 Feb 2005
Posted: Sunday, 12 November 2006 01:07AM
Hey there Deva, glad to see you are still in the NWN Community! I still owe you one for the hotfix you made for me for NPC Activities 4.0 back in the day!
  Profile: Charles Mead   Send Message To: Charles Mead

Go to Page ( 1 , 2 , 3 , 4 , 5 , 6 Next )

New Topic    Post Reply

What do these icons mean?
Where can I learn how to use the forums?

Jump To:

Search Forums | Forums FAQ | Forum Archives

 

 

  Visit the Official Site | Technical Support
Neverwinter Nights 2 Official Support
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

6,251,297 Users
170 Online
11 Logged In

9,046,484 posts in forums

Newest Forum Topics:
1. These forums are now closed (NWN 1: Scripting)

2. These forums are now closed (NWN2: Guilds and Registry)

3. These forums are now closed (BioWare News Discussion)

4. Can you level items? (NWN 1: Scripting)

5. Thank you! (NWN 1: Scripting)


Current time is: (set time)
Fri, 03 September 2010 12:58AM