//become nasty
IfAttacked
  tmpargument = 6
  PlaySound
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    tmpargument = TEAME
    TargetJoinTeam
    CallForHelp
IfKilled
  tmpargument = TEAME
  TargetJoinTeam
  tmpargument = 7
  PlaySound

//Talk
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnSameTeam
    IfTargetIsAPlayer
      IfStateIsOdd
        DoNothing
      Else
        tmpargument = [SAND]
        IfTargetHasQuest         //Old time visitor already has script!
          tmpargument = 8
          SetState
      IfStateIs0              //Who am I
        tmpargument = 0
        SendMessageNear
        tmpargument = 2
        PlaySound
      IfStateIs2              //We need more archeologists
        tmpargument = 1
        SendMessageNear
        tmpargument = 3
        PlaySound
      IfStateIs4              //Present the ancient script
        tmpargument = 2
        SendMessageNear
        tmpargument = 4
        PlaySound
      IfStateIs6
        tmpargument = 3
        SendMessageNear
        tmpx = selfx
        tmpy = selfy
        tmpdistance = 150
        tmpargument = 144
        SpawnExactCharacterXYZ
          tmpargument = [SAND]
          AddTargetQuest        //Give the quest to the target
      IfStateIs8              //"Solved mystery yet?"
        tmpargument = 4
        SendMessageNear
        tmpargument = 5
        PlaySound

      //Do not repeat
      IfStateIsOdd
        IfStateIs0
          tmpargument = 1
          SetState
      Else
        tmpargument = selfstate + 1
        SetState
        tmpargument = 240
        SetTime

//Return to greeting mode
IfTimeOut
  IfStateIsOdd
    tmpx = selfstate
    tmpy = 8            //8 is the last message
    IfXIsLessThanY
      tmpargument = selfstate + 1
      SetState
    Else
      tmpargument = 8
      SetState

//Combat AI
IfTimeOut
  tmpargument = 10
  SetTime
  SetTargetToWideEnemy
    tmpx = targetx
    tmpy = targety
    tmpdistance = 1500
    tmpturn = targetturnto
    Compass
    ClearWaypoints
    AddWaypoint
    IfFacingTarget
      tmpx = targetdistance
      tmpy = 200
      IfXIsLessThanY
        tmpargument = LATCHRIGHT
        PressLatchButton

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