Author Topic: npc Chaos  (Read 354 times)

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
npc Chaos
« on: September 10, 2010, 06:04:20 pm »


               Perhaps I've been awake to long going on 24hrs, and my logic has gone LD...

the issue im having is NPC runs a heart beat script for one.

checks ware NPC is at, if away from first location goto location and pray. then goto second location setfaceing location facing, speak,prayanim...etc

The problem is NPC doesnt face right, and other parts run.  what i need is for each case statement to run smothly IE.. goto location, set facing location, speak,pray...goto next loc, setfacing loc,speak,pray...repeat

i tried delaycommand,delaycommand execute script, im not getting it.
if I take out all delay command NPC goes to all areas prays speaks etc but never faces right way.
"mnk_pry_reset" is for errors or for when PC tries to talk to NPC and conversation started stops then resets but right now just resets if action invallid.

any ideas on how to fix this would be great.


here is script below, forgive structure its a work in progress still quite messy.

//:://////////////////////////////////////////////////////////////
//:: Title : tw_mnk_sitr_hb
//:: Author: altered below Greyfort
//:: Module: any who need
//:: Date  : Aug 24, 2010
//:: Vers  : 1.0
//:://////////////////////////////////////////////////////////////
//:://////////////////////////////////////////////////////////////
//WP_mslme1_wrshp,WP_mslme1_wrshp1,WP_mslme1_wrshp2,WP_mslme1_wrshp3
object oMonk=OBJECT_SELF;

object osWPpry0 =GetObjectByTag("WP_mslme1_wrshp");
string sWPpry0="wp_mslme2_srm1";
float fsWPpry0_monk = GetDistanceToObject(osWPpry0);
location lWPpry0_monkLoc=GetLocation(osWPpry0 );

object osWPpry1 =GetObjectByTag("WP_mslme1_wrshp1");
string sWPpry1 = "WP_mslme1_wrshp1";
float fsWPpry1_monk = GetDistanceToObject(osWPpry1);
location lWPpry1_monkLoc=GetLocation(osWPpry1);

object osWPpry2 =GetObjectByTag("WP_mslme1_wrshp2");
string sWPpry2 = "WP_mslme1_wrshp2";
float fsWPpry2_monk = GetDistanceToObject(osWPpry2);
location lWPpry2_monkLoc=GetLocation(osWPpry2);

object osWPpry3 =GetObjectByTag("WP_mslme1_wrshp3");
string sWPpry3 = "WP_mslme1_wrshp3";
float fsWPpry3_monk = GetDistanceToObject(osWPpry3);
location lWPpry3_monkLoc=GetLocation(osWPpry3);

//:://////////////////////////////////////////////////////////////
//:://////////////////////////////////////////////////////////////
int back2work  = GetLocalInt(OBJECT_SELF,"back2work");
int iNPC_state = GetLocalInt(OBJECT_SELF,"task");

switch (iNPC_state)
{
case 0:
     // statements ...monk anounces time for prayer...
     // npc near place0
     if( GetLocalInt(OBJECT_SELF,"back2work") ==0 && fsWPpry0_monk >=1.1 )
        {
        // speaks
        //AssignCommand(OBJECT_SELF,ActionSpeakString("Let us Pray...") );
        ActionSpeakString("Let us Pray..." );

        // move to pray spot0
        //AssignCommand(OBJECT_SELF,ActionMoveToObject(osWPpry0));
        //AssignCommand(OBJECT_SELF,ActionMoveToLocation(lWPpry0_monkLoc));
        ActionMoveToLocation(lWPpry0_monkLoc);

        //prays  GetIsObjectValid( GetNearestObjectByTag(sWPpry0) )
        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,7.0) );
        ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0);

        //mnk_pry_e1
        DelayCommand(7.3,AssignCommand(OBJECT_SELF,ExecuteScript("mnk_pry_e1",OBJECT_SELF) ) );
        //SetLocalInt(OBJECT_SELF,"task",1);
        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
     //error
case 1:
     // statements ... // npc near place1
     if( GetLocalInt(OBJECT_SELF,"back2work") ==0 && fsWPpry1_monk >=1.1 )//&& !GetIsObjectValid (GetSittingCreature(oPlc2Sit)) )
        {
        //moves to pray spot1
        //AssignCommand(OBJECT_SELF,AssignCommand(OBJECT_SELF,ActionMoveToObject(osWPpry1)));
        //AssignCommand(OBJECT_SELF,ActionMoveToLocation(lWPpry1_monkLoc));
        ActionMoveToLocation(lWPpry1_monkLoc);SetFacing(GetFacingFromLocation(lWPpry1_monkLoc) );

        // prays aloud speaks
        //AssignCommand(OBJECT_SELF,ActionSpeakString("Praise God from whom all blessings flow..."));
        //DelayCommand(10.0,AssignCommand(OBJECT_SELF,ActionSpeakString("Praise God from whom all blessings flow...") ) );
        ActionSpeakString("Praise God from whom all blessings flow...");

        // prays
        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0));
        //DelayCommand(10.0,AssignCommand(OBJECT_SELF,SetFacing(GetFacingFromLocation(lWPpry1_monkLoc) )));
        ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0);

        //set next task
        DelayCommand(7.3,AssignCommand(OBJECT_SELF,ExecuteScript("mnk_pry_e2",OBJECT_SELF) ) );
        //SetLocalInt(OBJECT_SELF,"task",2);
        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
case 2:
     // statements ...
     // // npc near place2
     //debug mesgs
     //ActionSpeakString("...case 2...back2work..."+IntToString(GetLocalInt(OBJECT_SELF,"back2work"))+"...task..."+IntToString(GetLocalInt(OBJECT_SELF,"task"))+"");
     if( GetLocalInt(OBJECT_SELF,"back2work") ==0 && fsWPpry2_monk >=1.1 )//&& fMnk2Plc <=1.0 && CheckCurrentAction() )//GetLocation(OBJECT_SELF)==lMnk2SitLoc && CheckCurrentAction() )
        {

        //moves to pray spot2
        //AssignCommand(OBJECT_SELF,ActionMoveToObject(osWPpry2));
        ActionMoveToLocation(lWPpry2_monkLoc);SetFacing(GetFacingFromLocation(lWPpry2_monkLoc) );

        // prays aloud
        ActionSpeakString("Praise him all creatures here below...");

        // prays
        //DelayCommand(20.0,AssignCommand(OBJECT_SELF,SetFacing(GetFacingFromLocation(lWPpry2_monkLoc) )));
        ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0);

        // set next task
        DelayCommand(7.3,AssignCommand(OBJECT_SELF,ExecuteScript("mnk_pry_e3",OBJECT_SELF) ) );
        //SetLocalInt(OBJECT_SELF,"task",3);

        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
case 3:
     // statements ...
     //// npc near place3     fsWPpry3_monk
     //debug mesgs
     //ActionSpeakString("...case 3...back2work..."+IntToString(GetLocalInt(OBJECT_SELF,"back2work"))+"...task..."+IntToString(GetLocalInt(OBJECT_SELF,"task"))+"");
     if(GetLocalInt(OBJECT_SELF,"back2work") ==0 && fsWPpry3_monk >=1.1 ) //GetLocation(OBJECT_SELF)!= lWP1_monkLoc && GetLocation(OBJECT_SELF)!=lWP2_monkLoc)
        {
        //moves to pray spot3
        //AssignCommand(OBJECT_SELF,ActionMoveToObject(osWPpry3));
        ActionMoveToLocation(lWPpry3_monkLoc);SetFacing(GetFacingFromLocation(lWPpry3_monkLoc) );

        // prays aloud
        ActionSpeakString("Praise him above ye Hevenly hosts...");

        //prays
        //DelayCommand(30.0,AssignCommand(OBJECT_SELF,SetFacing(GetFacingFromLocation(lWPpry3_monkLoc) )));
        ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0);

        //set next task
        DelayCommand(7.3,AssignCommand(OBJECT_SELF,ExecuteScript("mnk_pry_e4",OBJECT_SELF) ) );
        //SetLocalInt(OBJECT_SELF,"task",4);

        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
case 4:
     // statements ...
     //// npc near place3 npc going back 2 place0
     //debug mesgs
     //ActionSpeakString("...case 4...back2work..."+IntToString(GetLocalInt(OBJECT_SELF,"back2work"))+"...task..."+IntToString(GetLocalInt(OBJECT_SELF,"task"))+"");
     if(GetLocalInt(oMonk,"back2work") ==0 && fsWPpry0_monk >=1.1 )  //GetLocation(OBJECT_SELF)==lWP1_monkLoc && GetLocation(OBJECT_SELF)!=lWP2_monkLoc)
        {

        //moves to pray spot0
        //AssignCommand(OBJECT_SELF,ActionMoveToObject(osWPpry0));
        ActionMoveToLocation(lWPpry0_monkLoc);SetFacing(GetFacingFromLocation(lWPpry0_monkLoc) );

        // prays aloud
        ActionSpeakString("Praise Father Son and Holy Ghost...");

        //ActionSit(oPlc2Sit);
        //DelayCommand(40.0,AssignCommand(OBJECT_SELF,SetFacing(GetFacingFromLocation(lWPpry0_monkLoc) )));
        ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE,1.0,7.0);
        //set next task
        DelayCommand(7.3,AssignCommand(OBJECT_SELF,ExecuteScript("mnk_pry_e5",OBJECT_SELF) ) );
        //SetLocalInt(OBJECT_SELF,"task",5);
        //SetLocalInt(OBJECT_SELF,"back2work",1);
        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
case 5:
     // statements ...
     // npc working...
     //debug mesgs
     //ActionSpeakString("...case 5...back2work..."+IntToString(GetLocalInt(OBJECT_SELF,"back2work"))+"...task..."+IntToString(GetLocalInt(OBJECT_SELF,"task"))+"");
     if( GetLocalInt(OBJECT_SELF,"back2work") ==1 )//&& fsWP2_monk <=1.0 && fsWP2_monk >=0.01 ) //lWP2_monkLoc == GetLocation(OBJECT_SELF)&& GetLocation(OBJECT_SELF)!= lWP1_monkLoc )
        {
        //
        ActionSpeakString("...Amen...*whistleing*...Amen...Praise you Lord..."+IntToString(GetLocalInt(OBJECT_SELF,"back2work"))+"");
        //ClearAllActions();
        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW,2.9) );
        //DelayCommand(3.0,ClearAllActions() );
        DelayCommand(0.1,AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW,1.0,2.9) ) );

        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_CONJURE1,2.9) );
        //DelayCommand(6.0,ClearAllActions() );
        DelayCommand(3.0,AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_CONJURE1,1.0,2.9) ) );

        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_CONJURE2,2.9) );
        //DelayCommand(9.0,ClearAllActions() );
        DelayCommand(6.0,AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_CONJURE2,1.0,2.9) ) );

        //AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS,2.9) );
        //DelayCommand(9.0,AssignCommand(OBJECT_SELF,ActionSpeakString("OOOOMMMMM...") ) );
        DelayCommand(9.0,AssignCommand(OBJECT_SELF,ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS,1.0,7.9) ) );
        DelayCommand(9.1,AssignCommand(OBJECT_SELF,ActionSpeakString("Praise you Lord...") ) );

        DelayCommand(17.0,AssignCommand(OBJECT_SELF,ClearAllActions() ) );

         //   SetLocalInt(OBJECT_SELF,"back2work",0);
         //   SetLocalInt(OBJECT_SELF,"task",0);
         DelayCommand(17.0,ExecuteScript("mnk_pry_reset",OBJECT_SELF) );

        }else if ( GetCurrentAction() == ACTION_INVALID)
     //error ACTION_INVALID
            {
            //SetLocalInt(OBJECT_SELF,"ERROR",1);
            //debug mesgs
            //ActionSpeakString("!!!ERRORR!!!...RESET...!!!");
            ExecuteScript("mnk_pry_reset",OBJECT_SELF);
            }
     break;
//case 3:
     // statements ...
//     break;
default:
     // statements ...
     break;
}//needed for switch case

//:://////////////////////////////////////////////////////////////
//:://////////////////////////////////////////////////////////////

//end of script
}
               
               

               
            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
npc Chaos
« Reply #1 on: September 10, 2010, 06:22:39 pm »


               

Greyfort wrote...
i tried delaycommand,delaycommand execute script, im not getting it.
if I take out all delay command NPC goes to all areas prays speaks etc but never faces right way.


Just a point of note, it's unwise to use delay commands in the onheartbeat for anything.
It's very easy to cause a stack overflow if used for those scripts, it becomes one of those "just don't do it", unless there is a very specific "if" statement in front of it.

Didnt look at the whole script, as it's on the long side, but it seems you should be using tags for the way points.
I had this very same problem a few days ago. Put this under the variables tags you got: int  X2_L_WAYPOINT_SETFACING  1. (From here )

If your script has the npc going from tag to tag, the set facing portion shouldnt even need be scripted provided you are using the variable on the tags. Not sure if this is exactly what you're looking for but it may help ya narrow down some of the problems.
               
               

               


                     Modifié par Xovian, 10 septembre 2010 - 05:24 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
npc Chaos
« Reply #2 on: September 10, 2010, 10:18:35 pm »


               ok I see im not useing walk waypoints method just scripted it from scratch lol so it looks like I will have to do some research on that method, other wise npc gotoobject waypoint prays but is faceing wroung. I could use get postion of waypoint then tell npc to move to newlocation and set facing there also... LoL you always learn some thing new.  If you all have any quiker/smaller script ideas that would be great thanks.  Forgive me grammer and puntuation 27hrs 0 sleep.