Aller au contenu

Photo

Walk Waypoint scripting help needed


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

#1
pkniess77

pkniess77
  • Members
  • 7 messages
Been trying for days to get an NPC in my module to do a seemingly simple thing - walk a short distance, kneel down, and stop. The reason is that she's supposed to be eavesdropping on a conversation going on around the corner (it's part of a cutscene). I can't get it to work consistently for the life of me, though. I'll paste in the script I'm using, or at least the relevant part of it:

object oTarget;

oTarget = GetObjectByTag("shindia");

AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("WP_shindia_02")));

AssignCommand(oTarget, ActionPlayAnimation(ANIMATION_LOOPING_KNEELIDLE, 1.0f, 600.0f));

SetWalkCondition(NW_WALK_FLAG_PAUSED, TRUE);


I put that segment at the end of the default heartbeat script and saved it as a copy with it named the way it's supposed to be (wp_shindia), and the copy of the NPC that's placed in the area has the variable set as it should be, WP_TAG = "shindia". But when I run the module in-game, sometimes the NPC will do what she's supposed to do and sometimes she won't, without me making any changes at all. Sometimes she'll start out at the second waypoint instead of the first and won't kneel down, other times she'll start there and be facing the wrong direction. It seems to be random, and I don't know why. I had originally had a line in the script telling her to go to the first waypoint before going to the second, but when that line was in there, she'd show up at the 2nd waypoint, go back to the first, then back to the 2nd and then kneel or sometimes not kneel. Any help would be greatly appreciated, or if any of you script gurus know a better way of accomplishing this goal, I'd be very grateful. I'm still a bit new to mod-making, so I'm always open to new ideas about how to do things. Thanks!

Modifié par pkniess77, 05 décembre 2011 - 03:09 .


#2
Dann-J

Dann-J
  • Members
  • 3 161 messages
Mmm... you look familiar for some reason....

Anyhoo; I assume you've looked at this thread. From your snippet of code, it looks like you're trying to do the same thing at every walkpoint, rather than executing specific instructions for individual waypoints.

There shouldn't be any need to force her to walk from one waypoint to the other, as she'll do that by herself. All you should need is a check to see that she's at a specific waypoint, then make her pause for a specific amount of time and kneel down. When the pause time is up, she should get up and walk to whatever her next waypoint is.

Modifié par DannJ, 05 décembre 2011 - 04:39 .


#3
pkniess77

pkniess77
  • Members
  • 7 messages
I appreciate your reply, but I read through that thread before. There are only 2 waypoints, the one she starts from and the one she goes to, and I don't want her moving anymore after reaching the 2nd one. I don't know a whole lot about scripting, mostly I've used Lilac Soul's scripting program to do much of it for me. I tried using the switch case method as well, but when I did that she would just keep walking between the two walkpoints and not play the animation at the second point even though it was uncommented and even though there was a pause command right after it.

#4
Morbane

Morbane
  • Members
  • 1 883 messages
try to ClearAllActions() before the kneelidle loop. you might have to experiment with a delaycommand on the clearallactions to prevent it from happening too soon.

Modifié par Morbane, 05 décembre 2011 - 05:21 .


#5
pkniess77

pkniess77
  • Members
  • 7 messages
I did what you said, Morbane, and added a ClearAllActions command before the loop. Now she's at the waypoint and kneeling, but sometimes she's already there by the time the area finishes loading, maybe for some reason she starts walking before it's finished loading? So I'm thinking to add a delay like you said, before the command to send her to the waypoint, but the script isn't compiling. Here's what I added for the delay:

float fDelay = 5.0f;
DelayCommand(fDelay, AssignCommand);


Is that right? Also, although the NPC is kneeling, she doesn't stay down but rather keeps standing up and then kneeling again. Any idea why that might be? That didn't happen till I put the ClearAllActions line in, by the way.

#6
pkniess77

pkniess77
  • Members
  • 7 messages
Forgot to mention that the error I get with the script is this: NO LEFT BRACKET ON ARG LIST. What does that mean? Thanks!

#7
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Hey pkneiss77,

In my upcoming module, I have people doint lots of walkwaypoint stuff, and what you describe is possible. Here's the catch. I'm not at my modding computer and it was about 6 months ago that I did all this stuff, so I can't give you a great answer right now, but I'll tell you what I remember and when I get back to my modding computer, I'll give you some more stuff.

As I recall, there is a certain mechanism in the Walkwaypoint system that allows a certain script to fire every time you arrive at a waypoint. The script is probably saved as a local string on the NPC doing the waypoints. Let me look around on the net for a second...

#8
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
...found it. 
Check out this link:
http://nwn2.wikia.co...points]Scripted waypoints[/url]

Basically you need to make a script called "wp_<tag of npc doing the waypoints>"


This script will fire each time the NPC reaches a waypoint, so if you want the NPC to only crouch down at one waypoint, you need to put in the necessary conditionals to make sure the code only fires at the right waypoint. 


This is the way I scripted all my waypoints and they work pretty well.  There were a few scripts that took some work to get right and I had to make some changes when a few NPC's got stuck in different places.  It takes some time but you should be able to get this up and running.


An alternative solution which may be easier and more foolproof would be making a cutscene.  If this is just a cinematic event, you could use a convo and assign commands with nodes on the convo

Modifié par M. Rieder, 05 décembre 2011 - 07:52 .


#9
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
...found it.
Check out this link:

http://nwn2.wikia.co...ipted_waypoints

Basically you need to make a script called "wp_<tag of npc doing the waypoints>"


This script will fire each time the NPC reaches a waypoint, so if you want the NPC to only crouch down at one waypoint, you need to put in the necessary conditionals to make sure the code only fires at the right waypoint.


This is the way I scripted all my waypoints and they work pretty well. There were a few scripts that took some work to get right and I had to make some changes when a few NPC's got stuck in different places. It takes some time but you should be able to get this up and running.


An alternative solution which may be easier and more foolproof would be making a cutscene. If this is just a cinematic event, you could use a convo and assign commands with nodes on the convo

Modifié par M. Rieder, 05 décembre 2011 - 07:53 .


#10
Morbane

Morbane
  • Members
  • 1 883 messages
it is repeating because it is in the heartbeat slot - it fires every 6 seconds - the way to avoid it repeating is to use something like this:
if(GetLocalInt("once") == TRUE)return;
DelayCommand(5.0f, AssignCommand(oTarget, ActionPlayAnimation(ANIMATION_LOOPING_KNEELIDLE, 1.0f, 600.0f));
SetLocalInt("once", TRUE);

that might help - and do give MReider's suggestion a try - the built in system is actually pretty intuitive - me personally - I just hotwire everything ;)

Modifié par Morbane, 05 décembre 2011 - 08:07 .


#11
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Here is a simple waypoint script I used. I put a local string on the NPC with the name of a custom animation on it. The NPC will perform the custom animation at each waypoint.


//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,3.0f);
PlayCustomAnimation(oSelf,GetLocalString(oSelf,"sAnimation"),1,1.0);
}

#12
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
This one is more involved. It makes the NPC appear to chop wood, then place it in a wood pile. There are 2 waypoints for the NPC that uses this script:

#include "ginc_wp"
#include "x0_i0_walkway"
void main()
{

object oSelf=OBJECT_SELF;
string sTag = GetTag(oSelf);
object oSound = GetObjectByTag(sTag+"_sound");
int nWPT = GetCurrentWaypoint();
float fTimer = 0.0;
switch (nWPT)
{
case 1:

SoundObjectPlay(oSound);
DelayCommand(15.0,SoundObjectStop(oSound));

FaceAndPause(nWPT,15.0f);
PlayCustomAnimation(oSelf,"1hS_1attack01",1,1.0);
break;

case 2:
FaceAndPause(nWPT,3.0f);
PlayCustomAnimation(oSelf,"disableground",1,1.0);
break;
}


}

#13
pkniess77

pkniess77
  • Members
  • 7 messages
Been attempting to try it as a conversation, as you said, Rieder, but the convo won't start when the area loads. I've got a speaktrigger placed where the PC starts, and I'm sure I've got all the variables set right, so I don't know what's going on. I've got my cameras in place and the conversation saved and it's on one of the NPC's that the girl is listening to, since he says the first line. I've been specifying a listener and speaker for each line of the convo, too. Any ideas?

#14
Dann-J

Dann-J
  • Members
  • 3 161 messages
Are you fully patched to version 1.23? With previous patches, spawning directly on top of a speak trigger wouldn't trigger it properly, however this appears to have been fixed in one of the latest patches (either 1.22 ot 1.23).

If that's what's happening, then painting the trigger just ahead of where the PC spawns should do the trick. The player only has to take a couple of steps to activate it.

If you really want the conversation to fire as soon as the game begins, then an OnClientLoaded script attached to the start area would be better. Just make sure you place a local variable on the area after it fires once, so that the conversation doesn't try to fire every time you re-enter the area (or reload from a saved game).

You may also be too far away from the NPC who the conversation is attached to, which would also prevent the conversation starting.

#15
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
For future reference, spawning into a speak trigger is unreliable and will lead to nothing but headaches - even with version 1.23. Sometimes it works, sometimes it doesn't. I spent 6 months working with my current module using spawns into speak triggers (starting the game, or when transitioning areas) and they worked fine, but one day they just stopped working. I had to change all the conversations to start from the area on enter event. What a headache!

The generally accepted and advised way to start a conversation when entering an area is to put your script in the "area on enter" event. This is reliable every time.

Apart from that, it is hard to debug a conversation without being able to see all the moving parts. I recommend that if spawning next to the trigger does not work, you should start with a simpler conversation - one or two lines - and test that one before you move on. This will help you work through the process and likely reveal the problem.



Do what DannJ says for testing. Don't spawn into the trigger, just spawn next to it then walk into it.

#16
pkniess77

pkniess77
  • Members
  • 7 messages
Got it working, finally! I had to take out the quotes for the string variables on the speaktrigger. Now it plays, but there's a brief flash (about a second) where you see the player before the convo starts. The drow girl does what she's supposed to now, though, walks to the corner and kneels down. It was much easier to get it done in a convo. Thanks, guys! I did try to use a script on the "area on enter" but it didn't work. Might try it again though. I used a speaktrigger cause I downloaded a cutscene tutorial from the vault and that's what they suggested. But if an onEnter script is more reliable, I'll try to go that route. Thanks again!

#17
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
It takes some time to get the scripting expertise to write reliable scripts. Try the tutorials by knightmare and scriptwiz on the vault. They are very good.

#18
pkniess77

pkniess77
  • Members
  • 7 messages
I'll look into them, Rieder, thanks! :)

#19
Dann-J

Dann-J
  • Members
  • 3 161 messages

pkniess77 wrote...

Thanks, guys! I did try to use a script on the "area on enter" but it didn't work.


Below is a script I use to fire a conversation as soon as you enter an area, using the OnClientEnter slot. You set two variables on the area; Conversation is the name of the conversation file, and Talker is the tag of the creature you want to talk to. A third variable, TalkDone, gets set after it runs once to prevent it running again. At any point during the game, you can overwrite those local variables so that you can run a different one-off conversation the next time you enter that specific area (you have to set TalkDone back to zero, and change the Conversation and Talker variables as required). 


// OnClientEnter script to start conversation when entering an area for the first time
// Set local variables Conversation and Talker (both strings) on the area
void TalkOnEnter()
{
object oArea = GetArea(GetFirstPC());
string sConv = GetLocalString(GetArea(GetFirstPC()), "Conversation");
string sTalker = GetLocalString(GetArea(GetFirstPC()), "Talker");
int iDone = GetLocalInt(oArea, "TalkDone");
if (iDone == 1)// Once marked done, never run again
 return;
SetLocalInt(oArea, "TalkDone", 1);
AssignCommand(GetFirstPC(), ActionStartConversation(GetObjectByTag(sTalker),sConv, FALSE, FALSE, TRUE, FALSE));
}
void main()
{
DelayCommand(1.0, TalkOnEnter());// delay for 1 second before firing conversation
}