//------------------------------------------------------------------------------
//Setup script
IfSpawned
  Sneak                       //33% move speed
  
  tmpx = selfspawnx           //Stay at spawn
  tmpy = selfspawny
  ClearWaypoints
  AddWaypoint
      
//------------------------------------------------------------------------------
//Handle death by sending a message and other stuff
IfKilled
  tmpargument = 0
  SendMessageNear

  tmpargument = selfmoney
  DropMoney
  DropKeys

  // Make the character body
  tmpargument = 45
  SetBumpHeight

//------------------------------------------------------------------------------
//Handle being attacked by blocking or countering or running away
IfAttacked
  SetTargetToWhoeverAttacked
  tmpargument = 16
  PlaySound
  
  //Get mean
  IfTargetIsAPlayer
    tmpargument = 5
    TargetJoinTeam
    CallForHelp
    tmpargument = 1
    SetState  

//------------------------------------------------------------------------------
IfCalledForHelp
  tmpargument = 1
  SetState  
    
//------------------------------------------------------------------------------
//Run away in panic if players are mean
IfStateIs1
  IfTimeOut
    tmpargument = 35
    SetTime
    SetTargetToWideEnemy
      Run
      tmpx = rand & 1023 + targetx - 512
      tmpy = rand & 1023 + targety - 512
      tmpdistance = - 2000
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint
  
//------------------------------------------------------------------------------
//Friendly mode
IfStateIs0
  IfBumped
    IfTimeOut
      SetTargetToWhoeverBumped
      IfTargetIsAPlayer
        tmpargument = 80
        SetTime
        
        tmpx = 0
        tmpargument = [COBO]
        IfTargetHasQuest
          tmpx = 1
          
        //They do not have the quest
        tmpy = 1
        IfXIsEqualToY
          //Try to give it to them...
          tmpargument = [TOUR]
          AddTargetQuest
          
          //Get the current quest level (= to the number of hostages saved)
          tmpx = 0
          tmpargument = [TOUR]
          IfTargetHasQuest
            tmpx = tmpdistance
            
          //Have they saved anyone yet?
          tmpy = 0
          IfXIsMoreThanY
            tmpy = 4              //If quest level = 4, it means they have done this before
            IfXIsLessThanY
            
              //Did they save all?
              tmpy = 3
              IfXIsEqualToY
                tmpargument = [TOUR]    //They did! Unlock Tourist Starter
                AddIDSZ
                tmpargument = 7              //Tell them!
                SendMessage
                PlayFullSound
                tmpargument = 8
                SendMessage
              Else
                tmpargument = 6              //Tell them!
                SendMessage
                PlayFullSound       

              //Award the cash
              tmpargument = 400       
              SetMoney
              DropMoney
              
              //Award 50 XP per hostage saved
              tmpargument = tmpdistance*50
              tmpdistance = EXPQUEST
              GiveExperienceToTarget
              
              //Never repeat this again
              tmpargument = [TOUR]
              tmpdistance = 4
              SetTargetQuestLevel
            Else
              tmpargument = 2
              SetState
              
          //No one has been saved... explain quest again
          Else
            tmpx = selfcontent
            tmpy = 1
            IfXIsLessThanY
              tmpargument = 1           //Repeat message 1
              SetContent
            tmpx = selfcontent
            tmpy = 5
            IfXIsMoreThanY
              tmpargument = 5           //to message 5
              SetContent

            //Play the message
            tmpargument = selfcontent
            PlayFullSound
            SendMessage
            tmpargument = selfcontent + 1
            SetContent
          
        //They do not have the cobol quest
        Else
          tmpargument = 2
          SetState
          
      IfStateIs2
        tmpx = selfcontent
        tmpy = 9
        IfXIsLessThanY
          tmpargument = 9
          SetContent
        
        //For messages and such
        tmpargument = selfcontent
        tmpx = selfcontent
        
        //Welcome to lorule!
        tmpy = 9
        IfXIsEqualToY
          SendMessage
          PlayFullSound
          tmpargument = 10
          SetContent
          
        //I am a tourist guide
        tmpy = 10
        IfXIsEqualToY
          SendMessage
          PlayFullSound
          tmpargument = 11
          SetContent
          
        //100 zenny for tourist guide!
        tmpy = 11
        IfXIsEqualToY
          SendMessage
          PlayFullSound
          tmpargument = 12
          SetContent
          
        //Want to buy it?
        tmpy = 12
        IfXIsEqualToY
          SendMessage
          PlayFullSound
          tmpargument = 13
          SetContent
          
        //The buy process
        tmpy = 13
        IfXIsEqualToY
          tmpx = targetmoney
          tmpy = 99
          IfXIsMoreThanY
            
            //Create the tourist guide
            tmpargument = 160
            tmpdistance = selfz + 70
            tmpx = targetx
            tmpy = targety
            tmpturn = rand
            SpawnExactCharacterXYZ
            
            //Make them pay
            tmpargument = -100
            GiveMoneyToTarget
            tmpargument = 13
          Else
            tmpargument = 14            //Not enough cash!
          PlayFullSound
          SendMessage
          
          //Back to selling mode
          tmpargument = 11
          SetContent
          
        //Check for quest related stuff next update
        tmpargument = 0
        SetState
//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
