IF
  Die()
THEN
  RESPONSE #100
    Shout(66)
END

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  OR(2)
    Heard([NEUTRAL],79)
    Heard([EVILCUTOFF],79)
  Allegiance(Myself,NEUTRAL)
  !Global("BP_PlotMan","LOCALS",1)
THEN
  RESPONSE #100
    Enemy()
END

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,PC)
  OR(2)
    AttackedBy([GOODCUTOFF],DEFAULT)
    Allegiance(LastAttackerOf(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Enemy()
    Shout(151)
END

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,GOODCUTOFF)
  OR(2)
    HitBy([GOODCUTOFF],CRUSHING)
    Allegiance(LastHitter(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Shout(151)
    Enemy()
END

//////////////CLOUDLIKE  EFFECTS//////////////////////

IF
  CheckStat(Myself,11,180) // I'm in a stinking cloud
  CheckStatGT(Myself,5,INT)
  !StateCheck(Myself,STATE_SLEEPING) // not yet affected
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(2)
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStatGT(Myself,11,180) // I'm in a web,entangle, or grease spell
  CheckStatLT(Myself,15,180)
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,1,131) // I don't have free action
  CheckStatLT(Myself,1,WEB) //and not webbed up
  CheckStatLT(Myself,1,ENTANGLE) //nor entangled --I can move
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,15,180) // I'm in an Ice Storm
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTCOLD) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,16,180) // I'm in a Cloudkill or Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTPOISON) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,17,180) // I'm in a Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTACID) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,18,180) // Incendiary Cloud, Meteor Swarm or Fire Storm -- bad stuff
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTFIRE) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

// This is to try and keep them from going back in to whomp somebody
IF
  CheckStatLT(Myself,11,180) // No longer in the cloud effects
  CheckStatGT(Myself,5,INT)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  !Range(LastSeenBy(Myself),16)
  Exists([EVILCUTOFF])
  !Range(NearestEnemyOf(Myself),2)
THEN
  RESPONSE #100
    EquipRanged()  //use your bow, then
    SmallWait(3)
    Continue()
END

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////


IF
  OR(2)
    !Allegiance(Myself,EVILCUTOFF)
    !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
END

IF
  TargetUnreachable(LastSeenBy(Myself))
  Delay(3)
THEN
  RESPONSE #100
    ClearActions(Myself)
    Continue()
END

IF
  Range(NearestEnemyOf(Myself),2)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(NearestEnemyOf(Myself),0,125)
THEN
  RESPONSE #80
    RunAwayFrom(NearestEnemyOf(Myself),4)
  RESPONSE #20
    Continue()
END

IF
  General(Myself,UNDEAD)
  OR(2)
    TurnedBy([GOODCUTOFF.0.0.CLERIC_ALL])
    TurnedBy([GOODCUTOFF.0.0.PALADIN_ALL])
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  CheckStat(Myself,1,SCRIPTINGSTATE4)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  HasItem("potn55",Myself)  // ~Potion of Superior Healing~
  !GlobalTimerNotExpired("POT","LOCALS")
  HPPercentLT(Myself,60)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("potn55",Myself)  // ~Potion of Superior Healing~
END

IF
  HasItem("potn52",Myself)  // ~Potion of Extra Healing~
  !GlobalTimerNotExpired("POT","LOCALS")
  HPPercentLT(Myself,60)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("potn52",Myself)  // ~Potion of Extra Healing~
END

IF
  HasItem("SCRL56",Myself)  // ~Cure Serious Wounds~
  HPPercentLT(Myself,65)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatGT(Myself,11,INT)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("SCRL56",Myself)  // ~Cure Serious Wounds~
END

IF
  HaveSpell(INNATE_LAY_ON_HANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  HPPercentLT(Myself,70)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,INNATE_LAY_ON_HANDS)
END

IF
  HasItem("POTN08",Myself)  // ~Potion of Healing~
  !GlobalTimerNotExpired("POT","LOCALS")
  HPPercentLT(Myself,85)
  RandomNumLT(201,80)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("POTN08",Myself)  // ~Potion of Healing~
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,35)
  CheckStatGT(Myself,7,INT)
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
  !HasItem("POTN55",Myself)
  !HasItem("POTN52",Myself)
  !GlobalTimerNotExpired("BPW","LOCALS")
  Range([EVILCUTOFF],15)
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,35)
  CheckStatGT(Myself,7,INT)
  !General(Myself,HUMANOID)
  !General(Myself,GIANTHUMANOID)
  !HasItem("POTN55",Myself)
  !HasItem("POTN52",Myself)
  !GlobalTimerNotExpired("BPW","LOCALS")
  Range([EVILCUTOFF],15)
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  StateCheck(Myself,STATE_POISONED)
  HasItem("potn17",Myself)  // ~Elixir of Health~
  !GlobalTimerNotExpired("POT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("potn17",Myself)  // ~Elixir of Health~
END

IF
  StateCheck(Myself,STATE_POISONED)
  HasItem("potn20",Myself)  // ~Antidote~
  !GlobalTimerNotExpired("POT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("potn20",Myself)  // ~Antidote~
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_POISONED)
  CheckStatGT(Myself,7,INT)
  Range([EVILCUTOFF],15)
  !GlobalTimerNotExpired("POIS","LOCALS")
  !HasItem("POTN17",Myself)
  !HasItem("POTN20",Myself)
THEN
  RESPONSE #100
    Shout(83)
    SetGlobalTimer("POIS","LOCALS",ONE_ROUND)
END

IF
  ActionListEmpty()
  HasItem("ring05",Myself)  // ~Ring of Invisibility ~
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("BPRING05","LOCALS",0)
  RandomNumLT(40,14)
  !StateCheck(Myself,0x60400010)
  CheckStatLT(NearestEnemyOf,1,SEEINVISIBLE)
  CheckStatLT(SecondNearestEnemyOf,1,SEEINVISIBLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
	SetGlobal("BPRING05","LOCALS",1)
    UseItem("ring05",Myself)  // ~Ring of Invisibility ~
END

IF
  ActionListEmpty()
  HasItem("potn14",Myself)  // ~Oil of Speed~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(42,15)
  !StateCheck(Myself,STATE_HASTED)
  CheckStat(Myself,0,IMPROVEDHASTE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn14",Myself)  // ~Oil of Speed~
END

IF
  ActionListEmpty()
  HasItem("POTN45",Myself)  // ~Potion of Freedom~
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(Myself,0,131)
  OR(6)
    StateCheck(Myself,STATE_HELPLESS)
    CheckStatGT(Myself,0,GREASE)
    CheckStat(Myself,12,180)
    CheckStat(Myself,13,180)
    CheckStat(Myself,14,180)
    CheckStatGT(Myself,0,ENTANGLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN45",Myself)  // ~Potion of Freedom~
END

IF
  ActionListEmpty()
  HasItem("potn34",Myself)  // ~Potion of Magic Protection~
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  RandomNumLT(50,16)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn34",Myself)  // ~Potion of Magic Protection~
END

IF
  ActionListEmpty()
  HasItem("WAND16",Myself)  // ~Potion of Icedust~
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatGT(Myself,8,INT)
  HitBy([ANYONE],FIRE)
  CheckStatLT(Myself,81,RESISTFIRE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("WAND16",Myself)  // ~Potion of Icedust~
END

IF
  ActionListEmpty()
  HasItem("POTN02",Myself)  // ~Potion of Fire Resistance~
  !GlobalTimerNotExpired("BPT","LOCALS")
  HitBy([ANYONE],FIRE)
  CheckStatLT(Myself,41,RESISTFIRE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN02",Myself)  // ~Potion of Fire Resistance~
END

IF
  ActionListEmpty()
  HasItem("potn06",Myself)  // ~Potion of Cloud Giant Strength~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNum(44,15)
  CheckStatLT(Myself,23,STR)
  OR(4)
    Class(Myself,FIGHTER_ALL)
    Class(Myself,PALADIN_ALL)
    Class(Myself,RANGER_ALL)
    Class(Myself,MONK)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn12",Myself)  // ~Potion of Stone Giant Strength~
END

IF
  ActionListEmpty()
  HasItem("POTN05",Myself)  // ~Potion of Fire Giant Strength~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNum(43,15)
  CheckStatLT(Myself,22,STR)
  OR(4)
    Class(Myself,FIGHTER_ALL)
    Class(Myself,PALADIN_ALL)
    Class(Myself,RANGER_ALL)
    Class(Myself,MONK)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN05",Myself)  // ~Potion of Fire Giant Strength~
END

IF
  ActionListEmpty()
  HasItem("POTN09",Myself)  // ~Potion of Heroism~
  RandomNumLT(47,16)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureGT([GOODCUTOFF],2)
  OR(4)
    Class(Myself,FIGHTER_ALL)
    Class(Myself,PALADIN_ALL)
    Class(Myself,RANGER_ALL)
    Class(Myself,MONK)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN09",Myself)  // ~Potion of Heroism~
END

IF
  ActionListEmpty()
  HasItem("potn11",Myself)  // ~Potion of Invulnerability~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(48,17)
  CheckStatLT(LastAttackerOf(Myself),1,109) // weapon enchantment
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn11",Myself)  // ~Potion of Invulnerability~
END

IF
  ActionListEmpty()
  HasItem("POTN21",Myself)  // ~Potion of Clarity~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(55,36)
  OR(5)
    See([0.0.MIND_FLAYER])
    See([0.0.UMBERHULK])
    See([0.UNDEAD.VAMPIRE])
    StateCheck([EVILCUTOFF],STATE_CONFUSED)
    StateCheck([EVILCUTOFF],STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN21",Myself)  // ~Potion of Clarity~
END

IF
  ActionListEmpty()
  HasItem("POTN37",Myself)  // ~Potion of Mind Focusing~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(49,14)
  OR(3)
    CheckStatLT(Myself,8,DEX)
    CheckStatGT(Myself,11,DEX)
    CheckStatLT(Myself,9,INT)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN37",Myself)  // ~Potion of Mind Focusing~
END

IF
  ActionListEmpty()
  HasItem("POTN28",Myself)  // ~Potion of Fortitude~
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(Myself,18,CON)
  RandomNumLT(51,18)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN28",Myself)  // ~Potion of Fortitude~
END

IF
  ActionListEmpty()
  HaveSpell(INNATE_PROTECTION_FROM_EVIL)
  Alignment(LastSeenBy(Myself),MASK_EVIL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(79,25)
  Exists(NearestEnemyOfType([0.0.0.0.0.0.MASK_EVIL]))
  CheckStat(Myself,0,117)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,INNATE_PROTECTION_FROM_EVIL)
END

IF
  ActionListEmpty()
  HasItem("POTN29",Myself)  // ~Potion of Genius~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(53,10)
  OR(4)
    Class(Myself,BARD_ALL)
    Class(Myself,LONG_BOW)
    Class(Myself,SORCERER)
    CheckStatLT(Myself,8,INT)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN29",Myself)  // ~Potion of Genius~
END

IF
  ActionListEmpty()
  HasItem("POTN30",Myself)  // ~Potion of Infravision~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(56,14)
  TimeOfDay(NIGHT)
  OR(3)
    Race(Myself,HUMAN)
    Race(Myself,HALFLING)
    Race(Myself,HALFORC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN30",Myself)  // ~Potion of Infravision~
END

IF
  ActionListEmpty()
  HitBy([GOODCUTOFF],CRUSHING)
  CheckStatGT(Myself,7,INT)
  !GlobalTimerNotExpired("RANG","LOCALS")
  !StateCheck(Myself,STATE_POISONED)
  OR(2)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  !Range(LastSeenBy(Myself),5)
  !TargetUnreachable(LastSeenBy(Myself))
  !InWeaponRange(LastSeenBy(Myself))
  HPGT(LastSeenBy(Myself),0)
THEN
  RESPONSE #50
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #50
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #25
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #25
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #50
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
    MoveToObject(LastSeenBy(Myself))
    AttackReevaluate(LastSeenBy(Myself),180)
END

IF
  ActionListEmpty()
  HaveSpell(INNATE_LAY_ON_HANDS)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),123)
    Heard(SecondNearest([EVILCUTOFF]),123)
    Heard([EVILCUTOFF],123)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatGT(Myself,7,INT)
  HPGT(LastHeardBy(Myself),0)
  HPPercentGT(Myself,75)
  Range(LastHeardBy(Myself),10)
  !Range([EVILCUTOFF.0.0.CLERIC_ALL],10)
  !HasItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
  !HasItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
  RandomNumLT(24,9)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),INNATE_LAY_ON_HANDS)
END



IF
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  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)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,25)
  OR(3)
    Heard(ThirdNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(SecondNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(NearestMyGroupOfType([EVILCUTOFF]),124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  Exists(LastAttackerOf(LastHeardBy(Myself)))
  !Allegiance(LastAttackerOf(LastHeardBy(Myself)),EVILCUTOFF)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(LastHeardBy(Myself)),MORNINGSTAR)
    !Class(LastAttackerOf(LastHeardBy(Myself)),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(LastHeardBy(Myself)),65)
  OR(3)  
    !StateCheck(LastAttackerOf(LastHeardBy(Myself)),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(33,13)
  HitBy([0],0x0000)
  !Allegiance(LastHitter(Myself),EVILCUTOFF)
  !StateCheck(LastHitter(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
  OR(3)  
    !StateCheck(LastHitter(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(33,22)
  AttackedBy([0],DEFAULT)
  !Allegiance(LastAttackerOf(Myself),EVILCUTOFF)
  !StateCheck(LastAttackerOf(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(Myself),MORNINGSTAR)
    !Class(LastAttackerOf(Myself),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(Myself),65)
  OR(3)  
    !StateCheck(LastAttackerOf(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END




IF
  ActionListEmpty()
  StateCheck(Myself,0x00400010)
  Class(Myself,THIEF_ALL)
  HPPercentGT(Myself,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",12)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    FollowObjectFormation(LastSeenBy(Myself),1,3)
    SmallWait(5)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  CheckStatGT(Myself,0,SCRIPTINGSTATE4)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END



IF
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  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(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
  ActionListEmpty()
  HasItem("SCRL9G",Myself)  // ~Abi Dalzim's Horrid Wilting~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(43,29)
  CheckStatGT(Myself,11,INT)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),76,MAGICDAMAGERESISTANCE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("SCRL9G",LastSeenBy(Myself))  // ~Abi Dalzim's Horrid Wilting~
END

IF
  ActionListEmpty()
  HasItem("wand05",Myself)  // ~Wand of Fire~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(58,20)
  CheckStatGT(Myself,8,INT)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(Myself,74,RESISTFIRE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("wand05",LastSeenBy(Myself))  // ~Wand of Fire~
END

IF
  ActionListEmpty()
  HasItem("potn13",Myself)  // ~Oil of Fiery Burning~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(57,32)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(Myself,74,RESISTFIRE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn13",LastSeenBy(Myself))  // ~Oil of Fiery Burning~
END

IF
  ActionListEmpty()
  HasItem("potn26",Myself)  // ~Potion of Explosions~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(58,32)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(Myself,74,RESISTFIRE)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTFIRE)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn26",LastSeenBy(Myself))  // ~Potion of Explosions~
END

IF
  ActionListEmpty()
  HasItem("wand07",Myself)  // ~Wand of Lightning~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(59,21)
  CheckStatGT(Myself,10,INT)
  CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  CheckStat(LastSeenBy(Myself),0,129)
  LOS(LastSeenBy(Myself),25)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("wand07",LastSeenBy(Myself))  // ~Wand of Lightning~
END

IF
  ActionListEmpty()
  HasItem("wand13",Myself)  // ~Wand of Cloudkill~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(64,23)
  CheckStatGT(Myself,10,INT)
  OR(2)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(Myself,74,RESISTPOISON)
  OR(4)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,3)
    CheckStatGT(NearestMyGroupOfType,49,RESISTPOISON)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(SecondNearestMyGroupOfType)
    !Range(SecondNearestMyGroupOfType,4)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTPOISON)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  OR(4)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,5)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTPOISON)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
  OR(2)
    NumCreature([EVILCUTOFF.0.0.0.0.SUMMONED],0)
    Range(NearestMyGroupOfType([EVILCUTOFF.0.0.0.0.SUMMONED]),4)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatLT(LastSeenBy(Myself),76,RESISTPOISON)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSBREATH)
  CheckStatLT(LastSeenBy(Myself),76,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("wand13",Myself)  // ~Wand of Cloudkill~
END

IF
  ActionListEmpty()
  HasItem("potn27",Myself)  // ~Potion of Firebreath~
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(57,32)
  OR(2)
    LOS(LastSeenBy(Myself),12)
    Range(LastSeenBy(Myself),8)
  OR(5)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,2)
    !LOS(NearestMyGroupOfType,12)
    CheckStatGT(NearestMyGroupOfType,49,RESISTFIRE)
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
  OR(5)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,3)
    !LOS(SecondNearestMyGroupOfType,12)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTFIRE)    
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("potn27",LastSeenBy(Myself))  // ~Potion of Firebreath~
END

IF
  ActionListEmpty()
  HasItem("RING03",Myself)  // ~Ring of Animal Friendship~
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStat(LastSeenBy(Myself),0,119)
  General(LastSeenBy(Myself),ANIMAL)
  RandomNumLT(61,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("RING03",LastSeenBy(Myself))  // ~Ring of Animal Friendship~
END



IF
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  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)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,25)
  OR(3)
    Heard(ThirdNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(SecondNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(NearestMyGroupOfType([EVILCUTOFF]),124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  Exists(LastAttackerOf(LastHeardBy(Myself)))
  !Allegiance(LastAttackerOf(LastHeardBy(Myself)),EVILCUTOFF)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(LastHeardBy(Myself)),MORNINGSTAR)
    !Class(LastAttackerOf(LastHeardBy(Myself)),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(LastHeardBy(Myself)),65)
  OR(3)  
    !StateCheck(LastAttackerOf(LastHeardBy(Myself)),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(33,13)
  HitBy([0],0x0000)
  !Allegiance(LastHitter(Myself),EVILCUTOFF)
  !StateCheck(LastHitter(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
  OR(3)  
    !StateCheck(LastHitter(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(33,22)
  AttackedBy([0],DEFAULT)
  !Allegiance(LastAttackerOf(Myself),EVILCUTOFF)
  !StateCheck(LastAttackerOf(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(Myself),MORNINGSTAR)
    !Class(LastAttackerOf(Myself),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(Myself),65)
  OR(3)  
    !StateCheck(LastAttackerOf(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(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
  Race(LastSeenBy(Myself),MORNINGSTAR)
  Class(LastSeenBy(Myself),FAIRY_NYMPH)
  Specifics(LastSeenBy(Myself),65)
THEN
  RESPONSE #100
END

IF
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #80
    Continue()
  RESPONSE #20
END




IF
  ActionListEmpty()
  CheckStatGT(Myself,7,INT)
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
THEN
  RESPONSE #30
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    RunAwayFrom(LastHitter(Myself),40)
  RESPONSE #30
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastHitter(Myself),15)
  RESPONSE #40
    Shout(123)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #25
    SetGlobalTimer("BPW","LOCALS",10)
    Attack(LastHitter(Myself))
END

IF
  ActionListEmpty()
  CheckStatGT(LastSeenBy(Myself),10,180)
  CheckStatLT(Myself,11,180)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  OR(3)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #25
    Continue()
  RESPONSE #75
END

IF
  ActionListEmpty()
  !Range(LastSeenBy(Myself),8)
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
THEN
  RESPONSE #90
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #90
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END
