Aller au contenu

Photo

Script fire nly once


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

#1
andysks

andysks
  • Members
  • 1 655 messages
So I have a script for a hidden locked door in my campaign, where you have to pull multipull levers in order to open the door. I've written a script with the help of Lilac's as always, to set local intergers every time you pull a lever, and once you have every lever pulled, you should see convo from the door that it's now unlocked. And now to the point : evertime you pull the lever, you set an interger +1 . If the player pulls the same lever multiple times, that would take the number higher than I want it. I tested it, and even though I have put a Fire Only Once on the script, the message appears everytime you pull the lever.I give here the script, and maybe you understand what I mean if it's too complicated, or my english is messed up :D.

void main()
{
    // * note that nActive == 1 does  not necessarily mean the placeable is active
    // * that depends on the initial state of the object
    int nActive = GetLocalInt (OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE");
    // * Play Appropriate Animation
    if (!nActive)
    {
      ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
    }
    else
    {
      ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
    }
    // * Store New State
    SetLocalInt(OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE",!nActive);
    int nValue;
    // Get the creature who triggered this event.
    object oPC = GetLastUsedBy();

    // Have text appear over the PC's head.
    FloatingTextStringOnCreature("You hear a heavy clicking sound from deep in the sewers.", oPC);

    // Set a local integer.
    nValue = GetLocalInt(oPC, "lever_sewer") + 1;
    SetLocalInt(oPC, "lever_sewer", nValue);
    // Only fire once.
    if ( GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF)) )
        return;
    SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
}

#2
kamal_

kamal_
  • Members
  • 5 260 messages
You're doing stuff before checking for the DoOnce...

#3
MarshallV

MarshallV
  • Members
  • 43 messages
May be overkill for what you're doing but the Legends SE plugin (part of the quest plugin) can do things like this without needing to script (see about 4:45 in):

http://www.youtube.c...mkPVQHVs#t=270s

The whole SE system can be viewed here (Video 1 & 2 is regarding Quests for PW, you can skip to video 3 to see the SE plugin and how it works - you can use the SE plugin piece in stand alone modules):

http://www.youtube.c...ZJpm5hjHMcrONUB

M

Modifié par MarshallV_ForgotMyAccount, 20 juin 2013 - 12:49 .


#4
andysks

andysks
  • Members
  • 1 655 messages
I kinda thought it would be time-wise wrong.Thanks for the help I'll also check the videos and I'm certain it will work.

#5
Tchos

Tchos
  • Members
  • 5 080 messages
Overkill or not, I'm continually impressed by your growing collection of useful plugins, Marshall.

#6
andysks

andysks
  • Members
  • 1 655 messages
I had never heard of this plugin but now I watched a couple of these videos...I have to say...wow.This looks so simple and good to use.Perfect !And yes, overkill or not, I have to use it next time I will need something like that.As it turned out, putting the OnlyOnce was all that was needed from my script.

#7
Darin

Darin
  • Members
  • 282 messages
void main()
{
   //use a local integer to determine if object has been used.
   //note entire script is within the if statement of this integer
   // also note that you can CHANGE the integer through script
   // to allow it to run again.
   if(!(GetLocalInt(OBJECT_SELF,"nUsed")==1))
      {
         //Now set the integer nUsed = 1 to make sure it doesn't run again...
         SetLocalInt(OBJECT_SELF,"nUsed",1);

         // * note that nActive == 1 does not necessarily mean the placeable is active
         // * that depends on the initial state of the object
         int nActive = GetLocalInt (OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE");
         // * Play Appropriate Animation
         //Also cleaned up the if/else, since each only has one function, no {}s needed
         if (!nActive)
            ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
         else
            ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);

         // * Store New State
         SetLocalInt(OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE",!nActive);
         int nValue;
         // Get the creature who triggered this event.
         object oPC = GetLastUsedBy();

         // Have text appear over the PC's head.
         FloatingTextStringOnCreature("You hear a heavy clicking sound from deep in the sewers.", oPC);

         // Set a local integer.
         nValue = GetLocalInt(oPC, "lever_sewer") + 1;
         SetLocalInt(oPC, "lever_sewer", nValue);
      }
}

Modifié par EpicFetus, 21 juin 2013 - 04:17 .


#8
andysks

andysks
  • Members
  • 1 655 messages
Thank you EpicFetus but I made it work in the end.I just had to put the DoOnce before the actions and it all worked fine.But I appreciate your help no matter what :).

#9
Tchos

Tchos
  • Members
  • 5 080 messages
I always found the "DoOnce" name confusing early on, because it sounds like a command, not a flag. Like something it should do in the future, not whether it has already done it. DoOnce = TRUE -- "okay, I will then." Once I learned that the names in most cases are arbitrary, I switched to names that made more sense to me, like "IsDone", instead.

#10
Morbane

Morbane
  • Members
  • 1 883 messages

void SetIsDone(object oObject, string sFunction, int nFlag = TRUE)
{
          SetLocalInt(oObject, sFunction, nFlag);
          //SendMessageToPC(GetFirstPC(FALSE), sFunction + " Set as Done");
}

defaults to TRUE - make FALSE to un-done it

int GetIsDone(object oObject, string sFunction)
{
           if(GetLocalInt(oObject, sFunction) != TRUE)
          {
                         //SendMessageToPC(GetFirstPC(FALSE), sFunction + " Not Done");
                         return FALSE;
          }
          //SendMessageToPC(GetFirstPC(FALSE), sFunction + " Is Done");
          return TRUE;
}


:wizard:

Modifié par Morbane, 22 juin 2013 - 02:13 .


#11
andysks

andysks
  • Members
  • 1 655 messages
I was talking with a friend of mine yesterday, he is a programmer. When I explained to him what I want to do he suggested the same method Morbane has posted :) .He also said that another method could be with a binary code, if you want certain levers open and others not.But I think this is exactly what the Legends plugin does without us having to write anything.