//Content equals armour level (And if set on spawn, a special armour type)
//While the state equals what type armour it is

// Randomly create contents...
IfSpawned
  tmpargument = 4
  IfContentIs			//If content is 4, its a paladin chest
    tmpargument = 7
    tmpy = tmpargument // Remember offset for messages
    SetState
  Else				//Nope normal armour
    tmpargument = rand % 6	//Randomize armour type
    tmpy = tmpargument // Remember offset for messages
    SetState  // To make checks easier...
  IfStateIs0
    tmpx = [GNOM]
  IfStateIs1
    tmpx = [SOLD]
  IfStateIs2
    tmpx = [ELFF]
  IfStateIs3
    tmpx = [ADVE]
  IfStateIs4
    tmpx = [WIZA]
  IfStateIs5
    tmpx = [HEAL]
  IfStateIs7
    tmpx = [PALA]
  tmpargument = 0
  SetXY  // Remember who gets it
  SetState
  GetState

  tmpargument = rand % 3 //Randomize armourtype	(Old script: 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

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