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

IF
  ModalState(TURNUNDEAD)
  OR(2)
    GlobalTimerExpired("BPTurn","LOCALS")
    HPPercentLT(Myself,51)
THEN
  RESPONSE #100
    SetGlobalTimer("BPTurn","LOCALS",0)
    ClearActions(Myself)
    SmallWait(5)
    Continue()
END

IF
  BreakingPoint()
THEN
  RESPONSE #50
    DisplayStringHead(Myself,49766)  // ~I can't take this~
    Shout(124)
  RESPONSE #50
    DisplayStringHead(Myself,49767)  // ~No more~
    Shout(124)
  RESPONSE #50
    DisplayStringHead(Myself,49768)  // ~Mercy!~
    Shout(124)
END

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

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

IF
  HasItem("potn55",Myself)  // ~Potion of Superior Healing~
  !GlobalTimerNotExpired("POT","LOCALS")
  HPPercentLT(Myself,60)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    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,70)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    UseItem("potn52",Myself)  // ~Potion of Extra Healing~
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~
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
END

IF
  HPPercentLT(Myself,35)
  !HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
  !HasItem("POTN52",Myself)  // ~Potion of Extra Healing~
  !GlobalTimerNotExpired("HEAL","LOCALS")
  NumCreatureGT([EVILCUTOFF],1)
  OR(2)
    Range([GOODCUTOFF],20)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
THEN
  RESPONSE #100
    SetGlobalTimer("HEAL","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,72808)  // ~I need healing!~
    Shout(123)
END

IF
  HitBy([ANYONE],POISON)
  !StateCheck(Myself,STATE_POISONED)
  !HasItem("DAGG16",LastAttackerOf(Myself))  // ~Poisoned Throwing Dagger~
  !HasItem("SPER10",LastAttackerOf(Myself))  // ~Spear of Withering +4~
  !HasItem("ETTERC2",LastAttackerOf(Myself)) 
  !HasItem("Wyvern2",LastAttackerOf(Myself))  // <Invalid Strref -1>
  !Kit(LastAttackerOf(Myself),262144)
  !HasItem("DAGG16",LastHitter(Myself))  // ~Poisoned Throwing Dagger~
  !HasItem("SPER10",LastHitter(Myself))  // ~Spear of Withering +4~
  !HasItem("HALB05",LastHitter(Myself))  // ~Dragon's Breath +4~
  !HasItem("ETTERC2",LastHitter(Myself))  // <Invalid Strref -1>
  !HasItem("Wyvern2",LastHitter(Myself))  // <Invalid Strref -1>
  !Kit(LastHitter(Myself),ASSASIN)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@0)
    Shout(83)
    RandomWalkContinuous()
END

IF
  StateCheck(Myself,STATE_POISONED)
  HaveSpell(CLERIC_SLOW_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_SLOW_POISON)
END

IF
  StateCheck(Myself,STATE_POISONED)
  HasItem("potn17",Myself)  // ~Elixir of Health~
  !GlobalTimerNotExpired("POT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    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)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("potn20",Myself)  // ~Antidote~
END

IF
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("PSH","LOCALS")
  !HasItem("POTN17",Myself)  // ~Elixir of Health~
  !HasItem("POTN20",Myself)  // ~Antidote~
  !HaveSpell(CLERIC_SLOW_POISON)
THEN
  RESPONSE #100
    Shout(83)
    SetGlobal("BPC","LOCALS",1)
    DisplayStringHead(Myself,5236)  // ~ Please. . . that pack of gnolls . . .they poisoned me.  ~ [POISN01]
    SetGlobalTimer("PSH","LOCALS",ONE_ROUND)
END

IF
  HaveSpell(CLERIC_SANCTUARY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(Myself,0,SANCTUARY)
  HPPercentLT(Myself,40)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_SANCTUARY)
END

IF
  HaveSpell(CLERIC_FREE_ACTION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,194)
  OR(4)
    RandomNumLT(3,3)
    StateCheck(Myself,STATE_HELPLESS)
    !CheckStat(Myself,0,WEB)
    !CheckStat(Myself,0,ENTANGLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_FREE_ACTION)
END

IF
  HaveSpell(CLERIC_DEFENSIVE_HARMONY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,133)
  RandomNumLT(4,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_DEFENSIVE_HARMONY)
END

IF
  HaveSpell(CLERIC_HOLY_POWER)
  CheckStatLT(Myself,19,STR)
  CheckStatLT(Myself,3,SCRIPTINGSTATE6)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(8,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_HOLY_POWER)
END

IF
  HaveSpell(CLERIC_DRAW_UPON_HOLY_MIGHT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(Myself,4,SCRIPTINGSTATE6)
  RandomNumLT(9,6)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
END

IF
  HaveSpell(CLERIC_RESIST_FIRE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(7)
    HitBy([ANYONE],MAGICFIRE)
    HitBy([ANYONE],MAGICCOLD)
    HitBy([ANYONE],FIRE)
    HitBy([ANYONE],COLD)
    RandomNumLT(12,8)
    CheckStatLT(Myself,40,RESISTMAGICFIRE)
    CheckStatLT(Myself,40,RESISTMAGICCOLD)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_RESIST_FIRE)
END

IF
  HaveSpell(CLERIC_BLESS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(Myself,STATE_BLESS)
  !StateCheck(Myself,STATE_CHANT)
  Range([GOODCUTOFF],12)
  RandomNumLT(11,7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_BLESS)
END

IF
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([GOODCUTOFF])
  OR(9)
    StateCheck(LastSeenBy(Myself),STATE_CHARMED)
    StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
    StateCheck(LastSeenBy(Myself),STATE_SILENCED)
    StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
    StateCheck(LastSeenBy(Myself),STATE_BLIND)
    StateCheck(LastSeenBy(Myself),STATE_STUNNED)
    StateCheck(LastSeenBy(Myself),STATE_SLOWED)
    StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
    StateCheck(LastSeenBy(Myself),STATE_FEEBLEMINDED)
  OR(2)
    !HasImmunityEffects(Myself)
    !Range(LastSeenBy(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_DISPEL_MAGIC)
END

IF
  HaveSpell(CLERIC_REMOVE_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See([GOODCUTOFF])
  StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),0)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_REMOVE_FEAR)
END

IF
  HaveSpell(PALADIN_PROTECTION_FROM_EVIL)
  CheckStat(Myself,0,117)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Detect([ANYONE])
  RandomNumLT(13,9)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,PALADIN_PROTECTION_FROM_EVIL)
END

IF
  HaveSpell(INNATE_PROTECTION_FROM_EVIL)
  CheckStat(Myself,0,117)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Detect([ANYONE])
  RandomNumLT(13,9)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,INNATE_PROTECTION_FROM_EVIL)
END

IF
  Heard([GOODCUTOFF],123)
  HaveSpell(PALADIN_LAY_ON_HANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  HPGT(LastHeardBy(Myself),0)
  HPPercentGT(Myself,75)
  Range(LastHeardBy(Myself),10)
  !Range([GOODCUTOFF.0.0.CLERIC_ALL],20)
  !HasItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
  !HasItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),PALADIN_LAY_ON_HANDS)
END

IF
  Heard([GOODCUTOFF],123)
  HaveSpell(INNATE_LAY_ON_HANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  HPGT(LastHeardBy(Myself),0)
  HPPercentGT(Myself,75)
  Range(LastHeardBy(Myself),10)
  !Range([GOODCUTOFF.0.0.CLERIC_ALL],20)
  !HasItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
  !HasItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),INNATE_LAY_ON_HANDS)
END

IF
  Heard([GOODCUTOFF],123)
  NumItemsGT("POTN55",Myself,1)
  HPGT(LastHeardBy(Myself),0)
  HPPercentGT(Myself,75)
  Range(LastHeardBy(Myself),10)
  !Range([GOODCUTOFF.0.0.CLERIC_ALL],20)
  !HasItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
  !HasItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
  !GlobalTimerNotExpired("GAVE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GAVE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,72809)  // ~Here! Catch!~
    GiveItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
    SmallWait(2)
    ActionOverride(LastHeardBy(Myself),DisplayStringHead(Myself,73896))  // ~Got it!~
END

IF
  Heard([GOODCUTOFF],123)
  NumItemsGT("POTN52",Myself,1)
  HPGT(LastHeardBy(Myself),0)
  HPPercentGT(Myself,75)
  See(LastHeardBy(Myself))
  Range(LastHeardBy(Myself),10)
  !Range([GOODCUTOFF.0.0.CLERIC_ALL],20)
  !HasItem("POTN55",LastHeardBy(Myself))  // ~Potion of Superior Healing~
  !HasItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
  !GlobalTimerNotExpired("GAVE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("GAVE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,72809)  // ~Here! Catch!~
    GiveItem("POTN52",LastHeardBy(Myself))  // ~Potion of Extra Healing~
    SmallWait(6)
    ActionOverride(LastHeardBy(Myself),DisplayStringHead(Myself,73896))  // ~Got it!~
END

IF
  Heard([GOODCUTOFF],83)
  !StateCheck(Myself,STATE_POISONED)
  HasItem("POTN20",Myself)  // ~Antidote~
THEN
  RESPONSE #100
    GiveItem("POTN20",LastHeardBy(Myself))  // ~Antidote~
END

IF
  Heard([GOODCUTOFF],83)
  HaveSpell(CLERIC_SLOW_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(Myself,STATE_POISONED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),CLERIC_SLOW_POISON)
END

IF
  ModalState(TURNUNDEAD)
  GlobalTimerNotExpired("BPTurn","LOCALS")
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Turn()
END

IF
  See([ENEMY])
  Alignment(LastSeenBy(Myself),MASK_EVIL)
  HaveSpell(CLERIC_HOLY_SMITE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(38,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_HOLY_SMITE)
END

IF
  See([EVILCUTOFF.UNDEAD])
  !GlobalTimerNotExpired("BPTurn","LOCALS")
  ActionListEmpty()
  HPPercentGT(Myself,50)
  ModalState(NONE)
  !Range([GOODCUTOFF.UNDEAD],15)
  RandomNumLT(44,12)
THEN
  RESPONSE #100
    SetGlobalTimer("BPTurn","LOCALS",TWO_ROUNDS)
    Turn()
END

