// handle bunching + sticking
// handle spacing

// Find guy to protect
IfSpawned
  tmpx=0
  tmpy=1
  tmpargument=0
  SetXY
  SetState

tmpargument=0
GetXY
IfXIsLessThanY
  SetTargetToNearestFriend
    SetOwnerToTarget
    tmpx=2
    SetXY    

// Get mean if characters wanna be bad
IfAttacked
  SetTargetToWhoeverAttacked
    IfTargetIsAPlayer
      CallForHelp
      JoinEvilTeam
  SetTargetToOldTarget
IfCalledForHelp
  SetTargetToWhoeverCalledForHelp
    SetOwnerToTarget
    tmpargument=0
    SetState
    JoinEvilTeam

// Show the character's location
tmpx = selfx
tmpy = selfy
tmpargument = 4
ShowBlipXY

IfKilled				// This reduces the height of the char
  tmpargument = 0			  // Last words...
  SetState				  //
  IfTargetIsOnSameTeam			  // Fragged!
    tmpargument = 3			    //
    IfTargetIsSelf			    // No, just a damage tile
      tmpargument = 4			      //
  SendMessage				  //
  tmpargument = 65535			  // Drop money
  DropMoney				  //
  tmpargument = 45			  //
  SetBumpHeight				  //
IfAttacked				// Attacked
  SetTargetToWhoeverAttacked		  //
    IfTargetIsAlive			    //
      tmpargument = 1			        //
      SetState			        //  
      tmpdistance = rand & 2047 + 11000       // Ouch!
      tmpargument = tmpdistance & 1 + 4
      PlaySound			        //
    Else				    //Attacker died already
      SetTargetToOldTarget		      //
IfTargetKilled				// Return to follow mode
  tmpargument = 0			  // State 0 ( Follow )
  SetState				  //
IfTimeOut				// This is done every so often
  SetTargetToWideEnemy		  // Look out for enemies
    tmpargument = 1			      //
    SetState				      // Change to combat mode
  tmpargument = 0			  // Check state
  IfStateIs				  // State 0 ( Follow )
    tmpx = ownerx			    //
    tmpy = ownery			    //
    GetContent
    tmpturn = tmpargument < 14    // Stand to side
    tmpdistance = 500			    //
    Compass				    //
  Else					  // State 1 ( Combat )
    tmpx = targetdistance		    // Close enough to attack?
    tmpy = 200				    //
    IfXIsLessThanY			    //
      tmpargument = LATCHRIGHT		      // Right Attack == 2
      PressLatchButton			      //
    tmpx = targetx			    // Move towards enemy
    tmpy = targety			    //
    tmpturn = targetturnto		    //
    tmpdistance = 200			    //
    Compass				    //
  ClearWaypoints			  //
  AddWaypoint				  //
  tmpargument = rand&20			  // Try again later
  SetTime				  //
IfBumped				// Bumped
  SetTargetToWhoeverBumped		  //
    tmpargument = 0			    // Return to follow state
    SetTargetToNearbyEnemy		    // Look out for enemies
      tmpargument = 1			      // Stay in combat state
    Else				    // Revert
      SetTargetToOldTarget		      //
    SetState				    //
    tmpx = rand&511+selfx-256		    //
    tmpy = rand&511+selfy-256		    //
    ClearWaypoints			    //
    AddWaypoint				    //
    tmpargument = 40			    // Try again soon
    SetTime				    //
End					// Finished with this character

