IfSpawned
  MakeCrushValid

IfCrushed
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 1
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  tmpargument = 1
  SendMessageNear

IfDropped
  // Popped out of a chest
  tmpargument = 3
  PlaySound

IfKilled
  IfTargetIsSelf
    tmpargument = 2     //Sucide!
  Else
    tmpargument = 0     //Slain
  SendMessageNear
  tmpargument = 40
  SetBumpHeight
  tmpargument = 1
  PlaySound

IfAttacked
  SetTargetToWhoeverAttacked
    tmpargument = 0
    PlaySound

IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = LATCHLEFT
      PressLatchButton
  Else
    tmpx = rand & 1023 - 512 + selfx
    tmpy = rand & 1023 - 512 + selfy
    ClearWaypoints
    AddWaypoint
    SetTargetToOldTarget

// Look for enemies
IfTimeOut
  SetTargetToNearestEnemy
    IfFacingTarget
      tmpx = targetdistance
      tmpy = 800
      IfXIsLessThanY
        tmpx = selfaccel
        tmpy = 1
        IfXIsMoreThanY
          tmpargument = LATCHJUMP
          PressLatchButton
          tmpx = targetx - selfx > 4
          tmpy = targety - selfy > 4
          SetOldTarget
          SetTargetToSelf
          AccelerateTarget
          SetTargetToOldTarget

          // Play the sound
          tmpargument = 2
          PlaySound
      tmpx = targetx
      tmpy = targety
    Else
      tmpx = selfx
      tmpy = selfy
      tmpturn = selfturn
      tmpdistance = 500
      Compass
      tmpx = tmpx + targetx + targetx + targetx > 2
      tmpy = tmpy + targety + targety + targety > 2
    ClearWaypoints
    AddWaypoint
  Else
    tmpx = selfx
    tmpy = selfy
    tmpturn = selfturn
    tmpdistance = 500
    Compass
    tmpturn = rand & 1023 - 512 + selfx
    tmpx = tmpx + tmpturn + tmpturn + tmpturn > 2
    tmpturn = rand & 1023 - 512 + selfy
    tmpy = tmpy + tmpturn + tmpturn + tmpturn > 2
    ClearWaypoints
    AddWaypoint
  tmpargument = rand & 31 + 25
  SetTime

// All done
End
