Author Topic: Problem with trigger that makes NPCs speak strings  (Read 375 times)

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« on: February 05, 2011, 08:34:44 pm »


               I'm having trouble with one of my triggers. I have it set up so that when you walk on the trigger (which is painted around the two NPCs in question) two NPCs launch into an argument in which their dialog appears over their heads. It's a long exchange, and at first I could only get the last things they said to appear, and I realized the words were being processed way too fast. So I used DelayCommand for each line they spoke, but now they only say the first part of the exchange and stop.

Not sure what I'm doing wrong.

The script looks like this:

____________

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

if (DoOnce==TRUE) return;

SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

DelayCommand(2.0, AssignCommand(GetObjectByTag("NPC1"), ActionSpeakString("NPC1 speaks")));

DelayCommand(2.0, AssignCommand(GetObjectByTag("NPC2"), ActionSpeakString("NPC 2 speaks.")));

//And so on
_________________

I'm using Lilac Soul's Script Generator, which has been extremely helpful.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #1 on: February 05, 2011, 08:53:53 pm »


               I suspect that it is because their heartbeat scripts are canceling their actions from this script.
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #2 on: February 05, 2011, 08:56:02 pm »


               object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

if (DoOnce==TRUE) return;

SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

DelayCommand(2.0, AssignCommand(GetObjectByTag("NPC1"), ActionSpeakString("NPC1 speaks")));

DelayCommand(4.0, AssignCommand(GetObjectByTag("NPC2"), ActionSpeakString("NPC 2 speaks.")));

DelayCommand(6.0, AssignCommand(GetObjectByTag("NPC1"), ActionSpeakString("NPC1 speaks..again")));

DelayCommand(8.0, AssignCommand(GetObjectByTag("NPC2"), ActionSpeakString("NPC 2 speaks..Replysagain")));
/*
set up your delays as seen giving each npc a chance to speak about 2 seconds
first npc speaks after 2 secs then npc2 speaks at 4 sec and so on...
*/
//And so on

EDIT ADDED:  IF it is the default heart beat you will want to set a local var on npc and if that var true then fire your custom heart beat script "npc_talking" but keep in mind this will fire every 6seconds still so a work around that is they dont do anything on there HB untill fineshed talking then reset var to 0 and they will fire there default again, or fire talk script if propmted to.
               
               

               


                     Modifié par Greyfort, 05 février 2011 - 09:00 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #3 on: February 05, 2011, 09:36:23 pm »


               // save on file by this name..
// place this in trigger on_enter
// talk_trig_ent
void main()
{
object oPC=GetEnteringObject();
object oNPC1=GetObjectByTag("boy1");
object oNPC2=GetObjectByTag("boy2");



if (GetLocalInt(oNPC1,"Talking") ==0 && GetLocalInt(oNPC1,"Talking_started")==0 )
   {
   SetLocalInt(oNPC1,"Talking",1);
   }
/*
DelayCommand(2.0,AssignCommand(oNPC1,ActionSpeakString("you se that fish..") ) );
DelayCommand(4.0,AssignCommand(oNPC2,ActionSpeakString("no ware is it..") ) );

DelayCommand(6.0,AssignCommand(oNPC1,ActionSpeakString("in the pound there..") ) );
DelayCommand(8.0,AssignCommand(oNPC2,ActionSpeakString("OOH I see it..") ) );
*/

if (GetLocalInt(oNPC1,"Talking") ==1 && GetLocalInt(oNPC1,"Talking_started")==0 )
   {
   ExecuteScript ("NPC_TALK",oNPC1);
   }
}

// save on file by this name..
//NPC_TALK
void main()
{

object oNPC1=GetObjectByTag("boy1");
object oNPC2=GetObjectByTag("boy2");
if(GetLocalInt(oNPC1,"Talking_started")==0)
   {
   SetLocalInt(oNPC1,"Talking_started",1);
   }

DelayCommand(2.0,AssignCommand(oNPC1,ActionSpeakString("you se that fish..") ) );
DelayCommand(4.0,AssignCommand(oNPC2,ActionSpeakString("no ware is it..") ) );

DelayCommand(6.0,AssignCommand(oNPC1,ActionSpeakString("in the pound there..") ) );
DelayCommand(8.0,AssignCommand(oNPC2,ActionSpeakString("OOH I see it..") ) );


if(GetLocalInt(oNPC1,"Talking_started")==1)
   {
   SetLocalInt(oNPC1,"Talking_started",0);
   SetLocalInt(oNPC1,"Talking",0);
    // fire default heart "NW_C2_DEFAULT1"

    DelayCommand(10.0,  AssignCommand(oNPC1,  ExecuteScript( "NW_C2_DEFAULT1",oNPC1)));
    DelayCommand(10.0,  AssignCommand(oNPC2,  ExecuteScript( "NW_C2_DEFAULT1",oNPC2)));
   }
}

Note: to quickly see it work leave the heartbeat script blank you will see the npc’s talk to each other.  The trick is getting past the 6sec heartbeat so as not to keep repeating the script...or haveing it cancel out the npc talking..

these two scripts insure two npcs talk to each other, but with there heart beats gone they wont do much I supose when done talking you could have them execute default heartbeat "NW_C2_DEFAULT1"
I will look into that for ya:

EDIT ADD:
I added script in place to fire heart beat if you want it.  I forgot to add the delay before it fires heart beat.
               
               

               


                     Modifié par Greyfort, 05 février 2011 - 09:44 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #4 on: February 06, 2011, 12:42:11 am »


               I revised the previous posted scripts to insure npc fires talking script and then fires heart beat, the key is making sure when you either make a npc or place a npc you leave the script for heart beat blank.

place this script in trigger

// talk_trig_ent
// Greyfort Feb,05.2011
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void main()
{
object oPC=GetEnteringObject();
object oNPC1=GetObjectByTag("boy1");
object oNPC2=GetObjectByTag("boy2");

if ( GetIsPC(oPC)==TRUE )
{
AssignCommand(oNPC1,ClearAllActions(TRUE));
AssignCommand(oNPC2,ClearAllActions(TRUE));
//chk1
if (GetLocalInt(oNPC1,"Talking") ==0 && GetLocalInt(oNPC1,"Talking_started")==0 )
   {
   SetLocalInt(oNPC1,"Talking",1);
   }

//chk2
if (GetLocalInt(oNPC1,"Talking") ==1 && GetLocalInt(oNPC1,"Talking_started")==0 )
   {
   ExecuteScript ("NPC_TALK",oNPC1);
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//END OF SCRIPT
}

this script stands alone...

//  NPC_TALK
// Greyfort Feb,05.2011
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void main()
{

object oNPC1=GetObjectByTag("boy1");
object oNPC2=GetObjectByTag("boy2");
if(GetLocalInt(oNPC1,"Talking_started")==0)
   {
   SetLocalInt(oNPC1,"Talking_started",1);
   }
//--------------------------------------------------
//  Talk script
DelayCommand(2.0,AssignCommand(oNPC1,ActionSpeakString("You see that fish..") ) );
DelayCommand(4.0,AssignCommand(oNPC2,ActionSpeakString("No ware is it..") ) );

DelayCommand(6.0,AssignCommand(oNPC1,ActionSpeakString("In the pond there..") ) );
DelayCommand(8.0,AssignCommand(oNPC2,ActionSpeakString("OOH I see it..") ) );
//  End of Talk script

//--------------------------------------------------
//  Reset Variabes excute heartbeat...
if(GetLocalInt(oNPC1,"Talking_started")==1)
   {
   SetLocalInt(oNPC1,"Talking_started",0);
   SetLocalInt(oNPC1,"Talking",0);
   // fire default heart "NW_C2_DEFAULT1"

   DelayCommand(11.0,  AssignCommand(oNPC1,  ExecuteScript( "NW_C2_DEFAULT1",oNPC1)));

   DelayCommand(11.0,  AssignCommand(oNPC2,  ExecuteScript( "NW_C2_DEFAULT1",oNPC2)));
   }
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//END OF SCRIPT
}

If you already copied these scripts just simply copy and paste over your old ones, be sure to change oNPC1, and oNPC2 to the tag of your npc.

If ya need any more Help We are here
               
               

               


                     Modifié par Greyfort, 06 février 2011 - 12:43 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #5 on: February 06, 2011, 02:08:04 am »


               You may want to just use actions.  To keep your timming right just place all the commands into the action Que of one of the Npc's.  Making him the conductor of the fight.  Use eithee ActionWait( Fdelay)   or an animation for them to play to add your delays between things said.


void main ()
{

 object oPC = GetEnteringObject();

 if (!GetIsPC(oPC)) return;

 int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

 if (DoOnce==TRUE) return;
 SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

 object oNPC1 =  GetObjectByTag("NPC1");
 object oNPC2 =  GetObjectByTag("NPC2");

 AssignCommand(oNPC1, ActionSpeakString("NPC1 speaks"));
 AssignCommand(oNPC1, ActionWait(1.0));
 AssignCommand(oNPC1, ActionDoCommand(AssignCommand(oNPC2,ActionSpeakString("NPC 2 speaks."))));
 AssignCommand(oNPC1, ActionWait(1.0));

 AssignCommand(oNPC1, ActionSpeakString("NPC1 speaks"));
 // the playing of the animation will delay the NPC from saying the next line.
 AssignCommand(oNPC1, ActionPlayAnimation(ANIMATION_FIREFORGET_TAUNT,1.0,1.0));


 AssignCommand(oNPC1, ActionDoCommand(ActionDoCommand(AssignCommand(oNPC2,ActionSpeakString("NPC 2 speaks.")))));
 AssignCommand(oNPC1, ActionDoCommand(ActionDoCommand(ActionPlayAnimation(ANIMATION_FIREFORGET_TAUNT,1.0,1.0))));
 // Since the above animantion is not in oNPC1 action que it will not delay
 // the nexr command so we will add a wait to oNPC1.
 AssignCommand(oNPC1, ActionWait(1.0));

 // To make sure that the NPC follows all instructions we are going to make him
 // uncomandable.  We will let his last action be to make himself commandable again.
 AssignCommand(oNPC1, SetCommandable(TRUE,oNPC1));

 // now that the action que of oNPC1 is set to give commands to both NPCs
 // to speak we will make him uncommandable so the actions can not be removed.
 SetCommandable(FALSE,oNPC1);
}


               
               

               
            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Problem with trigger that makes NPCs speak strings
« Reply #6 on: February 06, 2011, 04:52:53 am »


               Hey, thanks everyone once again for the help. I really appreciated it.

I realized reading through your scripts, that the Achilles Heel of my effort was delaying each peace of dialogue to the same amount of time. I was essentially telling every string to be spoken at once, and that's exactly what happened. I didn't understand the nature of DelayCommand.

So I went back in and changed each string to be delivered two seconds after the one before as I intended (the first at 2.0, the second at 4.0, and so on.) That did the trick.

Thanks too for the info. on how to put those animations in there, that will be very useful.
               
               

               


                     Modifié par Dylan RPG, 06 février 2011 - 04:53 .