Aller au contenu

Photo

Advanced Waypoint Scripting Question


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

#1
Doc Valentine

Doc Valentine
  • Members
  • 9 messages
Hello there,

I am adapting from scripting with NWN and Kotor, so there are a few new things I need to learn. For instance, advanced waypoint scripting. Right now I am trying to make the castle I am building a little bit more alive, so I want NPC's doing various tasks throughout the castle. I know the basics of scripting waypoings, but where I need help is delaying items in the queue or, at least finidng a way to script on_waypoint_reached events.

The particular situation I am trying to simulate with my script is having an NPC walk a path in my library and stop at certain points and play animations such as "read" or "ponder". Now I cant simply just put an AddCommand all the way down for this, because they all fire at the same time. Is there a way that I can fire a command only after the previous command has been fired?

Here is my script at the moment:

void main()
{
  object oPerson = GetObjectByTag("dgman");
  object oWay1 = GetObjectByTag("per_way_1");
  object oWay2 = GetObjectByTag("per_way_2");
  object oWay3 = GetObjectByTag("per_way_3");
  object oWay4 = GetObjectByTag("per_way_4");
  object oWay5 = GetObjectByTag("per_way_5");
  object oWay6 = GetObjectByTag("per_way_6");
  object oWay7 = GetObjectByTag("per_way_7");
  object oWay8 = GetObjectByTag("per_way_8");
  location lPoint1 = GetLocation(oWay1);
  location lPoint2 = GetLocation(oWay2);
  location lPoint3 = GetLocation(oWay3); 
  location lPoint4 = GetLocation(oWay4);
  location lPoint5 = GetLocation(oWay5);
  location lPoint6 = GetLocation(oWay6);
  location lPoint7 = GetLocation(oWay7);
  location lPoint8 = GetLocation(oWay8);
  float fPoint1 = GetFacing(oWay1);
 
 
   AddCommand (oPerson, CommandMoveToLocation (lPoint1, FALSE, FALSE));
   AddCommand (oPerson, CommandMoveToLocation (lPoint2, FALSE, FALSE)); 
   AddCommand (oPerson, CommandMoveToLocation (lPoint3, FALSE, FALSE));
   AddCommand (oPerson, CommandMoveToLocation (lPoint4, FALSE, FALSE));
   AddCommand (oPerson, CommandMoveToLocation (lPoint5, FALSE, FALSE));
   AddCommand (oPerson, CommandMoveToLocation (lPoint6, FALSE, FALSE));
   AddCommand (oPerson, CommandMoveToLocation (lPoint7, FALSE, FALSE)); 
   AddCommand (oPerson, CommandMoveToLocation (lPoint8, FALSE, FALSE));
  
  
}  

Modifié par Doc Valentine, 18 janvier 2010 - 08:54 .


#2
hunharibo

hunharibo
  • Members
  • 126 messages
I would love to know this too!

I once took a look inside sys_ambient_h, most of this stuff is defined there, but it is kind of complex, i didnt understand half of it.

#3
Doc Valentine

Doc Valentine
  • Members
  • 9 messages
Ahhhh, nice, I'll have a look at that as soon as I can, maybe I can muster something from it.

#4
BioSpirit

BioSpirit
  • Members
  • 261 messages
You don't need a script to do that. It is possible to make a NPC to walk a set of waypoints and perform some random ambient animations at each waypoint by using buildin ambient system.

Now I cant simply just put an AddCommand all the way down for this, because they all fire at the same time. Is there a way that I can fire a command only after the previous command has been fired?


Of course you can. Exactly the same way as you just scripted above. AddCommand() will execute next command when previous is finished. Calling AddCommand multible times like you just did will recond the commands in creature's command queue for waiting execution.

Modifié par BioSpirit, 18 janvier 2010 - 10:07 .


#5
Doc Valentine

Doc Valentine
  • Members
  • 9 messages
Oh, wow, that hadn't occured to me, I was under the impression that the ambient variables only alowed for basic walking of waypoints. Thank you for that bit of advice.

Of course you can. Exactly the same way as you just scripted above. AddCommand() will execute next command when previous is finished. Calling AddCommand multible times like you just did will recond the commands in creature's command queue for waiting execution."


Really? I noticed that once I tested the script, the NPC would only walk to the final waypoint and none of the ones before it. Is there a parameter in the NPC's variables I need to set to make this function work properly?

#6
Craig Graff

Craig Graff
  • Members
  • 608 messages
If I recall correctly, the optional nOverrideAddBehavior needs to be set to COMMAND_ADDBEHAVIOR_DONTCLEAR. You are likely better off either using the ambient system or using EVENT_TYPE_CUSTOM_COMMAND_COMPLETE (if you do the latter, make sure you set your creature's AI_CUSTOM_AI_ACTIVE variable to 1).

Modifié par Craig Graff, 18 janvier 2010 - 10:36 .


#7
Doc Valentine

Doc Valentine
  • Members
  • 9 messages
Craig that worked wonders, it is working perfectly now. Thank you very much.

#8
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
Just an FYI, this kind of thing doesn't work across area boundaries. Unlike NWN, there is only 1 area running at any given time. I don't know what you were planning exactly, but I know this was a big deal during NWN and NWN2 days.

Modifié par FalloutBoy, 19 janvier 2010 - 05:50 .