Author Topic: Help with a few basic scripts please! :)  (Read 284 times)

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Help with a few basic scripts please! :)
« on: May 26, 2011, 04:13:51 am »


               HELP!
I've tried figuring out these on my own, but I am stumped! I'm still a total noob, so I was hoping people could fix these scripts for me!

1.) The first script is in an area trigger, activated OnEnter. I want the NPC to initiate dialogue with the PC, it works fine, BUT I want them only to do it once. ---instead they walk up to the PC every time I enter the trigger----


  •      int StartingConditional()
  • {
  •     // Inspect local variables
  •     if(!(GetLocalInt(GetPCSpeaker(), "LOCAL_INT_TAG1") == TRUE)) return FALSE;
  •     return TRUE;
  • }
  • void main()
  • {
  •   object oNPC = GetObjectByTag("NPC_TAG");
  •   object oPC = GetEnteringObject();
  •   if(GetIsPC(oPC) &&
  •   //GetLocalInt(oPC,"Dlg_Init_" + GetTag(oNPC)) == FALSE &&
  •   !IsInConversation(oNPC))
  •   {
  •     AssignCommand(oPC,ClearAllActions());
  •     AssignCommand(oNPC,ClearAllActions());
  •     AssignCommand(oNPC,ActionMoveToObject(oPC));
  •     AssignCommand(oNPC,ActionStartConversation(oPC));
  •   }
  •   SetLocalInt(GetPCSpeaker(), "LOCAL_INT_TAG1", TRUE);
  • }
2. The second problem I have is modifying a floaty text above NPC script. I have a basic script that works fine:


  • void main()
  • {
  •     object oPC = GetEnteringObject();
  •     object oDisplay = GetObjectByTag("DISPLAY_HERE");
  •     if (GetLocalInt(oPC, "Saw_Trigger_Text") == FALSE)
  •     {
  •         AssignCommand(oDisplay, SpeakString("The weather is terrible today"));
  •         SetLocalInt(oPC, "Saw_Trigger_Text", TRUE);
  •       }
  •     }
This works fine, but what I want is a script that, every time the PC triggers it, a new piece of floaty text is spoken. (Between 2 NPCs) and when it reaches the last one, it resets back to the beginning. For example:
  • NPC1: "The weather is terrible today."
  • NPC2: "You can say that again, I'm getting soaked standing here in the rain."
  • NPC1: "Good point. Why are we talking outside?"
  • NPC2: "Beats me...."
  • *loops back to the start*
So every time the PC enters the trigger, a new piece is said, and after the fourth one, it loops back to the start.

I am a big scripting noob, so if anyone could help me with these two scripts, that would be amazing!!! 

'<img'>:D:D:D
 
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Help with a few basic scripts please! :)
« Reply #1 on: May 26, 2011, 04:52:17 am »


               This will probably work for the 2nd script, but you have to do one thing first.  Right-click the trigger in the toolset and select variables.  Add this variable:  Convo|Int|1

void main()
{
   object oPC = GetEnteringObject();
   //do nothing if whatever enters the trigger is not a PC
   if( !GetIsPC(oPC) ) return;

   //Search for the NPC that will be talking by it's TAG
   object oDisplay = GetNearestObjectByTag("NPC_TAG_GOES_HERE");

   //Look for a variable on the trigger named "Convo" and set i equal to it
   //If i = 6, then set i back to 1
   int i = GetLocalInt(OBJECT_SELF, "Convo");
   if( i == 6 ) i == 1;

   string sText;
   //setup 5 possible things for sText to be
   switch(i)
   {
       case 1: sText = "The weather is nice today."; break;
       case 2: sText = "See that tornado tear across the desert this morning?." break;
       case 3: sText = "Cows are all facing west, storm must be coming." break;
       case 4: sText = "Your face is so ugly it just ruined this beautiful day." break;
       case 5: sText = "I need a drink." break;
   }
   //have the trigger assign the NPC to speak sText
   AssignCommand(oDisplay, SpeakString(sText));

   //increment i and set the Convo variable on the trigger to its new value
   //so that next time the next message will be spoken
   i++;
   SetLocalInt(OBJECT_SELF, "Convo", i);
}
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Help with a few basic scripts please! :)
« Reply #2 on: May 26, 2011, 04:55:58 am »


               This should work for the 1st script:

void main()
{
object oNPC = GetObjectByTag("NPC_TAG");
object oPC = GetEnteringObject();
//This checks for a variable on the player called LOCAL_INT_TAG1
//If it is set to TRUE, because you already spoke to the NPC, then quit
if( GetLocalInt(oPC, "LOCAL_INT_TAG1") == TRUE ) return;

if(GetIsPC(oPC) && !IsInConversation(oNPC))
{
AssignCommand(oPC,ClearAllActions());
AssignCommand(oNPC,ClearAllActions());
AssignCommand(oNPC,ActionMoveToObject(oPC));
AssignCommand(oNPC,ActionStartConversation(oPC));
}
SetLocalInt(GetPCSpeaker(), "LOCAL_INT_TAG1", TRUE);
}

For both of these, you'll have to make sure that the TAGs of the NPCs match what is in the script or vice versa.  If they don't match exactly, the script will attempt to locate something that doesn't exist and it will appear that nothing is happening.  The same goes for the variable names in the GetLocalInt() and SetLocalInt() functions

Good luck.
               
               

               


                     Modifié par Terrorble, 26 mai 2011 - 03:58 .
                     
                  


            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Help with a few basic scripts please! :)
« Reply #3 on: May 27, 2011, 03:31:53 am »


               Hi thanks for your help '<img'>'<img'>

Some slight problems though, '<img'>

with the first script you posted, it doesn't compile.
On the "case2" line, it says it needs a semi-colon despite there already being one there.

And with the second script you posted, it had the problem that the script would cause the NPC to initiate conversation every time I entered it, not just the first.

For some reason it fails to set the local variable to TRUE. I know this is the problem, because I made another trigger with a script whose only function was to set the variable to TRUE and once that was entered, the NPC would no longer try to start a conversation when initial script fired again. (If that's explained clearly)

Sometimes I wonder if there's problems with my Toolset, is it possible that it can be corrupted so scripts don't work the way they should. The only Hak Packs I use are CEP. I also think I might have problems due to not tagging all of my triggers uniquely, which is something I am now cleaning up.

Anyway thanks for the help, if you could see if the first script compiles in your Toolset, that would be great ':wizard:'
               
               

               


                     Modifié par Lethal_Bottle, 27 mai 2011 - 02:34 .
                     
                  


            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Help with a few basic scripts please! :)
« Reply #4 on: May 27, 2011, 04:25:55 am »


               

Lethal_Bottle wrote...

with the first script you posted, it doesn't compile.
On the "case2" line, it says it needs a semi-colon despite there already being one there.


For the lines that have case 2 - case 5, add a semi-color before the word "break" (just like at the end of the case 1 line).

And with the second script you posted, it had the problem that the script would cause the NPC to initiate conversation every time I entered it, not just the first.

For some reason it fails to set the local variable to TRUE. I know this is the problem, because I made another trigger with a script whose only function was to set the variable to TRUE and once that was entered, the NPC would no longer try to start a conversation when initial script fired again. (If that's explained clearly)


Change this line:

SetLocalInt(GetPCSpeaker(), "LOCAL_INT_TAG1", TRUE);

To:

SetLocalInt(oPC, "LOCAL_INT_TAG1", TRUE);
               
               

               


                     Modifié par _Knightmare_, 27 mai 2011 - 03:27 .