// Get mean if characters wanna be bad
IfAttacked
  Run
  SetTargetToWhoeverAttacked
  IfTargetIsAPlayer
    CallForHelp
    tmpargument = TEAME
    TargetJoinTeam
    tmpargument = 2
    SetState
  tmpargument = rand & 1 + 2
  PlaySound
IfKilled
  tmpargument = TEAME
  TargetJoinTeam

IfSpawned
  Sneak				//Dont run around
  tmpargument = 4
  SetContent

//------------------------------------------------------------------------------
// ZZ> Handle normal state
IfTimeOut
  tmpargument = 150
  SetTime

//WAIT AND TALK
  IfStateIs0
    SetTurnModeToVelocity
    tmpx = selfspawnx			//Return to where it was spawned
    tmpy = selfspawny
    ClearWaypoints
    AddWaypoint
    SetTargetToNearbyEnemy		//Enemy near, go combat mode
      tmpargument = 2
      SetState
      CallForHelp
    Else
      //Attract the attention of players
      tmpargument = 4
      IfContentIs
        SetTargetToNearestFriend
        tmpargument = [BENE]
        IfTargetHasQuest
          DoNothing                 //We have told them before
        Else
          tmpx = targetdistance
          tmpy = 128*6                    //Does he see a player?
          IfXIsLessThanY
            IfTargetIsAPlayer
              tmpargument = ACTIONMC      //Talk and move
              DoAction
              tmpargument = 2
              PlaySound
              tmpargument = 7
              SendMessageNear

              //Look at him
              SetTurnModeToWatchTarget
  IfStateIs1
    tmpargument = 0
    SetState

//IN COMBAT
  IfStateIs2
    SetTurnModeToVelocity
    SetTargetToNearbyEnemy
      IfFacingTarget			//Attack enemy?
        tmpx = targetdistance
        tmpy = 100
        IfXIsLessThanY
          tmpargument = LATCHRIGHT
          PressLatchButton
      Else
        tmpx = targetx			//Get in combat position
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
    Else
      tmpx = rand % 2047 + selfx - 1000			//Run!
      tmpy = rand % 2047 + selfy - 1000
      ClearWaypoints
      AddWaypoint
    tmpargument = 60
    SetTime

//What to do if bumped
IfStateIs0
  IfBumped
    SetTargetToWhoeverBumped
    IfTargetIsOnSameTeam
      IfTargetIsAPlayer
        tmpargument = ACTIONMC      //"bored" animation
        DoAction
        tmpargument = 1
        SetState                    //Prevent looping
        tmpargument = [BENE]
        IfTargetHasQuest                //Have they already beaten it?
          tmpturn = 1
          IfDistanceIsMoreThanTurn        //TODO: IfQuestBeaten
            tmpargument = 9
            PlayFullSound
            tmpargument = tmpargument - 3 //Thank you for helping me
            SendMessageNear
          Else
            //Check if anyone is claiming their quest reward
            tmpargument = [HEIR]
            CostTargetItemID
              tmpargument = 7               //Give them the reward
              PlayFullSound
              tmpargument = tmpargument - 3
              SendMessageNear
              tmpargument = [BENE]          //Dont repeat this
              tmpdistance = 1
              AddQuestAllPlayers
              tmpargument = 6
              SetContent                //Skip all the quest introductions

              //Give the reward
              tmpargument = 100
              tmpdistance = EXPQUEST
              GiveExperienceToGoodTeam      //uh oh.. all the guards in bishopia gain too
              tmpx = targetx
              tmpy = targety
              tmpdistance = targetz + 50
              tmpargument = 154             //soul carver
              SpawnExactCharacterXYZ
            Else
              tmpargument = 6               //Repeat the revenge sentence
              PlayFullSound
              tmpargument = tmpargument - 3
              SendMessageNear
        Else
          //They dont have the quest yet
          tmpargument = 6
          IfContentIs
            //Give them the quest
            tmpargument = [BENE]
            tmpdistance = 0           //The quest level
            AddQuestAllPlayers        //Add it
              tmpargument = 8
              PlayFullSound
              tmpargument = tmpargument - 3   //Tell em what happened
              SendMessageNear
              tmpargument = 20
              tmpdistance = EXPQUEST
              GiveExperienceToGoodTeam      //uh oh.. all the guards in bishopia gain too

          //The normal talking progression
          Else
            PlayFullSound
            tmpargument = selfcontent - 3
            SendMessageNear

            //Prepeare the next thing to say
            tmpargument = selfcontent + 1
            SetContent

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