Aller au contenu

Photo

NPC vs PC animation problem


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

#1
johnbgardner

johnbgardner
  • Members
  • 185 messages
I am using the following code on the OnUsed script of a chair to enable a PC to sit down. 

// Placeable OnUsed Template 
/*
 Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event
 Suggested: Plot=TRUE, DefaultActionPreference="Use"
*/
//
#include "ginc_wp"
#include "ginc_debug"
#include "ginc_rtee"
void main()
{
 object   oUser = GetLastUsedBy();
 string   sTag=GetLocalString(OBJECT_SELF, "wp");
    object   oWP=GetObjectByTag(sTag);
    location lChair=GetLocation(oWP);
 float    fFacing=GetFacingFromLocation(lChair);
 string   sAnimation=GetLocalString(OBJECT_SELF, "anim");
 
 AssignCommand(oUser, ActionJumpToLocation(lChair));
 DelayCommand(0.5, SetFacingWrapper(oUser, fFacing));
    AssignCommand(oUser, ActionSpeakString("Chair tag is "+sTag));
 DelayCommand(1.5, PlayCustomAnimationWrapper(oUser, sAnimation, 1));
 
}

It works perfectly with the NPC facing the right way and sitting on the chari.  I tried to use the exact same procedure in a  scripted waypoint script to have an NPC sit in the chair and the NPC sits in mid-air, i.e. it doesn't jump to the location.  The script I'm using is as follows:

// wp_jennithar
// Jennithar's walkwaypoint action script
#include "ginc_wp"
#include "ginc_rtee"
void main()
 {
  int      iCurWP=GetCurrentWaypoint();
  string   sWPPrefix=GetWPPrefix(OBJECT_SELF);
  object   oWP=GetWaypointByNum(iCurWP, sWPPrefix, 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");
  int      iEffect=GetLocalInt(oWP, "effect");
  effect   eEffect;
  int      i;
 
 
  for (i=1; i<=nRepeat; i++)
   {
    if (GetIsObjectValid(oItem))
     {
   ActionSpeakString("Valid Item found: "+sItemTag);
      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:
     ActionSpeakString("Playing animation "+sAnimation);
     PlayCustomAnimation(OBJECT_SELF, sAnimation, bLoop);
     break;

    // Here is where the NPC sits in a chair
    // chair
    case 1:
     ActionSpeakString("Sitting in chair");
        AssignCommand(OBJECT_SELF, ActionJumpToLocation(lInteractObject));
     DelayCommand(0.5, SetFacingWrapper(OBJECT_SELF, fFacing));
        AssignCommand(OBJECT_SELF, ActionSpeakString("Chair tag is "+sObjectTag));
     DelayCommand(1.5, PlayCustomAnimationWrapper(OBJECT_SELF, sAnimation, 1));
     break;
    // container
     case 2:
   ActionSpeakString("Opening container");
      DoPlaceableObjectAction(oInteractObject,PLACEABLE_ACTION_USE);
      break;
    // door
     case 3:
   ActionSpeakString("Opening door");
      DoDoorAction(oInteractObject, DOOR_ACTION_OPEN);
      break;
   // bed
     case 4:
   AssignCommand(OBJECT_SELF, ActionJumpToLocation(lInteractObject));
      DelayCommand(0.5, SetFacingWrapper(OBJECT_SELF,fFacing));
      DelayCommand(1.5, PlayCustomAnimationWrapper(OBJECT_SELF, sAnimation, 1));
   }
  switch (iEffect)
   {
    // no effect
    case 0:
     break;
    // Sleep
    case 1:
     ActionSpeakString("applying sleep effect");
     eEffect=EffectSleep();
     break;
   }
   if (iEffect != 0)
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEffect, OBJECT_SELF, fDelay);      
     ActionWait(fDelay);
   }
 }

I know the part of the script that seats the NPC is firing because the NPC speaks "Sitting in chair".  I'd appreciate any insights into what I may be doing wrong.  Thanks muchly.

#2
johnbgardner

johnbgardner
  • Members
  • 185 messages
AHA!!! I found the problem. It seems that the AssignCommand doesn't work for ActionJumpToLocation. I used simply ActionJumpToLocation and it's working! Lesson learned.

#3
kamal_

kamal_
  • Members
  • 5 260 messages
nm, you already solved it.

Modifié par kamal_, 25 juin 2012 - 11:29 .


#4
Dann-J

Dann-J
  • Members
  • 3 161 messages
I've also got usable stools in a module I'm working on. I simplified things by commanding NPCs to go and use the same usable stool placeables that PCs do (turning off their ability to use walk waypoints temporarily, rather than incorporating sitting into the walk waypoint system).

Make sure you set the sitter to unbumpable, and turn off their 'orient on dialog', otherwise they'll stand up again if you bump into or try to talk to them. You can switch both settings back when they stand up again.

#5
johnbgardner

johnbgardner
  • Members
  • 185 messages
thanks, I'll do that.