Author Sticky: Post Working Scripts Here
Sunthas Posted: Thursday, 04 July 07:03AM
1. Door Puzzle

2. This Script is designed to Force the players into doing something other than hack in slash while running around in a dungeon. There are 5 Levers and 4 Doors. The doors open and close in different patterns until the right combination of the levers is choosen then all 4 doors open up allowing the characters to pass through the doors. I recommend putting all 4 doors in a row.

3. This script is pretty ugly but it works. I will be working on a better version as I get further into my module. To make the Puzzle harder you could remove all door open commands and make the door open checks door lock checks. Then the players would have to check each door with each lever combination. See other notes in the script file.


NWScript:
//*******************************

// Door Puzzle

//*******************************

// Created by Sunthas

// email: neathon@hotmail.com

// Version 1.0

// 7-3-2002

// 4 Doors in Puzzle

// 5 Levers in Puzzle

// This code is attatched to the on_used script of each Lever.

// oDoor1 through oDoor4 is the name of the 4 doors.

// oLever1 through oLever5 is the name of the 5 levers.

// Be sure to set the hardness of the doors high enough that the players don't

// just break them down or mark them plot items. Also be sure to set the doors as locked and unpickable.

// Lastly make sure the players have a real method of finding your lever pattern

// otherwise they might just quit your game. 5 levers is 32 combinations.

// Also put your levers starting position as "Deactivated" in your module.

// Note:

// I'm sure this code could be cleaned up quite a bit. This is my first

// real contribution to something interesting that requires script.

void main()

{

  object oDoor1 = GetObjectByTag ("FencePuzzleGate1");

  object oDoor2 = GetObjectByTag ("FencePuzzleGate2");

  object oDoor3 = GetObjectByTag ("FencePuzzleGate3");

  object oDoor4 = GetObjectByTag ("FencePuzzleGate4");

  object oLever1 = GetObjectByTag ("FloorLever1");

  object oLever2 = GetObjectByTag ("FloorLever2");

  object oLever3 = GetObjectByTag ("FloorLever3");

  object oLever4 = GetObjectByTag ("FloorLever4");

  object oLever5 = GetObjectByTag ("FloorLever5");

  int Lever1;

  int Lever2;

  int Lever3;

  int Lever4;

  int Lever5;

  if ( GetLocalInt( OBJECT_SELF, "m_bActivated" ) != TRUE )

  {

    //Activate the Lever and Mark the Lever as Activated.

    SetLocalInt( OBJECT_SELF, "m_bActivated", TRUE );

    PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE );

  }

  else

  {

   //Deactivate the Lever and Mark the Lever as Deactivated.

    SetLocalInt( OBJECT_SELF, "m_bActivated", FALSE );

    PlayAnimation( ANIMATION_PLACEABLE_DEACTIVATE );

  }

// Get the status of the other levers.

  Lever1 = GetLocalInt (oLever1,"m_bActivated");

  Lever2 = GetLocalInt (oLever2,"m_bActivated");

  Lever3 = GetLocalInt (oLever3,"m_bActivated");

  Lever4 = GetLocalInt (oLever4,"m_bActivated");

  Lever5 = GetLocalInt (oLever5,"m_bActivated");

// This sets the lever pattern needed to insure all 4 doors are open at once.

// True = Lever Activated. False = Lever Deactivated.

  if (Lever1 == TRUE && Lever2 == FALSE && Lever3 == FALSE && Lever4 == TRUE && Lever5 == FALSE)

  {

   SetLocked(oDoor1, FALSE);

   ActionOpenDoor(oDoor1);

   SetLocked(oDoor2, FALSE);

   ActionOpenDoor(oDoor2);

   SetLocked(oDoor3, FALSE);

   ActionOpenDoor(oDoor3);

   SetLocked(oDoor4, FALSE);

   ActionOpenDoor(oDoor4);

  }

// The rest of the script just puts the doors in different positions insuring that

// at no single point in time are all 4 doors open. It currently operates on the pattern

// of Door1 open, then Door2 open, then Door3 open, then Door4 Open. This probably should be

// accomplished with a random number generator and then a simple check to make sure at

// least one door is closed. But this will work for now.

  else

  {

    if (GetIsOpen(oDoor1))

    {

     ActionCloseDoor(oDoor1);

     SetLocked(oDoor1, TRUE);

     SetLocked(oDoor2, FALSE);

     ActionOpenDoor(oDoor2);

     SetLocked(oDoor3, FALSE);

     ActionOpenDoor(oDoor3);

     ActionCloseDoor(oDoor4);

     SetLocked(oDoor4, TRUE);

    }

    else if (GetIsOpen(oDoor2))

    {

     ActionCloseDoor(oDoor1);

     SetLocked(oDoor1, TRUE);

     ActionCloseDoor(oDoor2);

     SetLocked(oDoor2, TRUE);

     SetLocked(oDoor3, FALSE);

     ActionOpenDoor(oDoor3);

     SetLocked(oDoor4, FALSE);

     ActionOpenDoor(oDoor4);

    }

    else if (GetIsOpen(oDoor3))

    {

     ActionCloseDoor(oDoor1);

     SetLocked(oDoor1, TRUE);

     ActionCloseDoor(oDoor2);

     SetLocked(oDoor2, TRUE);

     ActionCloseDoor(oDoor3);

     SetLocked(oDoor3, TRUE);

     SetLocked(oDoor4, FALSE);

     ActionOpenDoor(oDoor4);

    }

    else if (GetIsOpen(oDoor4))

    {

     SetLocked(oDoor1, FALSE);

     ActionOpenDoor(oDoor1);

     ActionCloseDoor(oDoor2);

     SetLocked(oDoor2, TRUE);

     SetLocked(oDoor3, FALSE);

     ActionOpenDoor(oDoor3);

     ActionCloseDoor(oDoor4);

     SetLocked(oDoor4, TRUE);

    }

    else

    {

     SetLocked(oDoor1, FALSE);

     ActionOpenDoor(oDoor1);

     SetLocked(oDoor2, FALSE);

     ActionOpenDoor(oDoor2);

     ActionCloseDoor(oDoor3);

     SetLocked(oDoor3, TRUE);

     ActionCloseDoor(oDoor4);

     SetLocked(oDoor4, TRUE);

    }

  }

} //end Main



If your having problems getting this to work feel free to email me at neathon@hotmail.com or message me here and I will do what I can to help. I want to thank everyone else for posting their scripts and exported files, they've really helped me learn this stuff.

-Sunthas