IF
  Die()
THEN
  RESPONSE #100
    CreateVisualEffectObject("SPHOLY",Myself)
    DestroySelf()
END

IF
  HotKey(K)
  Global("scriptoff","locals",0)
THEN
  RESPONSE #100
    SetGlobal("scriptoff","locals",1)
    DisplayStringHead(Myself,@1)
END

IF
  HotKey(K)
  Global("scriptoff","locals",1)
THEN
  RESPONSE #100
    SetGlobal("scriptoff","locals",0)
    DisplayStringHead(Myself,@2)
END

IF
  Global("scriptoff","locals",1)
THEN
  RESPONSE #100
END

IF
  Global("Init","locals",0)
THEN
  RESPONSE #100
    SetGlobal("init","locals",1)
    SetGlobalTimer("action_interruptible","locals",1)
    Continue()
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("rem_fear","locals")
  See([ANYONE])
  StateCheck(LastSeenBy(Myself),STATE_PANIC)
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  OR(2)
    Allegiance(Myself,EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  HaveSpellRES("tg#rc05") //remove fear
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("rem_fear","locals",THREE_ROUNDS)
    SpellRES("tg#rc05",LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("buff","locals")
//  HaveSpell(CLERIC_SANCTUARY)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("buff","locals",FIVE_ROUNDS)
//    SetGlobal("bladeb","locals",1)
//    Spell(Myself,CLERIC_SANCTUARY)
    SpellRES("tg#rc50",Myself) //summon fallen deva
//    SpellRES("tg#rc43",Myself)  // ~Globe of Blades~
//    Spell(Myself,CLERIC_AURA_OF_FLAMING_DEATH)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("buff","locals")
  See([ANYONE])
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  OR(2)
    Allegiance(Myself,EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  HaveSpell(CLERIC_FREE_ACTION)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("buff","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_FREE_ACTION)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("buff","locals")
  See([ANYONE])
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  OR(2)
    Allegiance(Myself,EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  !StateCheck(LastSeenBy(Myself),STATE_CHANT)
  HaveSpell(CLERIC_CHANT)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("buff","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_CHANT)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("buff","locals")
  See([ANYONE])
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  OR(2)
    Allegiance(Myself,EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
  CheckStatLT(LastSeenBy(Myself),40,RESISTFIRE)
  HaveSpell(CLERIC_RESIST_FIRE)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("buff","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_RESIST_FIRE)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("buff","locals")
  Global("armorfaith","locals",0)
  HaveSpell(CLERIC_ARMOR_OF_FAITH)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("buff","locals",FIVE_ROUNDS)
    SetGlobal("armoroffaith","locals",1)
    Spell(Myself,CLERIC_ARMOR_OF_FAITH)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("turn","locals")
  OR(6)
       General(NearestEnemyOf(Myself),UNDEAD)
       General(SecondNearestEnemyOf(Myself),UNDEAD)
       General(ThirdNearestEnemyOf(Myself),UNDEAD)
       Class(NearestEnemyOf(Myself),PALADIN_ALL)
       Class(SecondNearestEnemyOf(Myself),PALADIN_ALL)
       Class(ThirdNearestEnemyOf(Myself),PALADIN_ALL)
THEN
  RESPONSE #100
    SetGlobalTimer("turn","locals",60)
    SetInterrupt(FALSE)
    Turn()
    Wait(5)
    SetInterrupt(TRUE)
END

IF
  See(NearestEnemyOf(Myself))
  OR(2)
    !Exists(LastAttackerOf(Myself))
    !See(LastAttackerOf(Myself))
  OR(4)
    !Exists(NearestEnemyOf(Myself))
    !Class(NearestEnemyOf(Myself),LONG_BOW)
    !Class(NearestEnemyOf(Myself),SORCERER)
    !See(NearestEnemyOf(Myself))
  OR(4)
    !Exists(SecondNearestEnemyOf(Myself))
    !Class(SecondNearestEnemyOf(Myself),LONG_BOW)
    !Class(SecondNearestEnemyOf(Myself),SORCERER)
    !See(SecondNearestEnemyOf(Myself))
  OR(4)
    !Exists(NearestEnemyOf(Myself))
    !Class(NearestEnemyOf(Myself),CLERIC_ALL)
    !Class(NearestEnemyOf(Myself),DRUID_ALL)
    !See(NearestEnemyOf(Myself))
  OR(4)
    !Exists(SecondNearestEnemyOf(Myself))
    !Class(SecondNearestEnemyOf(Myself),CLERIC_ALL)
    !Class(SecondNearestEnemyOf(Myself),DRUID_ALL)
    !See(SecondNearestEnemyOf(Myself))
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  OR(2)
    Allegiance(Myself,GOODCUTOFF)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  OR(2)
    Allegiance(Myself,EVILCUTOFF)
    !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    NoAction()
END

 IF
  ActionListEmpty()
  GlobalTimerExpired("action_interruptible","locals")
  GlobalTimerNotExpired("cast","locals")
  CheckStatLT(LastSeenBy(Myself),2,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
  RESPONSE #100
    SetGlobalTimer("action_interruptible","locals",1)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  OR(4)
    StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
    StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
    CheckStatGT(LastSeenBy(Myself),0,SANCTUARY)
    Detect(NearestEnemyOfType([0.0.0.0.0.ILLUSIONARY]))
  !StateCheck(LastSeenBy(Myself),STATE_NONDETECTION)
  Global("trues","locals",0)
  HaveSpellRES("tg#rc29")  // true sight
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobal("trues","locals",1)
    SpellRES("tg#rc29",Myself)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  Global("doom","locals",0)
  HaveSpellRES("tg#rc19")
  CheckStatLT(LastSeenBy(Myself),6,SAVEVSSPELL)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobal("doom","locals",1)
    SpellRES("tg#rc19",LastSeenBy(Myself))  // ~Doom~
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  CheckStatLT(LastSeenBy(Myself),7,SAVEVSSPELL)
  HaveSpell(1718) //cleric symbol stun, not appearing on standard IDS
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    Spell(LastSeenBy(Myself),1718)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  HaveSpellRES("tg#rc39") //symbol, death
  HPLT(LastSeenBy(Myself),60)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  Range(LastSeenBy(Myself),3)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SpellRES("tg#rc39",LastSeenBy(Myself))
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("slay","locals")
  HaveSpell(CLERIC_FINGER_OF_DEATH)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  Range(LastSeenBy(Myself),3)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("slay","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("slay","locals")
  HaveSpellRES("tg#rc25")
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  Range(LastSeenBy(Myself),3)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("slay","locals",FIVE_ROUNDS)
    SpellRES("tg#rc25",LastSeenBy(Myself))  // ~Slay Living~
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("dominion","locals")
  HaveSpell(CLERIC_MENTAL_DOMINATION)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("dominion","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_MENTAL_DOMINATION)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("unholyword","locals")
  HaveSpellRES("tg#rc26")
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("unholyword","locals",TEN_ROUNDS)
    SpellRES("tg#rc26",Myself)  // ~Unholy Word~
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("flamestrike","locals")
  CheckStatLT(LastSeenBy(Myself),75,RESISTFIRE)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  HaveSpell(CLERIC_FLAME_STRIKE)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("flamestrike","locals",THREE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("grcommand","locals")
  HaveSpell(CLERIC_GREATER_COMMAND)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("grcommand","locals",FIVE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_GREATER_COMMAND)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("unholy","locals")
  HaveSpell(CLERIC_UNHOLY_BLIGHT)
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  CheckStatLT(LastSeenBy(Myself),75,MAGICDAMAGERESISTANCE)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("unholy","locals",THREE_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_UNHOLY_BLIGHT)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("poison","locals")
  HaveSpell(CLERIC_POISON)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSDEATH)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("poison","locals",TEN_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_POISON)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  Global("fear","locals",0)
  HaveSpellRES("tg#rc23")
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  Range(LastSeenBy(Myself),7)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobal("fear","locals",1)
    SpellRES("tg#rc23",Myself)  // ~Cloak of Fear~
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("hold","locals")
  HaveSpellRES("tg#rc49")
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("hold","locals",TEN_ROUNDS)
    SpellRES("tg#rc49",LastSeenBy(Myself))  // ~Hold Person~
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  !GlobalTimerNotExpired("silence","locals")
  HaveSpell(CLERIC_SILENCE_15_FOOT)
  OR(4)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SetGlobalTimer("silence","locals",TEN_ROUNDS)
    Spell(LastSeenBy(Myself),CLERIC_SILENCE_15_FOOT)
END

IF
  OR(2)
    ActionListEmpty()
    GlobalTimerNotExpired("action_interruptible","locals")
  !GlobalTimerNotExpired("cast","locals")
  HaveSpellRES("tg#rc36") //cause critical wounds
  CheckStatLT(LastSeenBy(Myself),75,RESISTMAGIC)
  Range(LastSeenBy(Myself),3)
THEN
  RESPONSE #100
    SetGlobalTimer("cast","locals",ONE_ROUND)
    SpellRES("tg#rc36",LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  GlobalTimerExpired("action_interruptible","locals")
  GlobalTimerExpired("cast","locals")
  CheckStatLT(LastSeenBy(Myself),3,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
  RESPONSE #100
    SetGlobalTimer("action_interruptible","locals",1)
    AttackOneRound(LastSeenBy(Myself))
END

