Author Topic: Make a script happen only once  (Read 390 times)

Legacy_Randomamil

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Make a script happen only once
« on: November 21, 2011, 05:22:29 pm »


               I just need to make it so this script happens once. It works, just too well. Each SpeakString happens two to three times before it even completes. I looked on line, but I am not even sure what the terminology for this would be and have had no luck finding it.

------------------------------------------------

void main()
{
    object oJester = GetObjectByTag("TheJesterWorldSerpentInn001");
    object oPC = GetLastPerceived();

    object oDoor = GetObjectByTag("WorldSerpentInn2HuntingGrounds");

    object oWP = GetWaypointByTag("BK_WP_THEHUNTINGGROUNDSENTER");
    object oHell = GetWaypointByTag("BK_WP_NOPLACEREAL");

    if (GetIsPC(oPC))
    {
        AssignCommand(oPC, ClearAllActions());
        SetCommandable(FALSE,oPC);
        DelayCommand(0.2, SetCommandable(TRUE,oPC));
        DelayCommand(0.5, AssignCommand(oJester, ClearAllActions()));
        DelayCommand(5.0, AssignCommand(oPC, SpeakString("Your the caretaker of my new houe.")));
        DelayCommand(10.0, AssignCommand(oJester, SpeakString("Oh yes! That's me. Say, let me show you something")));
        DelayCommand(11.0, AssignCommand(oPC, ActionForceFollowObject(oJester)));
        DelayCommand(12.0, AssignCommand(oJester, ActionForceMoveToObject(oDoor)));
        DelayCommand(20.0, AssignCommand(oJester, ActionOpenDoor(oDoor)));
        DelayCommand(21.0, AssignCommand(oJester, SpeakString("Right through here if we could")));
        DelayCommand(22.0, AssignCommand(oJester, ClearAllActions()));
        DelayCommand(25.0, AssignCommand(oJester, ActionJumpToObject(oHell)));
        DelayCommand(25.1, AssignCommand(oPC, ClearAllActions()));
        DelayCommand(27.0, AssignCommand(oPC, ActionJumpToObject(oWP)));
        DelayCommand(27.1, AssignCommand(oPC, ClearAllActions()));
    }
}


------------------------------------------------

I know it is going to be something like:

if something == (some other thing) return

I just can't figure out the something and the some other thing... 
               
               

               


                     Modifié par Randomamil, 21 novembre 2011 - 05:29 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Make a script happen only once
« Reply #1 on: November 21, 2011, 05:56:48 pm »


               That should do it. I have removed the last command (ClearAllActions() for oPC) since it's probably not needed. The code could probably be simplified further, if the owner of the script was known.

void main()
{
    object oPC = GetLastPerceived();
    if(!GetIsPC(oPC)) return;
    if(GetLocalInt(oPC, "JesterDone")) return;

    object oJester = GetObjectByTag("TheJesterWorldSerpentInn001");
    object oDoor = GetObjectByTag("WorldSerpentInn2HuntingGrounds");
    object oWP = GetWaypointByTag("BK_WP_THEHUNTINGGROUNDSENTER");
    object oHell = GetWaypointByTag("BK_WP_NOPLACEREAL");

    AssignCommand(oPC, ClearAllActions());
    SetCommandable(FALSE,oPC);
    DelayCommand(0.2, SetCommandable(TRUE,oPC));
    DelayCommand(0.5, AssignCommand(oJester, ClearAllActions()));
    DelayCommand(5.0, AssignCommand(oPC, SpeakString("Your the caretaker of my new houe.")));
    DelayCommand(10.0, AssignCommand(oJester, SpeakString("Oh yes! That's me. Say, let me show you something")));
    DelayCommand(11.0, AssignCommand(oPC, ActionForceFollowObject(oJester)));
    DelayCommand(12.0, AssignCommand(oJester, ActionForceMoveToObject(oDoor)));
    DelayCommand(20.0, AssignCommand(oJester, ActionOpenDoor(oDoor)));
    DelayCommand(21.0, AssignCommand(oJester, ActionSpeakString("Right through here if we could")));
    DelayCommand(22.0, AssignCommand(oJester, ClearAllActions()));
    DelayCommand(25.0, AssignCommand(oJester, ActionJumpToObject(oHell)));
    DelayCommand(25.1, AssignCommand(oPC, ClearAllActions()));
    DelayCommand(27.0, AssignCommand(oPC, ActionJumpToObject(oWP)));
    AssignCommand(GetModule(), DelayCommand(29.0, DeleteLocalInt(oPC, "JesterDone")));
    SetLocalInt(oPC, "JesterDone", TRUE);
}


Kato
               
               

               


                     Modifié par Kato_Yang, 21 novembre 2011 - 06:08 .
                     
                  


            

Legacy_Randomamil

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Make a script happen only once
« Reply #2 on: November 21, 2011, 06:07:02 pm »


               Oh yeah that did it. I am going to archive the if-statements you used (I don't what those are actually called).

The owner is "TheJesterWorldSerpentInn001" and it is set as OnConversation. I wanted a this to start when the player clicked on The Jester with out actually going into dialogue. If you can make it simpler that would be awesome!

Also, is there any way to make it so that once the script starts the player loses control over their character until the script ends?
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Make a script happen only once
« Reply #3 on: November 21, 2011, 06:23:45 pm »


               Since the owner of the script is oJester, you don't need to retrieve it with GetObjectByTag(), it is OBJECT_SELF, and it does not need to be assigned actions through AssignCommand(). So this should do the same thing but it's simplified and faster.


void main()
{
    object oPC = GetLastPerceived();
    if(!GetIsPC(oPC)) return;
    if(GetLocalInt(oPC, "JesterDone")) return;

    object oDoor = GetObjectByTag("WorldSerpentInn2HuntingGrounds");
    object oWP = GetWaypointByTag("BK_WP_THEHUNTINGGROUNDSENTER");
    object oHell = GetWaypointByTag("BK_WP_NOPLACEREAL");

    AssignCommand(oPC, ClearAllActions());
    SetCommandable(FALSE,oPC);
    DelayCommand(4.5, SetCommandable(TRUE,oPC));
    DelayCommand(5.0, AssignCommand(oPC, SpeakString("Your the caretaker of my new houe.")));
    DelayCommand(10.0, ActionSpeakString("Oh yes! That's me. Say, let me show you something"));
    DelayCommand(11.0, AssignCommand(oPC, ActionForceFollowObject(OBJECT_SELF)));
    DelayCommand(12.0, ActionForceMoveToObject(oDoor));
    DelayCommand(20.0, ActionOpenDoor(oDoor));
    DelayCommand(21.0, ActionSpeakString("Right through here if we could"));
    DelayCommand(25.0, ActionJumpToObject(oHell));
    DelayCommand(25.1, AssignCommand(oPC, ClearAllActions()));
    DelayCommand(27.0, AssignCommand(oPC, ActionJumpToObject(oWP)));
    AssignCommand(GetModule(), DelayCommand(29.0, DeleteLocalInt(oPC, "JesterDone")));
    SetLocalInt(oPC, "JesterDone", TRUE);
}


Kato
               
               

               


                     Modifié par Kato_Yang, 21 novembre 2011 - 06:26 .
                     
                  


            

Legacy_Randomamil

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Make a script happen only once
« Reply #4 on: November 21, 2011, 06:27:24 pm »


               That is going to make this whole process a lot easier. You are a saint my good man. Is there a way to +1 you are something?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Make a script happen only once
« Reply #5 on: November 21, 2011, 07:32:00 pm »


               If you are placing that script in the OnConversation event, You will need a filter to make sure ir does not fire every time he hears something.   Or at least make sure that he is not listening.