IfHealed
  // Spawn a defense ping
  IfStateIs0
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 2
    SpawnExactParticle
    tmpargument = 1
    SetState
    tmpargument = 20
    SetTime

IfAttacked
  // Must die in 1 hit to disallow punching it open
  tmpargument = 512
  HealSelf
  // Spawn a defense ping
  IfStateIs0
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpargument = 2
    SpawnExactParticle
    tmpargument = 1
    SetState
    tmpargument = 20
    SetTime

IfTimeOut
  // Ready the pings
  tmpargument = 0
  SetState
  tmpargument = 500
  SetTime

IfKilled
  GoPoof
  tmpargument = 0
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  SpawnExactParticle
  PlaySound

  //Is it a monster inside?
  tmpx = rand & 100
  tmpy = 50			//50% chance
  IfXIsMoreThanY
    tmpx = rand % 3		//Randomize monster
    tmpy = 0
    IfXIsEqualToY
      tmpargument = 66		//Ghoul
    tmpy = 1
    IfXIsEqualToY
      tmpargument = 42		//Ghost
    tmpy = 2
    IfXIsEqualToY
      tmpargument = 47		//Zombi
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    tmpturn = selfturn
    SpawnExactCharacterXYZ
    tmpargument = 0
    SendMessageNear
    tmpargument = 1
    PlaySound

  //Drop loot
  DropItems
  DropKeys
  tmpargument = 67605
  DropMoney
  tmpx = rand % 9		//Randomize loot
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 62		//Quiver
  tmpy = 1
  IfXIsEqualToY
    tmpargument = 67		//Scythe
  tmpy = 2
  IfXIsEqualToY
    tmpargument = 39		//Ammobox
  tmpy = 3
  IfXIsEqualToY
    tmpargument = 61		//Identify Scroll
  tmpy = 4
  IfXIsEqualToY
    tmpargument = 60		//Mana potion
  tmpy = 5
  IfXIsEqualToY
    tmpargument = 37		//Levitation Potion
  tmpy = 6
  IfXIsEqualToY
    tmpargument = 71		//Silver Crossbow
  tmpy = 7
  IfXIsEqualToY
    tmpargument = 69		//Silver Scimitar
  tmpy = 8
  IfXIsEqualToY
    tmpargument = 38		//Lamp
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpturn = selfturn
  SpawnExactCharacterXYZ

//Make it destroyable
IfSpawned
  JoinEvilTeam

End
