// Someone cast an unlock spell
IfOrdered
  tmpx = selforder
  tmpy = 491  // The unique code for an unlock order
  IfXIsEqualToY
    // Is it closed?
    tmpargument = 0
    IfStateIs
      // Open it up
      tmpargument = ACTIONMG
      DoAction
        tmpargument = 1
        SetState
        tmpargument = 60
        SetBumpHeight
        KeepAction
        // Spawn the trap particles
        SpawnPoof
        tmpargument = 1
        tmpdistance = 11025
        PlaySound
        // Wait a while
        tmpargument = 40
        SetTime
        // Tell the players...
        tmpargument = 3
        SendMessageNear


// Someone is trying to open it
IfBumped
  // Can they open the chest?
  SetTargetToWhoeverBumped
  IfTargetIsAPlayer		//Replaced by: IfTargetCanOpenStuff


    // Is it closed?
    tmpargument = 0
    IfStateIs


      // Are they in front?
      IfFacingTarget


        // Make target crouch
        tmpargument = ACTIONMG
        TargetDoAction



        // Open it up
        tmpargument = ACTIONMG
        DoAction
          tmpargument = 1
          SetState
          tmpargument = 60
          SetBumpHeight
          KeepAction
          // Check for disarm skill
          tmpx = 0
          tmpy = 8192  // 50% chance at 16 Dex
          tmpargument = [DISA]
          IfTargetHasSkillID
            tmpx = rand & 8191 + targetdex
          IfXIsLessThanY
            // Trap sprung
            SpawnPoof
            tmpargument = 1
            tmpdistance = 11025
            PlaySound
            tmpargument = 5
            SendMessageNear
            tmpargument = 5
            tmpdistance = EXPDARE
            GiveExperienceToTarget
          Else
            // Disarmed trap
            tmpargument = 0
            tmpdistance = 11025
            PlaySound
            tmpargument = 4
            SendMessageNear
            tmpargument = 25
            tmpdistance = EXPROLEPLAY
            GiveExperienceToTarget
          // Wait a while
          tmpargument = 40
          SetTime
    Else
      // Wait before allowing a swap
      IfTimeOut
        // Reset the timer
        tmpargument = 40
        SetTime


        // Make target crouch
        tmpargument = ACTIONMG
        TargetDoAction




        // Say it's empty...  Or check for false bottom
        IfStateIs2
          // Say the chest is empty...
          tmpargument = 0
          SendMessageNear
          // Content... 0 is normal chest, 2 is false bottom
          GetContent
          tmpargument = tmpargument & 2
          SetState
          IfStateIs2
            // It has a false bottom
            tmpargument = [DISA]
            IfTargetHasSkillID
              // Character easily finds the false bottom
              tmpargument = 1
              SendMessageNear


              // Give some experience
              tmpargument = 15
              tmpdistance = EXPROLEPLAY
              GiveExperienceToTarget


              // Figure out what to drop...  Opposite of first drop
              GetContent
              tmpargument = tmpargument & 1
              SetState
              IfStateIs0
                DropItems
              Else
                tmpargument = selfmoney
                DropMoney



              // No more false bottom
              tmpargument = 0
              SetContent
              tmpargument = 2
              SetState
            Else
              // Check wisdom until it is found
              tmpx = targetwis
              tmpy = rand & 4095 + 3584  // Need between 14 and 30 wisdom
              tmpy = rand & 4095  // Need between 0 and 16 wisdom
              IfXIsMoreThanY
                // Character finds the false bottom
                tmpargument = 1
                SendMessageNear


                // Give some experience
                tmpargument = 15
                tmpdistance = EXPSECRET
                GiveExperienceToTarget


                // Figure out what to drop...  Opposite of first drop
                GetContent
                tmpargument = tmpargument & 1
                SetState
                IfStateIs0
                  DropItems
                Else
                  tmpargument = selfmoney
                  DropMoney



                // No more false bottom
                tmpargument = 0
                SetContent
                tmpargument = 2
                SetState
          IfStateIs0
            // No false bottom
            tmpargument = 2
            SetState




        // Drop the contents
        IfStateIs1
          // Content...  0 is money, 1 is items
          GetContent
          tmpargument = tmpargument & 1
          SetState
          IfStateIs0
            tmpx = selfmoney
            tmpy = 0
            IfXIsMoreThanY
              // Drop the money
              tmpargument = selfmoney
              DropMoney
              tmpargument = 2
              SendMessageNear
            Else
              // No money in a money chest...
              tmpargument = 0
              SendMessageNear
          Else
            // Found some items
            DropItems
            tmpargument = 2
            SendMessageNear
          tmpargument = 2
          SetState

IfBumped
  IfFacingTarget
    DropItems




// All done
End
