// Make it stay open or close
IfSpawned
  KeepAction
  tmpargument = passage
  ClosePassage

//Open door and close it
IfTimeOut
  KeepAction
  tmpargument = 10
  SetTime
  tmpargument = passage + 1
  SetTargetToWhoeverIsInPassage
  tmpargument = 0
  IfContentIs			//Unlocked door
    IfTargetCanOpenStuff	//Only open for intelligent creatures
      tmpargument = passage
      OpenPassage
    Else 
      tmpargument = passage
      ClosePassage

  tmpargument = 1
  IfContentIs				//Goldkey door
    tmpargument = passage + 1
    tmpdistance = [KEYA]
    SetTargetToPassageID
      IfTargetCanOpenStuff
        tmpargument = [KEYA]
        CostTargetItemID
          tmpargument = 0
          SendMessageNear
          tmpargument = 10
          tmpdistance = EXPSECRET
          GiveExperienceToTarget
          tmpargument = passage
          OpenPassage
    Else
      tmpargument = passage
      IfPassageOpen
        DoNothing
      Else
        SetTargetToWhoeverIsInPassage
        IfTargetIsAPlayer
          tmpargument = 1
          SendMessageNear
          tmpargument = 200
          SetTime

  tmpargument = 2              
  IfContentIs			//Prismatic key door
    tmpargument = passage + 1
    tmpdistance = [KEYP]
    SetTargetToPassageID
      tmpargument = [KEYP]
      CostTargetItemID
        tmpargument = 10
        tmpdistance = EXPSECRET
        GiveExperienceToTarget
        tmpargument = 0
        SendMessageNear
        tmpargument = passage
        OpenPassage
        tmpdistance = [EVIL]
        tmpargument = [ATTA]
        OrderSpecialID
    Else
      tmpargument = passage
      IfPassageOpen
        DoNothing
      Else			//Tell its locked
        SetTargetToWhoeverIsInPassage
        IfTargetIsAPlayer
          tmpargument = 1
          SendMessageNear
          tmpargument = 200
          SetTime

IfOrdered
  tmpx = selforder
  tmpy = 491  // The unique code for an unlock order
  IfXIsEqualToY
    tmpargument = 3
    SendMessageNear

// Handle the animation and sound
tmpargument = passage 	// Is the passage clear?
IfPassageOpen			// 
  tmpargument = 0		  //
  IfStateIs			  // State 0 ( Closed )
    tmpargument = ACTIONMG	    //
    DoAction			    //
      tmpargument = 1		      // Open it
      SetState			      //
      tmpargument = 0		      //
      tmpdistance = 11025	      //
      PlaySound			      //
Else
  tmpargument = 1		  //
  IfStateIs			  // State 1 ( Open )
    tmpargument = ACTIONMJ	    //
    DoAction			    //
      tmpargument = 0		      // Close it
      SetState			      //
      tmpargument = 1		      //
      tmpdistance = 11025	      //
      PlaySound			      //

End				// Finished with this character
