// Randomly create contents...
IfSpawned
  JoinNullTeam  // So mimics don't chase...
  tmpargument = rand % 7
  tmpy = tmpargument // Remember offset for messages
  SetState  // To make checks easier...
  IfStateIs0
    tmpx = [ROGU]
  IfStateIs1
    tmpx = [GNOM]
  IfStateIs2
    tmpx = [SOLD]
  IfStateIs3
    tmpx = [ELFF]
  IfStateIs4
    tmpx = [ADVE]
  IfStateIs5
    tmpx = [WIZA]
  IfStateIs6
    tmpx = [HEAL]
  tmpargument = 0
  SetXY  // Remember who gets it
  SetState
  tmpx = rand & 255  // Figure out type of armor, 1 2 or 3...  0 isn't sold
  tmpy = 64
  IfXIsLessThanY
    tmpx = 64  // Armor 1 is more common
  tmpy = 191
  IfXIsMoreThanY
    tmpy = 230
    IfXIsLessThanY  // Armor 3 is rare
      tmpx = 64  // Armor 1 is more common...
  tmpargument = tmpx > 6
  SetContent


// 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 = 4
        SendMessageNear
  Else
    tmpy = 983  // The unique code for a looted shop
    IfXIsEqualToY
      GetContent
      tmpargument = tmpargument & 3 + 4
      SetContent



// 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 = 5
          SendMessageNear
    Else
      // Wait before allowing a swap
      IfTimeOut
        // Reset the timer
        tmpargument = 40
        SetTime


        // Make target crouch
        tmpargument = ACTIONMG
        TargetDoAction


        // Can the target use this armor
        tmpargument = 0
        GetXY
        tmpargument = tmpx  // The character's IDSZ
        IfTargetHasID
          // Check if the shop has been looted...
          GetContent
          tmpx = tmpargument & 4
          tmpy = 4
          IfXIsEqualToY
            // Steal the armor
            tmpargument = tmpargument & 3
            ChangeTargetArmor
            tmpargument = tmpargument + 4
            SetContent
            tmpargument = tmpx + 7
            SendMessageNear
          Else
            // Check money
            GetContent // The armor type...  0 - 3
            TargetPayForArmor
              tmpdistance = tmpy  // The base cost of the new armor

              // Swap armor
              ChangeTargetArmor
              SetContent
              tmpargument = tmpx
              tmpx = tmpdistance
              SendMessageNear
            Else
              // Not enough money...
              tmpargument = 6
              SendMessageNear
        Else
          // Say it's for someone else
          tmpargument = 11 + tmpy  // tmpy is message offset...
          SendMessageNear



// All done
End
