// 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
        tmpargument = 0
        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
  IfTargetCanOpenStuff

    // Is it closed?
    tmpargument = 0
    IfStateIs

      // Are they in front?
      IfFacingTarget

        // Make target crouch
        tmpargument = ACTIONMG
        TargetDoAction

        // Give some experience
        tmpargument = 5
        tmpdistance = EXPDARE
        GiveExperienceToTarget

        // Open it up
        tmpargument = ACTIONMG
        DoAction
          tmpargument = 1
          SetState
          tmpargument = 60
          SetBumpHeight
          KeepAction
          tmpargument = 0
          tmpdistance = 11025
          PlaySound
          // Wait a while
          tmpargument = 40
          SetTime
          // Tell the players...
          tmpargument = 4
          SendMessageNear
    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

// All done
End
