IF
  Global("IllaseraDead","GLOBAL",1)
  Global("IllaseraDeadRun","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,66488)  // ~Let's get out of here!!!~
    SetGlobal("IllaseraDeadRun","LOCALS",1)
    EscapeArea()
END

IF
  Heard([EVILCUTOFF],ALERT)
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    Enemy()
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  See(NearestMyGroupOfType)
  HPPercentLT(Myself,25)
  HPGT(Myself,1)
  !Range(NearestMyGroupOfType,8)
  !GlobalTimerNotExpired("Whined","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Whined","LOCALS",12)
    DisplayStringHead(Myself,46151)  // ~help!~
    Shout(124)
  RESPONSE #100
    SetGlobalTimer("Whined","LOCALS",12)
    DisplayStringHead(Myself,49763)  // ~I require assistance~
    Shout(124)
  RESPONSE #100
    SetGlobalTimer("Whined","LOCALS",12)
    DisplayStringHead(Myself,49764)  // ~Defend me!~
    Shout(124)
  RESPONSE #100
    SetGlobalTimer("Whined","LOCALS",12)
    DisplayStringHead(Myself,49765)  // ~Slay my attacker!~
    Shout(124)
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("DrankPotionTimer","LOCALS")
  HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("DrankPotionTimer","LOCALS",6)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN55",Myself)  // ~Potion of Superior Healing~
END

IF
  See(NearestEnemyOf(Myself))
  OR(2)
    Range(NearestMyGroupOfType,20)
    See(NearestMyGroupOfType([0.0.0.CLERIC_ALL]))
  HPPercentLT(Myself,35)
  !GlobalTimerNotExpired("CalledForHealing","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("CalledForHealing","LOCALS",6)
    DisplayStringHead(Myself,72808)  // ~I need healing!~
    Shout(123)
END

IF
  Heard(NearestMyGroupOfType,123)
  !StateCheck(LastHeardBy(Myself),STATE_REALLY_DEAD)  // astHeardBy(Myself))
  HPPercentGT(Myself,75)
  See(LastHeardBy(Myself))
  Range(LastHeardBy(Myself),10)
  !Range(NearestMyGroupOfType([0.0.0.CLERIC_ALL]),20)
  !NumItemsGT("POTN55",LastHeardBy(Myself),0)
  NumItemsGT("POTN55",Myself,1)
  !GlobalTimerNotExpired("GaveAwayPotion","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GaveAwayPotion","LOCALS",12)
    DisplayStringHead(Myself,72809)  // ~Here! Catch!~
    GiveItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
    SmallWait(3)
    ActionOverride(LastHeardBy(Myself),DisplayStringHead(Myself,73896))  // ~Got it!~
END

IF
  OR(3)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
    GlobalTimerNotExpired("Attacking","LOCALS")
  Allegiance(Myself,ENEMY)
  CheckStatLT(Myself,40,RESISTCRUSHING)
  OR(2)
    HPPercentLT(Myself,100)
    Range(NearestEnemyOf(Myself),8)
  !GlobalTimerNotExpired("Hardiness","LOCALS")
  HaveSpellRES("SPCL907")
THEN
  RESPONSE #100
    SetGlobalTimer("Hardiness","LOCALS",60)
    SpellRES("SPCL907",Myself)  // ~Hardiness~
END

IF
  Allegiance(Myself,ENEMY)
  See([ENEMY])
  HPGT(LastSeenBy(Myself),1)
  HPPercentGT(LastSeenBy(Myself),50)
  !Range(LastSeenBy(Myself),15)
  GlobalTimerNotExpired("Running","LOCALS")
THEN
  RESPONSE #100
    MoveToObject([ENEMY])
END

IF
  OR(3)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
    GlobalTimerNotExpired("Attacking","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  Range(NearestEnemyOf(Myself),8)
  GlobalLT("EtherealCount","LOCALS",5)
  !GlobalTimerNotExpired("Ethereal","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Ethereal","LOCALS",24)
    IncrementGlobal("EtherealCount","LOCALS",1)
    ForceSpellRES("illainv",Myself)  // ~Ethereal~
END

IF
  OR(3)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
    GlobalTimerNotExpired("Attacking","LOCALS")
  RandomNum(2,1)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  OR(3)
    See([GOODCUTOFF.0.0.SORCERER])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
  GlobalLT("EtherealCount","LOCALS",5)
  !GlobalTimerNotExpired("Ethereal","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Ethereal","LOCALS",24)
    IncrementGlobal("EtherealCount","LOCALS",1)
    ForceSpellRES("illainv",Myself)  // ~Ethereal~
END

IF
  OR(3)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
    GlobalTimerNotExpired("Attacking","LOCALS")
  HPPercentLT(Myself,50)
  !Range(NearestEnemyOf(Myself),12)
  !GlobalTimerNotExpired("CriticalWounds","LOCALS")
  GlobalLT("HealCount","LOCALS",2)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("CriticalWounds","LOCALS",15)
    IncrementGlobal("HealCount","LOCALS",1)
    ForceSpell(Myself,CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    NoAction()
END

IF
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,21)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),124)
    Heard(SecondNearest([EVILCUTOFF]),124)
    Heard([EVILCUTOFF],124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  HPGT(LastHitter(LastHeardBy(Myself)),1)
  !See(LastHitter(LastHeardBy(Myself)))
  HPGT(LastAttackerOf(LastHeardBy(Myself)),1)
  !See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,21)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  RandomNumLT(28,22)
  OR(4)
    See([GOODCUTOFF.0.0.0.0.SUMMONED_DEMON])
    See([GOODCUTOFF.0.0.0.0.SUMMONED])
    See([GOODCUTOFF.0.0.0.207])
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
  RandomNumLT(29,23)
  OR(7)
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  RandomNumLT(30,16)
  See(Protagonist)
  RandomNumLT(26,10)
  OR(4)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
  RandomNumLT(27,10)
  OR(3)
    See([GOODCUTOFF.0.0.MONK])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.THIEF_ALL])
  RandomNumLT(24,9)
  OR(3)
    See(StrongestOf)
    See(BestAC)
    See(LeastDamagedOf)
  RandomNumLT(25,9)
  See(WeakestOf)
  RandomNumLT(23,8)
  See(WorstAC)
  RandomNumLT(21,8)
  See(MostDamagedOf)
  RandomNumLT(32,11)
  OR(2)
    See(TenthNearest([GOODCUTOFF.0.0.LONG_BOW]))
    See(TenthNearest([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(20,8)
  See(TenthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
THEN
  RESPONSE #100
END

IF
  !Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  See([GOODCUTOFF])
THEN
  RESPONSE #100
    MoveToObject([GOODCUTOFF])
END
IF
  StateCheck(LastSeenBy(Myself),STATE_DEAD)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_INVISIBLE)
  Range(NearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobalTimer("Running","LOCALS",4)
    RunAwayFrom(NearestEnemyOf(Myself),15)
END

IF
  ActionListEmpty()
   !StateCheck(Myself,STATE_INVISIBLE)
  Range(SecondNearestEnemyOf(Myself),8)
  RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Running","LOCALS",4)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  ActionListEmpty()
  Range(NearestEnemyOf(Myself),8)
  HPPercentLT(Myself,20)
  HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("Running","LOCALS",4)
    RunAwayFrom(NearestEnemyOf(Myself),15)
END

IF
  ActionListEmpty()
  Range(LastSeenBy(Myself),8)
  RandomNum(3,1)
THEN
  RESPONSE #100
    SetGlobalTimer("Running","LOCALS",3)
    RunAwayFrom(LastSeenBy(Myself),15)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
  RandomNum(2,1)
  OR(2)
    Gender(LastSeenBy(Myself),SUMMONED)
    Gender(LastSeenBy(Myself),ILLUSIONARY)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  RandomNum(2,1)
  OR(2)
    HasBounceEffects(LastSeenBy(Myself))
    HasItem("shld24",LastSeenBy(Myself))  // ~Reflection Shield +1~
  Range(LastSeenBy(Myself),8)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON3,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
  RandomNum(2,1)
  !Range(LastSeenBy(Myself),8)
  OR(3)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
    Class(LastSeenBy(Myself),BARD_ALL)
  OR(7)
    HasImmunityEffects(LastSeenBy(Myself))
    CheckStat(LastSeenBy(Myself),0,SPELLFAILUREMAGE)
    StateCheck(LastSeenBy(Myself),STATE_MIRRORIMAGE)
    StateCheck(LastSeenBy(Myself),STATE_BLUR)
    StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
  RandomNum(3,1)
  !Range(LastSeenBy(Myself),8)
  OR(2)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),DRUID_ALL)
  OR(7)
    HasImmunityEffects(LastSeenBy(Myself))
    CheckStat(LastSeenBy(Myself),0,SPELLFAILUREPRIEST)
    StateCheck(LastSeenBy(Myself),STATE_DRAWUPONHOLYMIGHT)
    StateCheck(LastSeenBy(Myself),STATE_BLESS)
    StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
  RandomNum(3,1)
  !Range(LastSeenBy(Myself),8)
  OR(4)
    Class(LastSeenBy(Myself),FIGHTER_ALL)
    Class(LastSeenBy(Myself),PALADIN_ALL)
    Class(LastSeenBy(Myself),RANGER_ALL)
    Class(LastSeenBy(Myself),THIEF_ALL)
  OR(4)
    HasImmunityEffects(LastSeenBy(Myself))
    StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
   RandomNum(2,1)
  !Range(LastSeenBy(Myself),8)
  HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("Running","LOCALS")
  RandomNum(2,1)
  !Range(LastSeenBy(Myself),8)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON2,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #75
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #50
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  Range(LastSeenBy(Myself),8)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON2,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #50
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
END

