//Elf special abillties:
//LEVEL   ABILLITY
//1     - Weapon Profiency, Arcane Magic
//2     - Listen
//3     - n/a
//4     - n/a
//5     - Stealth (While standing still)
//6     - n/a
//7     - n/a
//8     - Bow Mastery
//9     - n/a
//10    - n/a
//11    - Elven Senses
//12    - n/a
//13    - n/a
//14    - Danger Sense
//-----------------------------------------------------------------------------
//Reset
IfSpawned
  tmpargument = 0
  SetState
  SetContent

//-----------------------------------------------------------------------------
//Danger sense skill
tmpx = selflevel
tmpy = 12          //Need level 14
IfXIsMoreThanY
  SetTargetToSelf           //Make sure the enemy is correct
  tmpargument = [NONE]      //All enemies
  AddBlipAllEnemies         //Reveal 'em all

//-----------------------------------------------------------------------------
//Go stealth mode when standing still
//State 0 = Ready
//State 1 = Cooldown
//State 2 = Going stealth stealth
//State 3 = In stealth mode

tmpx = selflevel
tmpy = 3           //Need to be level 5 at least
IfXIsMoreThanY
  //If tmpdistance > 0 then reset cloak timer
  tmpdistance = 0

  //Stuff that makes us visible
  SetTargetToSelf
  IfBumped
    tmpdistance = 300     //6 seconds
  IfAttacked
    tmpdistance = 300     //6 seconds
  IfTargetIsAttacking
    tmpdistance = 150     //3 seconds
  IfTargetIsDefending
    tmpdistance = 100     //2 seconds

  //Is the player standing still?
  SetTargetToSelf
  tmpx = targetspeedx + targetspeedy + targetspeedz
  tmpy = 0
  IfXIsEqualToY
    SetTargetToNearbyEnemy  //Can't hide in plain sight
      tmpx = selflevel*50 + targetdistance        //Level increases
    Else
      tmpx = 551
    tmpy = 550
    IfXIsMoreThanY
      IfInvisible
        DoNothing           //No need to hide if already invisisble
      Else
        IfStateIs0
          tmpargument = 2
          SetState
          tmpargument = 50
          SetTime
  Else                    //Character is moving, reset timer
    tmpdistance = 75     //1,5 seconds

  //Handle and reset cooldown counter for stealth
  IfTimeOut
    IfStateIs1
      tmpargument = 0
      SetState
    IfStateIs2
      tmpargument = 0
      SetAlpha
      tmpargument = 11
      PlaySound
      tmpargument = 3
      SetState

    //Check sneak abillity to see if we are detected
    IfStateIs3
      tmpargument = 75            //Check every 1,5 seconds
      SetTime
      SetTargetToNearestEnemy
        tmpturn = selflevel*50
        tmpx = targetdistance
        tmpy = 1000 - tmpturn
        IfXIsLessThanY
          tmpturn = targetdistance > 7          //Distance increases chance
          tmpx = targetwis > 8
          tmpx = tmpx - tmpturn
          tmpx = rand % 40 + tmpx
          tmpy = selfdex > 8
          tmpy = rand % 40 + tmpy
          IfXIsMoreThanY                        //We were detected!
            tmpdistance = 300               //6 seconds

  //Disable stealth and reset timer if tmpdistance is bigger than 0
  tmpturn = 0
  IfDistanceIsMoreThanTurn
    tmpargument = tmpdistance
    SetTime
    IfStateIs3
      tmpargument = 255
      SetAlpha
      tmpargument = 12
      PlaySound
    tmpargument = 1
    SetState

//-----------------------------------------------------------------------------
//Listen skill
tmpx = selflevel
tmpy = 0            //At least level 2
IfXIsMoreThanY
  EnableListenSkill

//-----------------------------------------------------------------------------
//Bow Mastery skill
tmpx = selflevel
tmpy = 6            //At least level 9
IfXIsMoreThanY
  IfScoredAHit
    SetTargetToLastItemUsed
    tmpargument = [LBOW]    //Only with longbows (two-handed)
    IfTargetHasID
      SetTargetToWhoeverWasHit
      tmpargument = 512
      DamageTarget          //+2 damage

//------------------------------------------------------------------------------
//Invoke Elven Senses if enough xp gained
tmpargument = 0
IfContentIs
  tmpx = selflevel
  tmpy = 9          //Need level 11
  IfXIsMoreThanY
    SetTargetToSelf
    SetOwnerToTarget
    EnchantTarget 	//Give the special bonus
    tmpargument = 1
    SetContent

//-----------------------------------------------------------------------------
// ZZ> Gong sound
IfCleanedUp
  tmpargument = 2
  PlayFullSound

//------------------------------------------------------------------------------
// ZZ> Yell at player
IfTooMuchBaggage
  tmpargument = 7
  SendMessageNear
  tmpargument = 7
  PlaySound
  tmpargument = 50
  SetReloadTime

//------------------------------------------------------------------------------
// ZZ> Scream and shout
IfUsed
  tmpargument = rand & 1 + 8
  PlaySound

//------------------------------------------------------------------------------
// ZZ> Handle being bored by cheering or sneezing
IfBored
  tmpargument = ACTIONMC
  DoAction
    tmpargument = 6
    SendMessageNear
    tmpargument = 10
    PlaySound

//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 5
  PlaySound
  tmpargument = 3
  IfArmorIs
    tmpargument = MESSAGECOSTUME
  Else
    tmpargument = MESSAGEDEATH
  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = MESSAGEACCIDENT
  SendMessage

  // Drop goodies
  tmpargument = 1+selflevel*selflevel*100		//The money loss formula
  DropMoney
  DropKeys

  // Make the character body
  tmpargument = 45
  SetBumpHeight

  // Reset skill
  UndoEnchant
  tmpargument = 0
  SetContent

//------------------------------------------------------------------------------
// ZZ> For helper AIs
IfLeaderKilled
  BecomeLeader

//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  // Pick either 0 or 7, Parry or Combat
  SetTargetToWhoeverAttacked
  IfTargetIsOnSameTeam
    tmpargument = 6
    PlaySound
    tmpargument = MESSAGEOUCH
    SendMessageNear
  Else
    tmpargument = rand & 1 + 3
    PlaySound

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