//Handle talking
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsAPlayer
    IfTargetIsOnSameTeam
      tmpargument = 3
      IfArmorIs
        IfStateIs5
          tmpargument = 6
          PlaySound
          tmpargument = 4
          SendMessage
          tmpargument = 6
          SetState
          tmpargument = 100
          SetTime

      Else
        //Recieving money?
        IfStateIs3
          tmpx = targetmoney
          tmpy = 0
          IfXIsMoreThanY
            tmpargument = 0 - 1
            GiveMoneyToTarget
            IfTargetIsMale          //Its a dude
              tmpargument = 5
              PlaySound
              tmpargument = 3
              SendMessage
            Else                    //Its a nice lady
              tmpargument = 7
              PlaySound
              tmpargument = 5
              SendMessage
            tmpargument = 4               //Return to begging!
            SetState
            tmpargument = 75               //Wait before talking
            SetTime

            //Get nicer clothes!
            tmpx = selfmoney
            tmpy = 6
            IfXIsEqualToY
              tmpargument = 1
              ChangeArmor
            tmpy = 10
            IfXIsEqualToY
              tmpargument = 2
              ChangeArmor
            tmpy = 15
            IfXIsEqualToY
              tmpargument = 3   //final!
              ChangeArmor
              tmpargument = 5
              SetState
          Else
            tmpargument = 0
            SetState

        //begging
        IfStateIs0                    //Ready to accept money!
          tmpargument = 4
          PlaySound
          tmpargument = 2
          SendMessage
          tmpargument = 2           //Prepeare for give money
          SetState
          tmpargument = 75               //Wait before talking
          SetTime

//become bad
IfCalledForHelp
  JoinEvilTeam
  tmpargument = 1               //Combat
  SetState

//Ouch
IfAttacked
  SetTargetToWhoeverAttacked
  tmpargument = 4
  PlaySound

//Death stuff
IfKilled
  tmpargument = selfmoney
  DropMoney

  //Sound
  tmpargument = 1
  PlaySound

  //Message
  IfTargetIsSelf
    tmpargument = 0
  Else
    tmpargument = 1
  SendMessage

//Use shield and attack
IfTargetIsOnHatedTeam
  IfFacingTarget
    tmpx = targetdistance
    tmpy = 60
    IfXIsLessThanY
      tmpargument = rand & 1
      PressLatchButton          //Left or right


//Main AI loop
IfTimeOut
  tmpargument = rand & 31 + 15
  SetTime

  //Standing at spawn
  IfStateIs0
    SetTargetToNearbyEnemy
      tmpargument = 1
      SetState
    tmpx = selfspawnx
    tmpy = selfspawny
    ClearWaypoints
    AddWaypoint

  //Combat
  IfStateIs1
    SetTargetToNearbyEnemy
      tmpx = targetx
      tmpy = targety
      tmpdistance = 1500
      tmpturn = targetturnto
      ClearWaypoints
      AddWaypoint
    Else
      tmpargument = 0
      SetState                  //No enemies around anymore

  //Resume talking
  IfStateIs2
    tmpargument = 3
    SetState
  IfStateIs4
    tmpargument = 0
    SetState
  IfStateIs6
    tmpargument = 5
    SetState

End
