Aller au contenu

Photo

Scripted waypoint question


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

#1
johnbgardner

johnbgardner
  • Members
  • 185 messages
I'm using the following code for a scripted waypoint script. For some reason I can't get the NPC to lie down and sleep.
Perhaps I'm wrong in assuming that the GetWaypointByNum function would return INVALID if the NPC wasn't at a daytime waypoint.  I'd really appreciate someone pointing me in the right direction to accomplish this.  Thanks.

#include "ginc_wp"
#include "ginc_rtee"
void main()
 {
  int      iCurWP=GetCurrentWaypoint();
  object   oWP=GetWaypointByNum(iCurWP, "WP_", OBJECT_SELF);
  int      iEquipAction=GetLocalInt(oWP, "eqaction");
  string   sItemTag=GetLocalString(oWP, "item");
  int      iItemSlot=GetLocalInt(oWP, "slot");
  object   oItem=GetItemPossessedBy(OBJECT_SELF, sItemTag);
  int      iInteractAction=GetLocalInt(oWP, "doaction");
  string   sObjectTag=GetLocalString(oWP, "object");
  object   oInteractObject=GetObjectByTag(sObjectTag);
  location lInteractObject=GetLocation(oInteractObject);
  float    fFacing=GetFacingFromLocation(lInteractObject);
  string   sAnimation=GetLocalString(oWP, "anim");
  int    bLoop=GetLocalInt(oWP, "loop");
  int    nRepeat=GetLocalInt(oWP, "repeat");
  float    fDelay=GetLocalFloat(oWP, "delay");
  object   oBedWP;
  location lBed;
  effect   eEffect=EffectSleep();
  int      i;
 
  if (!GetIsObjectValid(oWP))
   {
    oBedWP=GetWaypointByNum(iCurWP, "NIGHT_", OBJECT_SELF);
    lBed=GetLocation(oBedWP);
    fFacing=GetFacingFromLocation(lBed);
    AssignCommand(OBJECT_SELF, SetFacing(fFacing, 0));
    PlayCustomAnimation(OBJECT_SELF, "proneB", 1);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, OBJECT_SELF, 9000.0);
   }
  else
   {
    ActionMoveToObject(oWP, 0, 0.5); 
    for (i=0; i<=nRepeat; i++)
     {
     if (GetIsObjectValid(oItem))
    {
     switch(iEquipAction)
      {
       // Equip item, perform animation, then unequip item
       case 0:
        ActionEquipItem(oItem, iItemSlot);
        PlayCustomAnimation(OBJECT_SELF, sAnimation, bLoop);
        ActionUnequipItem(oItem);
        break;
      // Equip item
       case 1:
        ActionEquipItem(oItem, iItemSlot);
        break;
      // Unequip item
       case 2:
        ActionUnequipItem(oItem);
       break;  
      }
     }
      switch (iInteractAction)
     {
      // just animation
      case 0:
       PlayCustomAnimation(OBJECT_SELF, sAnimation, bLoop);
       break;
      // chair
      case 1:
       AssignCommand(OBJECT_SELF, ActionJumpToLocation(lInteractObject));
       AssignCommand(OBJECT_SELF, SetFacing(fFacing, 0));
       DelayCommand(1.5, PlayCustomAnimationWrapper(OBJECT_SELF, sAnimation, 1));
       break;
      // container
      case 2:
       DoPlaceableObjectAction(oInteractObject,PLACEABLE_ACTION_USE);
       break;
      // door
      case 3:
       DoDoorAction(oInteractObject, DOOR_ACTION_OPEN);
       break;
       }     
     ActionWait(fDelay);
   }
  }
 }

#2
kevL

kevL
  • Members
  • 4 078 messages
the #include 'x0_i0_walkway' has the function GetWaypointByNum(), that's defining your oWP object. It says that it's trying to retrieve a local object on the WWPController and will look for a different local_object depending on whether it's day or night (subfunction). I don't fully understand the WWPController ... but for now i suggest you put some debug code in that script, specifically

if (!GetIsObjectValid(oWP))
{
SendMessageToPC(GetFirstPC(FALSE), "script says, oWP is not valid");

// etc.
}
else
{
SendMessageToPC(GetFirstPC(FALSE), "script says, oWP is Valid");

// etc.
}


here's a few links, but it sounds like what you're doing is a lot more custom,

http://nwn2.wikia.co...h_walkwaypoints
http://nwn2.wikia.co...ipted_waypoints
http://social.biowar...-3298471-1.html


It's possible ( even likely ) that you're trying to latch your custom scripts into the default system that comes with the game inconsistently. But that's just a guess ... oh, this is interesting:

// Retrieves specified WP object from oCreature's WWP Controller
object GetWaypointByNum(int iWayPoint, string sPrefix = WW_WP_PREFIX, object oCreature = OBJECT_SELF)
{
object oWWPController = GetWWPController(oCreature);
object oRet = GetLocalObject(oWWPController, GetWPPrefix() + IntToString(iWayPoint));

return oRet;
}

- the function *does not use* the string parameter; it gets its own w/ GetWPPrefix() -- not sure if it's related or not, but remember, these WWP functions are going on 10 yrs. old,

#3
johnbgardner

johnbgardner
  • Members
  • 185 messages
thanks, I'll look into that. My problem is that I can't just use a GetNearestObject because my waypoints could be just about anything. For example, a planter that needs to be watered. I don't use the standard waypoint object, just tag the placeable or other object consistent with the waypoint sequence. It seems to work great. Wait a sec, that statement just gave me an idea. I use a waypoint object to facilitate getting into the bed, maybe I can use the GetObject function that specifies type (waypoint) to see if I'm at the night post. Hmm...be back later if it works.

#4
johnbgardner

johnbgardner
  • Members
  • 185 messages
After putting in some degguging lines, I find that for some reason the scripted waypoint script is not even firing when the NPC goes to the night post. Apparently it has something to do with switching the day/night waypoints. In x0_i0_walkway the author deliberately skips running that script saying in a comment that if it runs it could cause wierd behavior. Does anyone have a suggestion as to how to override this without modifying the x0_i0_walkway script?

#5
kevL

kevL
  • Members
  • 4 078 messages
maybe you could use the standard WP_## tags and put a string_var on the placeables "bed", "planter", etc. and then in the script put like

if (GetLocalString(GetCurrentWaypoint(), "sWWPtype") == "bed") // do nap.


- ie, just define oWP as GetCurrentWaypoint() and use uhm pre-placed variables on those placeables to determine what section of code runs ..? ps. check for GetIsNight() too

Modifié par kevL, 25 juin 2012 - 06:03 .


#6
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
I don't know what your path looks like, but you could do everything with day waypoints, but then have a conditional that tells the walker to skip the bed waypoint if it's still daytime. Then the bed waypoint could tell them to pause the walkwaypoints until morning.

#7
johnbgardner

johnbgardner
  • Members
  • 185 messages
The problem is that the script it is supposed to fire at each waypoint doesn't fire for the NIGHT_ post waypoint at all. Perhaps I just need to eliminate the NIGHT_ waypoint and make it a regular one that the NPC only goes to at night and only leaves when it becomes day again. Although that might introduce a problem if the PC has a conversation at night. I'll try that. Thanks all for the input.

#8
johnbgardner

johnbgardner
  • Members
  • 185 messages
I finally "fingered" it out! The x0_i0_walkway script doesn't run the script if posted UNLESS a variable is set on the NPC ( int WP_SINGLE_POINT_OVERRIDE set to 1). Also, the script uses the waypoint prefixes WP_ and WN_ (not POST_ or NIGHT_) to call the script. Final solution: duplicate the waypoint script (wp_jennithar and wn_jennithar), make the night waypoint wn_jennithar_01 and set the variable on jennithar appropriately. Working like a charm now :)