IF
  Die()
THEN
  RESPONSE #100
    Shout(151)
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],125)
    Heard([EVILCUTOFF],125)
  Allegiance(Myself,NEUTRAL)
THEN
  RESPONSE #100
    Enemy()
END

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

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

IF
  Allegiance(Myself,EVILCUTOFF)
  Heard([EVILCUTOFF],151)
  !See([GOODCUTOFF])
  !TargetUnreachable(LastHeardBy(Myself))
THEN
  RESPONSE #100
    MoveToObject(LastHeardBy(Myself))
END

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

IF
  See(NearestEnemyOf(Myself))
  Global("SHOUT","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SHOUT","LOCALS",1)
    Shout(151)
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
  ActionListEmpty()
  SpellCast(Myself,0)
  HaveAnySpells()
  HitBy([ANYONE],CRUSHING)
  NumCreatureGT([EVILCUTOFF],3)
  !GlobalTimerNotExpired("SBN","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SBN","LOCALS",15)
    DisplayStringHead(Myself,@1300)
    Shout(69)
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN55",Myself) 
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",6)
    DisplayStringHead(Myself,@500)
    UseItem("POTN55",Myself)
END

IF
  HPPercentLT(Myself,60)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN52",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",6)
    DisplayStringHead(Myself,@500)
    UseItem("POTN52",Myself)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,35)
  See([EVILCUTOFF])
  !GlobalTimerNotExpired("BPW","LOCALS")
  !HasItem("POTN52",Myself)
  !HasItem("POTN55",Myself) 
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",6)
    DisplayStringHead(Myself,@501)
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  HitBy([ANYONE],POISON)
  !StateCheck(Myself,STATE_POISONED)
  !HasItem("DAGG16",LastAttackerOf(Myself))
  !HasItem("SPER10",LastAttackerOf(Myself))
  !HasItem("HALB05",LastAttackerOf(Myself))
  !HasItem("ETTERC2",LastAttackerOf(Myself))
  !HasItem("Wyvern2",LastAttackerOf(Myself))
  !Kit(LastAttackerOf(Myself),ASSASIN)
  !HasItem("DAGG16",LastHitter(Myself))
  !HasItem("SPER10",LastHitter(Myself))
  !HasItem("HALB05",LastHitter(Myself))
  !HasItem("ETTERC2",LastHitter(Myself))
  !HasItem("Wyvern2",LastHitter(Myself))
  !Kit(LastHitter(Myself),ASSASIN)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@900)
    Shout(83)
    RunAwayFrom(NearestEnemyOf(Myself),15)
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("POIS","LOCALS")
  See([EVILCUTOFF])
  !HasItem("POTN17",Myself)
  !HasItem("POTN20",Myself)
THEN
  RESPONSE #100
    Shout(83)
    DisplayStringHead(Myself,@901)
    SetGlobalTimer("POIS","LOCALS",6)
END

IF
  Global("SNAFU","LOCALS",0)
  OR(3)
    CheckStatGT(Myself,60,SPELLFAILUREMAGE)
    CheckStatGT(Myself,0,SCRIPTINGSTATE4)
    StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",1)
END

IF
  Global("SNAFU","LOCALS",1)
  CheckStatLT(Myself,61,SPELLFAILUREMAGE)
  CheckStat(Myself,0,SCRIPTINGSTATE4)
  !StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",0)
END

IF
  Global("BPMRC","LOCALS",0)
  OR(3)
    Class(Myself,MAGE_ALL)
    Class(Myself,BARD)
    Class(Myself,SORCERER)
THEN
  RESPONSE #100
    SetGlobal("BPMRC","LOCALS",1)
END

IF
  Global("BPMRC","LOCALS",0)
THEN
  RESPONSE #100
    ChangeClass(Myself,MAGE)
    SetGlobal("BPMRC","LOCALS",1)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  GlobalLT("SCH","LOCALS",2)
  Global("SNAFU","LOCALS",0)
THEN
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_SPIRIT_ARMOR)
    ReallyForceSpell(Myself,WIZARD_SPELL_IMMUNITY_INVOCATION)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_BLUE)
    ReallyForceSpell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_HASTE)
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    SetGlobalTimer("CHE","LOCALS",60)
    SetGlobalTimer("BPIP","LOCALS",15)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SHIELD)
    ReallyForceSpell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    ForceSpell(Myself,WIZARD_NON_DETECTION)
    SetGlobalTimer("CHE","LOCALS",60)
    SetGlobalTimer("BPIP","LOCALS",15)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ELECTRICITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_FIRE)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    SetGlobalTimer("CHE","LOCALS",60)
    IncrementGlobal("SCH","LOCALS",1)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FIRE_SHIELD_RED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,128)
  CheckStat(Myself,0,125)
  CheckStat(Myself,0,SHIELDGLOBE)
  Range(NearestEnemyOf(Myself),8)
  RandomNumLT(9,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(Myself,WIZARD_FIRE_SHIELD_RED)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_HASTE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    See([EVILCUTOFF.HUMANOID.HALFORC.FIGHTER.106])
    See([EVILCUTOFF.HUMANOID.HALFORC.FIGHTER_CLERIC.106])
  Range(LastSeenBy(Myself),12)
  OR(2)
   !StateCheck(Myself,STATE_HASTED)
   !StateCheck(LastSeenBy(Myself),STATE_HASTED)
  CheckStat(LastSeenBy(Myself),0,IMPROVEDHASTE)
  RandomNumLT(32,17)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell([EVILCUTOFF],WIZARD_HASTE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RESIST_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(6)
    StateCheck(SixthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FifthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FourthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(ThirdNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(SecondNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck([EVILCUTOFF],STATE_PANIC)
  See(ThirdNearest([EVILCUTOFF]))
  RandomNumLT(33,18)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_RESIST_FEAR)
END

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

IF
  RandomNumLT(32,21)
  OR(2)
    Heard([EVILCUTOFF.HUMANOID.HALFORC.FIGHTER_CLERIC.106],124)
    Heard([EVILCUTOFF.HUMANOID.HALFORC.FIGHTER.106],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(3)
    See([GOODCUTOFF.0.0.0.0.SUMMONED_DEMON])
    See([GOODCUTOFF.0.0.0.0.SUMMONED])
    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.MAGE_ALL])
    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.MAGE_ALL]))
    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
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #80
    Continue()
  RESPONSE #20
END

IF
  ActionListEmpty()
  OR(2)
    Global("SNAFU","LOCALS",1)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    StateCheck(Myself,STATE_INVISIBLE)
    StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    IncrementGlobal("BPIP","LOCALS",-1)
  RESPONSE #90
    RunAwayFrom(NearestEnemyOf(Myself),10)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CLOUDKILL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    Gender(LastSeenBy(Myself),SUMMONED)
    CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !Range(LastSeenBy(Myself),15)
  RandomNumLT(45,25)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_CLOUDKILL)
    SetGlobalTimer("BPT","LOCALS",6)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SKULL_TRAP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),15)
  CheckStatLT(LastSeenBy(Myself),60,RESISTMAGIC)
  RandomNumLT(48,30)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MONSTER_SUMMONING_2)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  RandomNumLT(61,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MONSTER_SUMMONING_2)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_METEOR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(NearestEnemyOf(Myself),5)
  !HasItem("BLAKBLAD",Myself)  // ~Black Blade of Disaster~
  !HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
  RandomNumLT(69,32)
THEN
  RESPONSE #100
    Spell(Myself,WIZARD_MELF_METEOR)
    SetGlobalTimer("BPT","LOCALS",6)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_RAY_OF_ENFEEBLEMENT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatGT(LastSeenBy(Myself),15,STR)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(99,45)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_RAY_OF_ENFEEBLEMENT)
END

IF
  ActionListEmpty()
  HasItem("wand08",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  LevelLT(LastSeenBy(Myself),10)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  RandomNumLT(61,21)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    DisplayStringHead(Myself,@910)
    UseItem("wand08",LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),50,RESISTACID)
  RandomNumLT(68,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_MAGIC_MISSILE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStat(LastSeenBy(Myself),2,SCRIPTINGSTATE5)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(70,36)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_CHROMATIC_ORB)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(71,36)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_BLINDNESS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_BLIND)
  RandomNumLT(64,22)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_BLINDNESS)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPOOK)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),8,SAVEVSSPELL)
  RandomNumLT(65,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SPOOK)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
THEN
  RESPONSE #30
    DisplayStringHead(Myself,@911)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    RunAwayFrom(LastHitter(Myself),40)
  RESPONSE #10
    DisplayStringHead(Myself,@914)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    Attack(LastHitter(Myself))
  RESPONSE #40
    DisplayStringHead(Myself,@913)
    Shout(123)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastSeenBy(Myself),15)
END

IF
  ActionListEmpty()
  OR(4)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
    HasItem("MELFMET",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("BPDD","LOCALS",6)
    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)
THEN
  RESPONSE #90
    SetGlobalTimer("BPDD","LOCALS",6)
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #40
    SetGlobalTimer("BPDD","LOCALS",6)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
THEN
  RESPONSE #100
    SetGlobalTimer("BPDD","LOCALS",6)
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

