//--------------------------------------------------------------------------------
// Character screams
IfAttacked
  tmpargument = 3
  PlaySound

//--------------------------------------------------------------------------------
//Monster death
IfKilled
  // Make the character body
  tmpargument = 50
  SetBumpHeight

  //Death sound
  tmpargument = 4
  PlaySound

  // Tell everyone it died
  tmpargument = 0
  IfTargetIsOnSameTeam
    tmpargument = 1
    IfTargetIsSelf
      tmpargument = 2
  SendMessageNear

  //Drop the loot
  DropMoney
  DropKeys
  DropItems

//--------------------------------------------------------------------------------
//Combat AI
IfTimeOut

  // Reset the timer
  tmpargument = 10
  SetTime

  //Groan
  tmpx = 7
  tmpy = rand & 255
  IfXIsMoreThanY
    tmpargument = rand & 1 + 1
    PlaySound

  //Target enemy
  SetTargetToWideEnemy
    SetTurnModeToWatchTarget

    //Chase enemy
    tmpx = selfx
    tmpy = selfy
    tmpturn = targetturnto
    tmpdistance = 600
    Compass

  //No enemies found - wander
  Else
    SetTurnModeToVelocity
    tmpx = rand & 511 + selfx - 256
    tmpy = rand & 511 + selfy - 256
    tmpargument = 60
    SetTime

  ClearWaypoints
  AddWaypoint	//Do movements

  // Attack the enemy?
  tmpx = targetdistance
  tmpy = 250
  IfXIsLessThanY
    IfFacingTarget
      IfTargetIsOnHatedTeam
        tmpx = rand & 1280 + selfdex
        tmpy = 2560		//50% chance at 5 dexterity
        IfXIsMoreThanY			//Attack rating based on DEX
          tmpargument = ACTIONBC		//Attack
          DoAction

//--------------------------------------------------------------------------------
//Dont flock
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnSameTeam
    tmpx = rand % 500 + targetx - 250
    tmpy = rand % 500 + targety - 250
    tmpturn = targetturnto + 32768		//TargetTurnAway
    tmpdistance = rand % 400 + 500
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = 50
    SetTime
  SetTargetToOldTarget

//--------------------------------------------------------------------------------
End
//--------------------------------------------------------------------------------

//SetTargetToNearestFriend
//  tmpx = targetdistance
//  tmpy = 100
//  IfXIsLessThanY
//    tmpx = selfx
//    tmpy = selfy
//    tmpturn = targetturnto + 32768		//TargetTurnAway
//    tmpdistance = 200
//    Compass
//    ClearWaypoints
//    AddWaypoint
//SetTargetToOldTarget
