//Randomize skin
IfSpawned
  tmpargument = rand % 4
  ChangeArmor

IfKilled				// This reduces the height of the char
  tmpargument = 6
  PlaySound				//Death sound

  // Last words...
  tmpargument = 0
  IfTargetIsAPlayer			  // Fragged!
    tmpargument = 3
  IfTargetIsSelf			    // No, just a damage tile
    tmpargument = 4
  SendMessageNear				  
  tmpargument = selfmoney		  // Drop money
  DropMoney				  //
  tmpargument = 45			  //
  SetBumpHeight				  //

IfAttacked				// Attacked
  SetTargetToWhoeverAttacked		  //
    IfTargetIsAlive			    //
      IfTargetIsOnHatedTeam		      // Go after 'em
        tmpargument = 1			        //
        SetState			        //  
        tmpargument = tmpdistance & 1 + 4
        PlaySound			        //
        IfTargetIsOldTarget		        //
          DoNothing
        Else				        //
          IfTargetIsAPlayer
            tmpargument = 1			          //
            SendMessageNear			          //help me!
            tmpargument = 6			          //
            PlaySound			          //

      Else				      // Complain
        tmpargument = 2			        //
        SendMessageNear			        //
        tmpargument = 1			        //
        PlaySound			        //
        SetTargetToOldTarget		        //
    Else				    //Attacker died already
      SetTargetToOldTarget		      //

IfTargetKilled				// Return to wander mode
  tmpargument = 0			
  SetState				 

IfTimeOut				// This is done every so often

  //Wander
  IfStateIs0
    tmpx = rand & 511 + selfspawnx - 256
    tmpy = rand & 511 + selfspawny - 256 
    ClearWaypoints
    AddWaypoint
    tmpargument = rand % 20 + 50
    SetTime
    SetTurnModeToVelocity

    SetTargetToNearbyEnemy		  // Look out for enemies
      tmpargument = 1			      //
      SetState				      // Change to combat mode

  //Combat
  IfStateIs1
    tmpargument = rand % 20
    SetTime
    IfHoldingRangedWeapon
      tmpx = targetdistance		    // Ranged attack?
      tmpy = 800				    //
      IfXIsLessThanY			    //
        tmpargument = LATCHRIGHT		      // Right Attack == 2
        PressLatchButton			      //
      tmpx = targetx			    // Move towards enemy
      tmpy = targety			    
      tmpturn = targetturnto		    
      tmpdistance = 0 - 600
      Compass
      ClearWaypoints
      AddWaypoint	    
      SetTurnModeToWatchTarget
    Else
      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

    //No enemies found
    SetTargetToWideEnemy
      DoNothing
    Else
      tmpargument = 0
      SetState

// Use shield?
IfTargetIsAttacking
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = [SHIE]
      IfHoldingItemID
        tmpargument = LATCHLEFT
        PressLatchButton

IfBumped				// Bumped
  SetTargetToWhoeverBumped		  //
  IfTargetIsOnHatedTeam			  // Try to counter
    tmpargument = LATCHRIGHT		    //
    PressLatchButton			    //
  Else					  // Get around other character
    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				    //

// Ya!  Unarmed attack sound
IfUsed
  tmpargument = 7
  PlaySound
End					// Finished with this character
