//The different states:
//0: Closed
//1: Open
//Content equals to number of keys used to open the door
//------------------------------------------------------------------
//Just in case
IfSpawned
  tmpargument = passage
  ClosePassage

//------------------------------------------------------------------
// Someone cast an unlock spell
IfOrdered
  tmpx = selforder
  tmpy = 491  			// The unique code for an unlock order
  IfXIsEqualToY
    tmpargument = 0		    // Is it closed?
    IfStateIs
      tmpargument = 2
      SendMessageNear		//Tell it dint work
      PlaySound

//------------------------------------------------------------------
//Open if both keys are used
IfOrdered
  tmpx = selforder
  tmpy = [OPEN]
  IfXIsEqualToY				//Someone used a key
    GetContent
    tmpargument = tmpargument +1
    SetContent				//Number of keys used +1
    tmpx = tmpargument
    tmpy = 2
    IfXIsEqualToY			//Used enough keys to open?
      tmpargument = passage
      OpenPassage			//Yep
      tmpargument = 1
      SendMessageNear

//------------------------------------------------------------------
// Handle the animation and sound
tmpargument = passage	// Is the passage clear?
IfPassageOpen			//
  IfStateIs0			  // State 0 ( Closed )
    tmpargument = ACTIONMG	    //
    DoAction			    //
      tmpargument = 1		      // Open it
      SetState			      //
      tmpargument = 1		      //Spooky sounds
      PlayFullSound
      tmpargument = 0
      PlayFullSound
      KeepAction
      tmpargument = 15		//Boss music theme
      tmpdistance = 0
      PlayMusic
Else
  IfStateIs1			  // State 1 ( Open )
    tmpargument = ACTIONMJ
    DoAction
      tmpargument = 0		      // Close it
      SetState
      KeepAction

//------------------------------------------------------------------
End				// Finished with this character
//------------------------------------------------------------------
