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

//Only 66% chance for being there
IfSpawned
  tmpx = rand % 3
  tmpy = 0
  IfXIsEqualToY
    SetTargetToSelf
    SetTargetToTargetLeftHand
      PoofTarget
    SetTargetToTargetRightHand
      PoofTarget
    GoPoof
  Else
    //Randomize what we want to trade
    tmpargument = 0
    tmpx = rand % 5
    tmpy = 0
    SetXY
    
    //We even randomize the starting position!
    tmpargument = rand % 3
    SetState
    IfStateIs0
      tmpx = 6976   //East house
      tmpy = 4928
    IfStateIs1
      tmpx = 5824   //Healer square
      tmpy = 6848
    IfStateIs2
      tmpx = 4416   //North house
      tmpy = 2624  
    Teleport
    tmpargument = 0
    SetState
    
//Talk
IfBumped
  SetTargetToWhoeverBumped
  IfStateIs0
    IfTargetIsOnSameTeam
      IfTargetIsAPlayer
        GetContent
        tmpx = tmpargument
        
        //Trade finished PART 2
        tmpy = 7
        IfXIsEqualToY
          tmpargument = 8
          PlaySound
          tmpargument = 4
          SendMessage
          tmpargument = 6       //Just loop the last two
          SetContent
        
        //Trade finished
        tmpy = 6
        IfXIsEqualToY
          tmpargument = 7
          PlaySound
          tmpargument = 3
          SendMessage
          GetContent
          tmpargument = tmpargument + 1
          SetContent
          
        //Initiate trade
        tmpy = 5
        IfXIsEqualToY
          tmpargument = 1
          SetXY             //Store old values
          tmpargument = 0
          GetXY
          tmpy = 0
          IfXIsEqualToY
            tmpargument = [BUNN]            //Tundra bunny for faerie
          tmpy = 1
          IfXIsEqualToY
            tmpargument = [FROG]            //Frog for mystic mold
          tmpy = 2
          IfXIsEqualToY
            tmpargument = [SQUI]            //Squirrel for black sheep
          tmpy = 3
          IfXIsEqualToY
            tmpargument = [MYST]            //Mystic mold for albino bat
          tmpy = 4
          IfXIsEqualToY
            tmpargument = [BUNN]            //Tundra bunny for grub bug
          IfTargetHoldingItemID
            SetTargetToTargetLeftHand
              IfTargetHasID                   //Get target
                DoNothing
              Else
                SetTargetToWhoeverBumped
                SetTargetToTargetRightHand    //Its in right
            Else
              SetTargetToTargetRightHand
              
            tmpargument = 12
            PlaySound
            tmpargument = 7
            SendMessage
            GetContent
            tmpargument = tmpargument + 1
            SetContent
            PoofTarget                      //Get rid of it =)
              SetTargetToWhoeverBumped
              tmpy = 0
              IfXIsEqualToY
                tmpargument = 80        //Faerie
              tmpy = 1
              IfXIsEqualToY
                tmpargument = 81        //Mold
              tmpy = 2
              IfXIsEqualToY
                tmpargument = 78        //Sheep
              tmpy = 3
              IfXIsEqualToY
                tmpargument = 83        //Albino bat
              tmpy = 4
              IfXIsEqualToY
                tmpargument = 84        //Grub bug
              tmpx = targetx
              tmpy = targety
              tmpdistance = targetz + 50
              SpawnExactCharacterXYZ        //And spawn a new one!
                tmpargument = 10
                tmpdistance = EXPROLEPLAY
                GiveExperienceToTarget          //award some xp
          Else
            tmpargument = 11
            PlaySound
            tmpargument = 5
            SendMessage
            tmpargument = 4             //They took the pet away, revert
            SetContent
          
          tmpargument = 1          //Restore the value
          GetXY
        //Check if trade works
        tmpy = 4
        IfXIsEqualToY
          tmpargument = 1
          SetXY
          tmpargument = 0
          GetXY
          tmpy = 0
          IfXIsEqualToY
            tmpargument = [BUNN]            //Tundra bunny for faerie
          tmpy = 1
          IfXIsEqualToY
            tmpargument = [FROG]            //Frog for mystic mold
          tmpy = 2
          IfXIsEqualToY
            tmpargument = [SQUI]            //Squirrel for black sheep
          tmpy = 3
          IfXIsEqualToY
            tmpargument = [MYST]            //Mystic mold for albino bat
          tmpy = 4
          IfXIsEqualToY
            tmpargument = [BUNN]            //Tundra bunny for grub bug
          IfTargetHoldingItemID
            tmpargument = 10
            PlaySound
            tmpargument = 8
            SendMessage
            GetContent
            tmpargument = tmpargument + 1
            SetContent
          Else
            tmpargument = 11
            PlaySound
            tmpargument = 5
            SendMessage
          tmpargument = 1
          GetXY
          
        //Trade?
        tmpy = 3
        IfXIsEqualToY
          tmpargument = 1
          SetXY             //Store values
          tmpargument = 9
          PlaySound
          tmpargument = 0
          GetXY
          tmpargument = 9 + tmpx
          SendMessage
          GetContent
          tmpargument = tmpargument + 1
          SetContent
          tmpargument = 1
          GetXY                 //Restore values
          
        //Blabber part 2
        tmpy = 2
        IfXIsEqualToY
          tmpargument = 8
          PlaySound
          tmpargument = 4
          SendMessage
          GetContent
          tmpargument = tmpargument + 1
          SetContent
          
        
        //Blabber part 1
        tmpy = 1
        IfXIsEqualToY
          tmpargument = 7
          PlaySound
          tmpargument = 3
          SendMessage
          GetContent
          tmpargument = tmpargument + 1
          SetContent
          
        //Greet
        tmpy = 0
        IfXIsEqualToY
          tmpargument = [ELFF]
          IfTargetHasID
            tmpargument = 6
            PlaySound
            tmpargument = 2
            SendMessage
          Else
            tmpargument = 5
            PlaySound
            tmpargument = 1
            SendMessage
          
          GetContent
          tmpargument = tmpargument + 1
          SetContent
          
        //Wait before talking again
        tmpargument = 1
        SetState
        tmpargument = 140
        SetTime
        
IfTimeOut
  tmpargument = 35
  SetTime
  
  //Waiting...
  IfStateIs0
    tmpx = selfx
    tmpy = selfy
    ClearWaypoints
    AddWaypoint
  
  //Reset talking
  IfStateIs1
    tmpargument = 0
    SetState
    
  //Combat!
  IfStateIs2
    SetTargetToWideEnemy
      tmpx = targetx
      tmpy = targety
      ClearWaypoints
      AddWaypoint
      
      //Attack!
      tmpx = targetdistance
      tmpy = 200
      IfXIsLessThanY
        IfHoldingMeleeWeapon
          PressLatchButton
          
//cast unseen
IfStateIs2          
  IfInvisible
    tmpargument = 0
    SetContent
  Else
    GetContent
    tmpx = tmpargument
    tmpy = 175                  //3,5 sec
    IfXIsLessThanY
      tmpargument = LATCHLEFT
      PressLatchButton
      GetContent
      tmpargument = tmpargument + 1
      SetContent
  
//Death related stuff
IfKilled
  tmpargument = 2
  PlaySound
  tmpargument = 0
  SendMessageNear
  tmpargument = selfmoney
  DropMoney
  
//Become bad
IfCalledForHelp
  tmpargument = 2
  SetState
  
//say ouch
IfAttacked
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    IfTargetIsAPlayer
      tmpargument = 5       //Team EVIL
      TargetJoinTeam
      CallForHelp
      tmpargument = 2
      SetState
      
End
