Author Topic: Co-Op Lever Puzzle  (Read 320 times)

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« on: August 14, 2011, 04:52:52 am »


               I'm not very any good with scripting, so hoping someone can give me a hand here.

I'm in need of a script for a set of levers so that when used, they open a door when the specified set (2, 3 or 4) are pulled at the same time. I want it so that they have the option range of requiring 2 - 4 levers because the idea is to spread several areas around the module (think secret treasure caches) which can only be accessed by 2, 3 or 4 players (depending on the cache in question).

Thanks in advance:)
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #1 on: August 14, 2011, 05:14:49 am »


               I actually created the same thing in my module, but only for two levers. Since you can't reasonably expect them to be pulled at exactly the same time, there's a short delay before the level deactivates again. I had a chest nearby spawn haste potions if a lone player failed to activate the lever, and made the time delay just long enough for a hasted PC to have a chance of pulling both. If a solo player has a henchman however, the henchman will run to pull the lever.

If you want to remove the option of using haste to pull both, just make sure the variable fDelay is lower, or space the levers further apart.

To make it work for more levers, as far as I remember you can just change the if statement from ==2 to another value. In that case, the henchman section would be rendered useless, so you'd be better just deleting that bit.

Here's the script (easier than posting it on the forums)
               
               

               


                     Modifié par _six, 14 août 2011 - 04:19 .
                     
                  


            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #2 on: August 14, 2011, 05:22:33 am »


               I'll take a look, thanks a lot.

I'm designing my module with 2-4 real players, so that shouldn't be a problem ^.^
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #3 on: August 14, 2011, 05:36:12 am »


               Some stupid questions, but like i said, i'm not very good with scripts, lol.

float fDelay = 2.4f;


What does 2.4 equals in real time? 2.4mins?

object oDoor = GetNearestObjectByTag("dungleverdoor");


I assume thats the Door's tag, right? just making sure.

       SetLocalInt(oArea, "dunglever", GetLocalInt(oArea, "dunglever")+1);
       SetLocalInt(oArea, "dlattempts", GetLocalInt(oArea, "dlattempts")+1);


Are these just some scripting work i don't need to bother with? or do i need to set a variable someplace?

           object oLev;
           if(GetTag(OBJECT_SELF)=="dunglever1")
           {    oLev = GetNearestObjectByTag("dunglever2");
           }
           else oLev = GetNearestObjectByTag("dunglever1");


I'll assume these are the tags for the levers, right? so i'ld be looking to add all the info and stuff for 2 more levers to make the script work for more then 2, right?

if(GetLocalInt(oArea, "dunglever") == 2)
       {
           SetLocked(oDoor, FALSE);
           AssignCommand(oDoor, ActionOpenDoor(oDoor));
           DelayCommand(0.5f, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
           DelayCommand(0.5f, SetLocalInt(OBJECT_SELF, "active", FALSE));
           DelayCommand(0.5f, SetLocalInt(oArea, "dunglever", 0));


Again, i'll assume this is the if statement you mentioned?

Sorry for the trouble, just want to verify that i know what i think i know....or that maybe i'm worse then i thought i was o.o
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #4 on: August 14, 2011, 12:16:58 pm »


               

Shiek2005 wrote...

Some stupid questions, but like i said, i'm not very good with scripts, lol.

float fDelay = 2.4f;


What does 2.4 equals in real time? 2.4mins?

2.4 seconds. That's the amount of time it takes hasted to get between my levers where I placed them. Placing the levers far apart will rule that hasting option out.

object oDoor = GetNearestObjectByTag("dungleverdoor");


I assume thats the Door's tag, right? just making sure.

Yes.

       SetLocalInt(oArea, "dunglever", GetLocalInt(oArea, "dunglever")+1);
       SetLocalInt(oArea, "dlattempts", GetLocalInt(oArea, "dlattempts")+1);


Are these just some scripting work i don't need to bother with? or do i need to set a variable someplace?

"dunglever" stores how many levers are 'pulled' at any one time in an area. So that's necessary in the script, otherwise it wouldn't have any idea how many other levers are pulled in the area. You'd need to replace oArea with a nearby placeable (where oArea is first mentioned) if you're planning to have more than one lever puzzle in the area.

I could probably have come up with a better shorthand for "dungeon" than "dung".

"dlattempts" is used to track how many failures the player(s) is having, and only really useful for spawning the haste potions. So it's not really particularly important. Just deleting that one line will prevent any haste potions from appearing.


           object oLev;
           if(GetTag(OBJECT_SELF)=="dunglever1")
           {    oLev = GetNearestObjectByTag("dunglever2");
           }
           else oLev = GetNearestObjectByTag("dunglever1");


I'll assume these are the tags for the levers, right? so i'ld be looking to add all the info and stuff for 2 more levers to make the script work for more then 2, right?

The entire "object oHen..." block of code is only used for instructing henchmen to pull levers. If you don't need to make henchmen pull levers too, it's not necessary. Everything from the // If player has henchman... comment up to the // If two levers have been pulled... comment.

if(GetLocalInt(oArea, "dunglever") == 2)
       {
           SetLocked(oDoor, FALSE);
           AssignCommand(oDoor, ActionOpenDoor(oDoor));
           DelayCommand(0.5f, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
           DelayCommand(0.5f, SetLocalInt(OBJECT_SELF, "active", FALSE));
           DelayCommand(0.5f, SetLocalInt(oArea, "dunglever", 0));


Again, i'll assume this is the if statement you mentioned?

Yes, this is the part of the code fired when the levers are pulled successfully. The ==2 there should work changed to ==3 to work with 3 levers, and also create a mildly humourous image in my post.
               
               

               


                     Modifié par _six, 14 août 2011 - 11:20 .
                     
                  


            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #5 on: August 14, 2011, 04:52:26 pm »


               Ok, thanks, that helps, last question to see if i got everything right...i just need to tag the levers "dunglever" right?
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #6 on: August 14, 2011, 10:18:53 pm »


               Without the henchman part, it doesn't matter what you tag your levers, as long as they have the right OnUsed script.
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #7 on: August 15, 2011, 02:11:34 am »


               Ok, thanks a lot for the help. I'll give the script a try and see how it goes '^_^'
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Co-Op Lever Puzzle
« Reply #8 on: August 15, 2011, 02:55:00 am »


               Works great...thanks a lot '^_^'

Just tested with 4 levers, works flawlessly.