// 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
        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
          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

          IfStateIs1
            DropItems
            tmpargument = selfmoney
            DropMoney
            tmpargument = 2
            SetState

        // Say it's empty...
        IfStateIs2
          // Say the chest is empty...
          tmpargument = 0
          SendMessageNear

// All done
End
