Aller au contenu

Photo

Scripted Waypoints: FYI


  • Veuillez vous connecter pour répondre
24 réponses à ce sujet

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I just came across scripted waypoints.  Apparently if you name a certain script according to a certain naming convention, while an NPC is walking waypoints, at each waypoint, a script can be run.  This seems very useful for lots of things.  Just wanted to get the info out there in case anyone else is unaware of it.

Here's a link that describes it further:

Link...


If anyone wants to comment about applications of this system, tricks, tips, warnings, known bugs, all comments are welcome.

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
There is a Sticky about this here: http://social.biowar...4/index/3298471

Comments and such still welcomed here.

#3
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I've been playing with it and found, to my dismay, that the function PlayCustomAnimation() does not work well with the scripted waypoint system. I suspect this is because PlayCustomAnimation() does not go in the action cue. I tried to make a wrapper function labled as an action but that didn't seem to work.

#4
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I suspect you need to a bit more, like pausing the walkwaypoints and then setting the PlayCustomAnimation on a delay.

If it's not compiling, it might have something to do with the switch/case grammar. Post your script so we can look at it.

#5
The Fred

The Fred
  • Members
  • 2 516 messages
The waypoints stuff is kinda legacy code anyway, left over from pre-expansion NWN1. I'd not be surprised if it didn't gel with things. Like a lot of that code, it still exists and still works, but has been largely forgotten about and sometimes causes odd issues if you do try and use it.

#6
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

Lugaid of the Red Stripes wrote...

I suspect you need to a bit more, like pausing the walkwaypoints and then setting the PlayCustomAnimation on a delay.

If it's not compiling, it might have something to do with the switch/case grammar. Post your script so we can look at it.


Here's the script:


//Plays a custom animation at each waypoint determined by the local string
//sAnimation.
#include "ginc_wp"
#include "x0_i0_walkway"
void main()
{
object oSelf=OBJECT_SELF;
int nWPT = GetCurrentWaypoint();
FaceAndPause(nWPT,0.5f);
PlayCustomAnimation(oSelf,GetLocalString(oSelf,"sAnimation"),1,1.0);
}

Modifié par M. Rieder, 31 mai 2011 - 11:16 .


#7
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
The NPC starts to do the animation, but gets interrupted when she starts back for the next WPT. I need to figure out how to delay the movement to the next WPT until the animation finishes.

#8
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
I got it working. I just increased the duration of the pause to 3.0 in the function FaceAndPause().

#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Much to my chagrin, I just noticed that the most prominent sticky in this forum is, yes, you guessed it, walkwaypoints and scripted waypoints repost. Failed that spot check...

#10
Dann-J

Dann-J
  • Members
  • 3 161 messages
I've been playing about with scripted waypoints as well. They're great for randomising NPC walking around towns or merchant stalls, rather than having everyone just walk back and forth along the same path. I also randomise the pause time at each waypoint, just so everyone doesn't up and walk about in synch, like a big game of Musical Chairs.

The most useful feature I've found is the ability to override the NPCs tag so that everyone can run the same waypoint script, simply by setting a local variable on them (WP_TAG). That way you can still target individuals via their unique tags, but you don't need dozens of separate scripts or duplicate waypoint sets.

The down side is that sometimes you find yourself standing about and watching what NPCs will do next, rather than actually playing the module...

#11
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
I have something similar DannJ. It's very basic right now, but have it set so that all the generic NPCs walk the same WPs. When they get to one of the points, they randomly choose another one and then walk to there. I have the WPs scattered all over the area. Gives a good representation of the general population wandering about.

#12
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

DannJ wrote...

I've been playing about with scripted waypoints as well. They're great for randomising NPC walking around towns or merchant stalls, rather than having everyone just walk back and forth along the same path. I also randomise the pause time at each waypoint, just so everyone doesn't up and walk about in synch, like a big game of Musical Chairs.

The most useful feature I've found is the ability to override the NPCs tag so that everyone can run the same waypoint script, simply by setting a local variable on them (WP_TAG). That way you can still target individuals via their unique tags, but you don't need dozens of separate scripts or duplicate waypoint sets.

The down side is that sometimes you find yourself standing about and watching what NPCs will do next, rather than actually playing the module...



That sounds very useful.  Could you explain the process of overriding the NPC's tag in more detail? 

#13
M. Rieder

M. Rieder
  • Members
  • 2 530 messages

_Knightmare_ wrote...

I have something similar DannJ. It's very basic right now, but have it set so that all the generic NPCs walk the same WPs. When they get to one of the points, they randomly choose another one and then walk to there. I have the WPs scattered all over the area. Gives a good representation of the general population wandering about.



Do you also do this by overriding the tag?  I'd like to keep the tags separate, but I like the idea of everyone using one script.  Makes things a lot easier.  I'll be puting the ambience in a town in the next few weeks and some new tricks would be nice.

#14
kamal_

kamal_
  • Members
  • 5 240 messages
yeah, I'm going to have to trade some area designing for some commoner scripted waypoint-fu.

#15
The Fred

The Fred
  • Members
  • 2 516 messages
Random walking is good. I think they started to use that instead of waypoints from HotU onwards (maybe SoU) - in fact, there are a lot of clever systems still there from HotU which I'm not sure ever got used, and I'm not sure actually work. Look for scripts starting "x2_am_" I think (I'm guessing that stands for "ambient"). There is a bunch of stuff like waypoints you can put down to make people do things and so forth. Mostly I'm just using this for inspiration and making brand new stuff myself, though, but there's probably a veritable mine of untapped resources.

#16
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

M. Rieder wrote...

_Knightmare_ wrote...

I have something similar DannJ. It's very basic right now, but have it set so that all the generic NPCs walk the same WPs. When they get to one of the points, they randomly choose another one and then walk to there. I have the WPs scattered all over the area. Gives a good representation of the general population wandering about.



Do you also do this by overriding the tag?  I'd like to keep the tags separate, but I like the idea of everyone using one script.  Makes things a lot easier.  I'll be puting the ambience in a town in the next few weeks and some new tricks would be nice.


Yes. Set a local string variable on the NPC that must be named "WP_TAG" without quotes. Set its value equal to the tag of walk waypoints you want them to follow (without the numbers) and they will follow that waypoint set. So if you had 50 people all with that string, you only need one set of walkpoints for all of them, no matter what their individual tags are. Then just have a single script that is run that tells them to go to some random next waypoint:


#include "ginc_wp"
 
void main()
{
    int iCurrentWP = GetCurrentWaypoint();
    int iNextWP;
    switch (iCurrentWP)
    {
        case 1:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 2:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 3:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;

   ///// Etc.

  case 19:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 20:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
 }
}

They will just walk randomly from point to point. You can uncomment the animation lines and have them do something once they reach the target WPs location. After doing the animation, they would continue on to the next random WP. The script doesn't get placed on anything, it just needs to exist within the module/campaign and must be named "wp_<tag of walk waypoints>" without quotes.

#17
kamal_

kamal_
  • Members
  • 5 240 messages

The Fred wrote...

Random walking is good. I think they started to use that instead of waypoints from HotU onwards (maybe SoU) - in fact, there are a lot of clever systems still there from HotU which I'm not sure ever got used, and I'm not sure actually work. Look for scripts starting "x2_am_" I think (I'm guessing that stands for "ambient"). There is a bunch of stuff like waypoints you can put down to make people do things and so forth. Mostly I'm just using this for inspiration and making brand new stuff myself, though, but there's probably a veritable mine of untapped resources.

With ambient animation turned on, the npc's move around from where they are placed, but they do not move very far, maybe a house length, tops. (they also can interact with each other when close, which is nice)

#18
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
@KM (or anyone else who knows)

I noticed you used the animation "ANIMATION_LOOPING_SIT_CROSS" in your sample script. Have you been able to make that animation work, or is it just an example. There are quite a few of the animations that I cannot get to work with PlayAnimation or ActionPlayAnimation and have to substitute with PlayCustomAnimation.

I would also like to talk about the ambient animations. Are they pretty simple to turn on? It sounds like a nice shortcut to making a bustling little community.

#19
kamal_

kamal_
  • Members
  • 5 240 messages

M. Rieder wrote...

Are they pretty simple to turn on? It sounds like a nice shortcut to making a bustling little community.

Yes. it's a variable you set on the npc.
X2_L_SPAWN_USE_AMBIENT  == 1   (they move around some)
X2_L_SPAWN_USE_AMBIENT_IMMOBILE == 1  (play some animations, but don't move)

#20
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Thanks kamal_ . I'm definitely going to experiment with that one and probably use it.

#21
MasterChanger

MasterChanger
  • Members
  • 686 messages

_Knightmare_ wrote...

#include "ginc_wp"
 
void main()
{
    int iCurrentWP = GetCurrentWaypoint();
    int iNextWP;
    switch (iCurrentWP)
    {
        case 1:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 2:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 3:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;

   ///// Etc.

  case 19:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
  case 20:
            iNextWP = Random(GetNumWaypoints()-1) + 2;
            SetNextWaypoint(iNextWP);
            //ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0, 7.0);
            break;
 }
}


Out of curiosity,_KM_,  what is the purpose of your switch-case? All the case instructions seem to be the same.

Modifié par MasterChanger, 04 juin 2011 - 06:50 .


#22
kamal_

kamal_
  • Members
  • 5 240 messages

MasterChanger wrote...
Out of curiosity,_KM_,  what is the purpose of your switch-case? All the case instructions seem to be the same.

You need one case per waypoint you have.

Modifié par kamal_, 04 juin 2011 - 06:56 .


#23
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
If the NPC does the same thing at each waypoint, I don't think you need to even worry about what waypoint the NPC is at, just put the lines of code down and they will be executed.

But, I think that KM was just posting an example and I think that KM meant that each case would be the same or different.

#24
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

M. Rieder wrote...

If the NPC does the same thing at each waypoint, I don't think you need to even worry about what waypoint the NPC is at, just put the lines of code down and they will be executed.

But, I think that KM was just posting an example and I think that KM meant that each case would be the same or different.


Correct, just an example. You need one case statement per waypoint in the set if you want anything special to happen at the waypoint number. So, in my example I have 20 waypoints scattered about the town. As it stands they will just walk between the different waypoints. You can add code under each case and have them do something special when they reach a certain waypoint. For example, if my waypoints were tagged "wp_walkpoint_1" through "wp_walkpoint_20" (my script name as well as the WP_TAG string value would be "wp_walkpoint") and I wanted them to do somethig special when they reached "wp_walkpoint_7"  I would add that special/extra code under case 7. As an example of that, maybe WP 7 is outside a door, I could code it so when they reached there, they opened the door and then destroyed themselves, giving the appearance that they entered the building through the door.

Modifié par _Knightmare_, 04 juin 2011 - 08:34 .


#25
MasterChanger

MasterChanger
  • Members
  • 686 messages
Gotcha. You were just setting up the potential for them to be different. However, if you don't want them to be different, you could just use fall-through syntax:

switch (iWP)
{
case 1:
case 2:
case 3:
...
case 500: // do something
break;
}

Alternatively, if something special happens only at certain waypoints, and the others are generic, you could just leave out your non-special cases, and group all your generic stuff under the default case:

switch (iWP)
{
case 3: // dance like a chicken
break;

case 10: // dance like a drunk chicken
break;

case 20: // critical hit with a vorpal sword! dance like a headless chicken
break;

default: // do something generic and boring like just going to the next WP
break;
}