IfKilled				// This reduces the height of the char
  tmpargument = 1
  PlaySound

  tmpargument = 0			  // Last words...
  SendMessageNear				  //
  
  tmpargument = selfmoney
  DropMoney				  //
  
  tmpargument = 45			  //
  SetBumpHeight				  //

IfTimeOut				// This is done every so often
  tmpargument = rand & 15 + 15		  // Try again later
  SetTime				  //

  SetTargetToNearestFriend
  tmpx = targetdistance
  tmpy = 128*5
  IfXIsLessThanY
    IfTargetIsHurt
      tmpargument = 2
      SetState

  //Helper
  IfStateIs2				  // State 2 ( Helper )
    IfTargetIsHurt			    // Heal wounded
      tmpx = targetx
      tmpy = targety
      ClearWaypoints			  //
      AddWaypoint				  //
      tmpx = targetdistance		      //
      tmpy = 300			      //
      IfXIsLessThanY			      // In Range?
        tmpx = 260			        //
        tmpy = selfmana			        //
        IfXIsLessThanY				// Enough to cast?
          IfFacingTarget
            tmpargument = LATCHLEFT	          // Left Attack == 1
            PressLatchButton		          //
        Else					// Do something else
          tmpargument = 0		          //
          SetState			          //
    Else				    // Switch to follow
      tmpargument = 0			      //
      SetState				      //
    tmpx = targetx			    //
    tmpy = targety			    //
    ClearWaypoints			  //
    AddWaypoint				  //
  Else					  // Find someone to bash
    tmpdistance = 128*4
    SetTargetToDistantEnemy
      tmpargument = 1
      SetState

  //Wander (Avatar healers stand ground)
  IfStateIs0
    tmpargument = 0
    IfArmorIs
      tmpx = rand & 511 + selfspawnx - 256			   
      tmpy = rand & 511 + selfspawny - 256
    Else			    
      tmpx = selfspawnx			   
      tmpy = selfspawny
    ClearWaypoints			  //
    AddWaypoint				  //
 
  //Attack
  IfStateIs1				  // State 1 ( Combat )
    SetTargetToWideEnemy
    IfFacingTarget
      tmpx = targetdistance		    // Close enough to attack?
      tmpy = 200				    //
      IfXIsLessThanY			    //
        tmpargument = rand & 1 + LATCHLEFT    // Right Attack == 2
        PressLatchButton			      //
    
    tmpx = targetx			    // Move towards enemy
    tmpy = targety			    //
    tmpturn = targetturnto		    //
    tmpdistance = 200			    //
    Compass				    //
    ClearWaypoints			  //
    AddWaypoint				  //
  
    //Target ran away
    tmpx = targetdistance
    tmpy = 700
    IfXIsMoreThanY
      tmpargument = 0
      SetState

IfAttacked				// Counter attack if not healing
  IfStateIs0				  //
    SetTargetToWhoeverAttacked		    //
      IfTargetIsAlive			      //
        IfTargetIsOnHatedTeam		        // Go get 'em
          tmpargument = 1		          //
          SetState			          //
          tmpargument = rand & 1 + 2
          PlaySound
        IfTargetIsOnSameTeam		        // Yell at 'em
          tmpargument = MESSAGEOUCH	          //
          SendMessageNear		          //
          SetTargetToOldTarget		          //
          tmpargument = 4
          PlaySound
      Else				      // Attacker dead already
        SetTargetToOldTarget		        //

IfBumped				// Bumped
  SetTargetToWhoeverBumped		  //
  IfTargetIsOnSameTeam
    IfTargetIsHurt			  //
      // Heal 'em
      tmpargument = 2			      // State 2 ( Helper )
      SetState				      //
    Else					  // Revert
      SetTargetToOldTarget		    //

IfTargetKilled				// Mode switch
  tmpargument = 0			  // Return to follow mode
  SetState				  //

// Heal effect
IfUsed
  tmpargument = 50
  SetReloadTime
  IfTargetIsOnSameTeam
    tmpx = targetx
    tmpy = targety
    tmpdistance = targetz
    tmpargument = 0
    SpawnExactParticle

    tmpargument = rand & 511 + 1024
    HealTarget

  Else
    tmpx = targetx
    tmpy = targety
    tmpdistance = targetz
    tmpargument = 0
    SpawnExactParticle
    tmpdistance = DAMAGEHOLY

    tmpargument = rand & 511 + 1024
    DamageTarget

End					// Finished with this character
