//Show where you are on the map
tmpx = selfx
tmpy = selfy
tmpargument = BLUE
ShowBlipXY

//------------------------------------------------------------------------------
IfSpawned
  Sneak				//Dont run around
  tmpargument = 1
  SetContent

//------------------------------------------------------------------------------
IfHealed
  tmpargument = 7
  SendMessageNear

// Get mean if characters wanna be bad
IfAttacked
  Run
  SetTargetToWhoeverAttacked
  IfTargetIsAPlayer
    CallForHelp
    tmpargument = TEAME     //Team Evil
    TargetJoinTeam
    tmpargument = 2
    SetState
  tmpargument = rand & 1 + 8
  PlaySound
IfKilled
  SetTargetToWhoeverAttacked
  IfTargetIsAPlayer
    tmpargument = TEAME
    TargetJoinTeam
    CallForHelp			//Warn friends
IfCalledForHelp
  DisableExport
  
//------------------------------------------------------------------------------
// ZZ> Handle normal state
IfTimeOut
  tmpargument = 50
  SetTime

  //WAIT AND TALK
  IfStateIs0
    SetTargetToNearbyEnemy		//Enemy near, go combat mode
      tmpargument = 2
      SetState
      CallForHelp
    Else
      tmpx = selfspawnx
      tmpy = selfspawny
      tmpturn = selfturn + 8192
      tmpdistance = 200
      Compass
      ClearWaypoints
      AddWaypoint

      tmpargument = [NONE]
      tmpdistance = BLAHFRIENDS + BLAHPLAYERS
      SetTargetToWideBlahID
        tmpx = targetdistance
        tmpy = 128*5                    //Does he see a player?
        IfXIsLessThanY
          IfTargetIsAPlayer
          
            //Call for help if not already agreed on help or finished the quest
            tmpargument = 1
            IfContentIs
              tmpargument = [COBO]
              IfTargetHasQuest
                DoNothing                 //We have told them before
              Else
                tmpargument = ACTIONMC
                DoAction
                tmpargument = 11
                PlaySound
                SendMessageNear
                tmpargument = 225
                SetTime

            //Look at him
            SetTurnModeToWatchTarget
            tmpx = targetx
            tmpy = targety
            ClearWaypoints
            AddWaypoint
          Else
            SetTurnModeToVelocity
        Else
          SetTurnModeToVelocity     

  //Cooldown to start talking
  IfStateIs1
    tmpargument = 0
    SetState

  //IN COMBAT
  IfStateIs2
    SetTurnModeToVelocity
    SetTargetToNearbyEnemy
      IfFacingTarget			//Attack enemy?
        tmpx = targetdistance
        tmpy = 150
        IfXIsLessThanY
          IfHoldingMeleeWeapon
            PressLatchButton
          Else
            tmpargument = LATCHPACKRIGHT
            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
    
    //Draw weapon
    IfUnarmed
      tmpargument = LATCHPACKRIGHT
      PressLatchButton

//What to do if bumped
IfStateIs0
  IfBumped
    SetTargetToWhoeverBumped
    IfTargetIsOnSameTeam
      IfTargetIsAPlayer
        tmpargument = ACTIONMC      //"bored" animation
        DoAction
        tmpargument = 1
        SetState                    //Prevent looping
        tmpargument = 150
        SetTime
        
        tmpargument = [COBO]
        IfTargetHasQuest                //Have they already beaten it?
          tmpturn = 1
          IfDistanceIsMoreThanTurn        //TODO: IfQuestBeaten
            tmpargument = 6
            SetContent
            PlayFullSound     //"Thank you!"
            SendMessageNear
          Else
            //Check if anyone is claiming their quest reward
            tmpturn = 0
            IfDistanceIsMoreThanTurn
              
              tmpargument = [COBO]          //Dont repeat this
              tmpdistance = 2
              AddQuestAllPlayers
              
              tmpargument = 6
              SetContent
              PlayFullSound     //"Thank you!"
              SendMessageNear
              
              //Give the reward
              tmpargument = 75
              tmpdistance = EXPQUEST
              GiveExperienceToGoodTeam      //uh oh.. all the guards gain too
              
              tmpx = rand % 3                 //Randomize the ring
              tmpy = 0
              IfXIsEqualToY
                tmpargument = 158             //Ring of Protection
              tmpy = 1
              IfXIsEqualToY
                tmpargument = 135             //Ring of Jumping
              tmpy = 2
              IfXIsEqualToY
                tmpargument = 136             //Ring of Life
              tmpy = 3
              IfXIsEqualToY
                tmpargument = 137             //Ring of Luck
              tmpx = targetx
              tmpy = targety
              tmpdistance = targetz + 50
              SpawnExactCharacterXYZ
            Else
              tmpargument = 4               //Repeat the reward sentence
              PlayFullSound
              SendMessageNear
        Else
          
          //We have met and told them before, no need to repeat everything
          tmpargument = [COBO]
          IfTargetHasQuest
            tmpargument = 6
            SetContent
            
          //Small multiplayer oriented fix to allow new players to gain this quest as well
          Else
            tmpargument = 6
            IfContentIs
              tmpargument = 1
              SetContent
            
          tmpargument = selfcontent
          PlayFullSound
          SendMessageNear
          
          //Unlock the module or prepeare the next quest line
          tmpargument = 5
          IfContentIs
            tmpargument = [COBO]
            tmpdistance = 0
            AddQuestAllPlayers
            tmpargument = 6       //Dont re-add the quest everytime we are bumped
            SetContent
          Else
            tmpargument = 6
            IfContentIs
              tmpargument = 4     //Simply repeat the reward sentence from now
              SendMessageNear
              PlaySound
            Else
              //Prepeare the next thing to say
              tmpargument = selfcontent + 1
              SetContent
            

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