
IF
  Global("GBYesSir","LOCALS",0)
  Name("MoonDog",Myself)
THEN
  RESPONSE #100
    SetGlobal("GBYesSir","LOCALS",1)
    ChangeAIScript("",OVERRIDE)
END

IF
  !Specifics(Myself,200)
THEN
  RESPONSE #100
    ChangeSpecifics(Myself,200)
END

IF
  Class(Myself,GENIE_DJINNI)
  Global("GBIAmDjinn","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("GBIAmDjinn","LOCALS",1)
    DestroyItem("MonHP1")  // <Invalid Strref -1>
    ChangeAIScript("",OVERRIDE)
END

IF
  Class(Myself,GENIE_EFREETI)
  Global("GBIAmEfreet","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("GBIAmEfreet","LOCALS",1)
    ChangeAIScript("",OVERRIDE)
END

IF
  !Class(Myself,MAGE)
  !Class(Myself,FIGHTER)
  !Class(Myself,SPIDER_HUGE)
  HaveAnySpells()
  Global("GBChangeClass","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("GBChangeClass","LOCALS",1)
    ChangeClass(Myself,MAGE)
END

IF
  HotKey(E)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,14671)  // ~AI off~
    SetGlobalTimer("GBAIInterrupt","LOCALS",ONE_ROUND)
    PauseGame()
END

IF
  GlobalTimerNotExpired("GBAIInterrupt","LOCALS")
THEN
  RESPONSE #100
END

IF
  HotKey(S)
  Global("GBNoAI","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,14671)  // ~AI off~
    SetGlobal("GBNoAI","LOCALS",1)
END

IF
  HotKey(S)
  !Global("GBNoAI","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,14669)  // ~AI on~
    SetGlobal("GBNoAI","LOCALS",0)
END

IF
  Global("GBNoAI","LOCALS",1)
THEN
  RESPONSE #100
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
  ModalState(DETECTTRAPS)
THEN
  RESPONSE #100
END

IF
  ModalState(TURNUNDEAD)
  Global("GBTurned","LOCALS",1)
  GlobalTimerExpired("GBAutoTurning","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("GBTurned","LOCALS",0)
END

IF
  ModalState(TURNUNDEAD)
THEN
  RESPONSE #100
END

IF
  ModalState(STEALTH)
THEN
  RESPONSE #100
END

IF
  HotKey(K)
  Global("GBKillMyself","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Player1,13573)  // ~  It would be wise for you to leave.  Now.~
    DisplayStringHead(Myself,40115)  // ~Are you sure... you wish me to do this?~
    SetGlobal("GBKillMyself","LOCALS",1)
END

IF
  HotKey(K)
  Global("GBKillMyself","LOCALS",1)
THEN
  RESPONSE #100
    DisplayStringHead(Player1,32107)  // ~I am sure.  Good-bye.~
    DisplayStringHead(Myself,741)  // ~Farewell then. Take care.~
    ForceSpell(Myself,DRYAD_TELEPORT)
END

IF
  HotKey(N)
  !Global("GBKillMyself","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Player1,35233)  // ~No, don't go.  Just keep quiet.~
    DisplayStringHead(Myself,40148)  // ~As you wish, my <PRO_LADYLORD>.~
    SetGlobal("GBKillMyself","LOCALS",0)
END

IF
  Heard([GOODCUTOFF],203)
  !See(NearestEnemyOf(Myself))
THEN
  RESPONSE #500
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #100
    VerbalConstant(Myself,65)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #50
    VerbalConstant(Myself,BATTLE_CRY)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #50
    VerbalConstant(Myself,10)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #50
    VerbalConstant(Myself,11)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,SELECT_COMMON)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,27)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,28)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,29)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,30)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,31)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,SELECT_ACTION)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,33)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,34)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,SELECT_RARE)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,36)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,37)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,38)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,63)
    MoveToObject(LastHeardBy(Myself))
  RESPONSE #25
    VerbalConstant(Myself,64)
    MoveToObject(LastHeardBy(Myself))
END

IF
  ActionListEmpty()
  CheckStatGT(Player1,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player1)
  !HasBounceEffects(Player1)
  !StateCheck(Player1,STATE_INVISIBLE)
  !StateCheck(Player1,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player1,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  CheckStatGT(Player2,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player2)
  !HasBounceEffects(Player2)
  !StateCheck(Player2,STATE_INVISIBLE)
  !StateCheck(Player2,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player2,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  CheckStatGT(Player3,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player3)
  !HasBounceEffects(Player3)
  !StateCheck(Player3,STATE_INVISIBLE)
  !StateCheck(Player3,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player3,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  CheckStatGT(Player4,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player4)
  !HasBounceEffects(Player4)
  !StateCheck(Player4,STATE_INVISIBLE)
  !StateCheck(Player4,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player4,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  CheckStatGT(Player5,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player5)
  !HasBounceEffects(Player5)
  !StateCheck(Player5,STATE_INVISIBLE)
  !StateCheck(Player5,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player5,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  CheckStatGT(Player6,0,200)
  CombatCounter(0)
  HaveSpell(CLERIC_LESSER_RESTORATION)
  See(Player6)
  !HasBounceEffects(Player6)
  !StateCheck(Player6,STATE_INVISIBLE)
  !StateCheck(Player6,STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(Player6,CLERIC_LESSER_RESTORATION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  !Global("GBHealInProgress","GLOBAL",0)
  !GlobalTimerNotExpired("GBHealingNow","GLOBAL")
THEN
  RESPONSE #100
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  HaveSpell(CLERIC_MASS_CURE)
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  OR(5)
    HPPercentLT(Player1,85)
    HPPercentLT(Player2,85)
    HPPercentLT(Player3,85)
    HPPercentLT(Player4,85)
    HPPercentLT(Player5,85)
  OR(5)
    HPPercentLT(Player1,85)
    HPPercentLT(Player2,85)
    HPPercentLT(Player3,85)
    HPPercentLT(Player4,85)
    HPPercentLT(Player6,85)
  OR(5)
    HPPercentLT(Player1,85)
    HPPercentLT(Player2,85)
    HPPercentLT(Player3,85)
    HPPercentLT(Player5,85)
    HPPercentLT(Player6,85)
  OR(5)
    HPPercentLT(Player1,85)
    HPPercentLT(Player2,85)
    HPPercentLT(Player4,85)
    HPPercentLT(Player5,85)
    HPPercentLT(Player6,85)
  OR(5)
    HPPercentLT(Player1,85)
    HPPercentLT(Player3,85)
    HPPercentLT(Player4,85)
    HPPercentLT(Player5,85)
    HPPercentLT(Player6,85)
  OR(5)
    HPPercentLT(Player2,85)
    HPPercentLT(Player3,85)
    HPPercentLT(Player4,85)
    HPPercentLT(Player5,85)
    HPPercentLT(Player6,85)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(MostDamagedOf(Myself),CLERIC_MASS_CURE)
END

IF
  ActionListEmpty()
  RandomNum(10,1)
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),50)
  HaveSpell(CLERIC_HEAL)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_HEAL)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  RandomNum(10,1)
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),50)
  HaveSpell(CLERIC_RESURRECTION)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_RESURRECTION)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  RandomNum(10,1)
  ActionListEmpty()
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),60)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_CURE_CRITICAL_WOUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  RandomNum(10,1)
  ActionListEmpty()
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),70)
  HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_CURE_SERIOUS_WOUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  RandomNum(10,1)
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),80)
  HaveSpell(CLERIC_CURE_MEDIUM_WOUNDS)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_CURE_MEDIUM_WOUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  ActionListEmpty()
  RandomNum(10,1)
  CombatCounter(0)
  HPPercentLT(MostDamagedOf(Myself),90)
  HaveSpell(CLERIC_CURE_LIGHT_WOUNDS)
  See(MostDamagedOf(Myself))
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  Global("GBHealInProgress","GLOBAL",0)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    SetGlobalTimer("GBHealingNow","GLOBAL",FIVE_ROUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",1)
    Spell(MostDamagedOf(Myself),CLERIC_CURE_LIGHT_WOUNDS)
    SetGlobal("GBHealInProgress","GLOBAL",0)
END

IF
  Heard([GOODCUTOFF],200)
  HaveSpell(CLERIC_RESURRECTION)
  !HasBounceEffects(LastHeardBy(Myself))
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
  InParty(LastHeardBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    Spell(LastHeardBy(Myself),CLERIC_RESURRECTION)
END

IF
  Heard([GOODCUTOFF],200)
  HaveSpell(CLERIC_HEAL)
  !HasBounceEffects(LastHeardBy(Myself))
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
  InParty(LastHeardBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    Spell(LastHeardBy(Myself),CLERIC_HEAL)
END

IF
  Heard([GOODCUTOFF],200)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  !HasBounceEffects(LastHeardBy(Myself))
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
  InParty(LastHeardBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    Spell(LastHeardBy(Myself),CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  Heard([GOODCUTOFF],200)
  HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  !HasBounceEffects(LastHeardBy(Myself))
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
  InParty(LastHeardBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    MakeUnselectable(2)
    Spell(LastHeardBy(Myself),CLERIC_CURE_SERIOUS_WOUNDS)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT(Player1,90)
  See(Player1)
  OR(2)
    CombatCounter(0)
    HPPercentLT(Player1,25)
  OR(2)
    !CombatCounter(0)
    Global("HealedPlayer1","LOCALS",0)
  !StateCheck(Player1,STATE_INVISIBLE)
  !StateCheck(Player1,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject(Player1)
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobal("HealedPlayer1","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player1,INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT("Imoen2",90)  // ~Imoen~
  See("Imoen2")  // ~Imoen~
  OR(2)
    CombatCounter(0)
    HPPercentLT("Imoen2",25)  // ~Imoen~
  OR(2)
    !CombatCounter(0)
    Global("HealedImoen2","LOCALS",0)
  !StateCheck("Imoen2",STATE_INVISIBLE)  // ~Imoen~
  !StateCheck("Imoen2",STATE_IMPROVEDINVISIBILITY)  // ~Imoen~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject("Imoen2")
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobal("HealedImoen2","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell("Imoen2",INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT("Aerie",90)  // ~Aerie~
  See("Aerie")  // ~Aerie~
  OR(2)
    CombatCounter(0)
    HPPercentLT("Aerie",25)  // ~Aerie~
  OR(2)
    !CombatCounter(0)
    Global("HealedAerie","LOCALS",0)
  !StateCheck("Aerie",STATE_INVISIBLE)  // ~Aerie~
  !StateCheck("Aerie",STATE_IMPROVEDINVISIBILITY)  // ~Aerie~
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject("Aerie")
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobal("HealedAerie","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell("Aerie",INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT("Viconia",90)  // Viconia
  See("Viconia")  // Viconia
  OR(2)
    CombatCounter(0)
    HPPercentLT("Viconia",25)  // Viconia
  OR(2)
    !CombatCounter(0)
    Global("HealedViconia","LOCALS",0)
  !StateCheck("Viconia",STATE_INVISIBLE)  // Viconia
  !StateCheck("Viconia",STATE_IMPROVEDINVISIBILITY)  // Viconia
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject("Viconia")
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobal("HealedViconia","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell("Viconia",INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT("Anomen",90)  // Anomen
  See("Anomen")  // Anomen
  OR(2)
    CombatCounter(0)
    HPPercentLT("Anomen",25)  // Anomen
  OR(2)
    !CombatCounter(0)
    Global("HealedAnomen","LOCALS",0)
  !StateCheck("Anomen",STATE_INVISIBLE)  // Anomen
  !StateCheck("Anomen",STATE_IMPROVEDINVISIBILITY)  // Anomen
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject("Anomen")
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobal("HealedAnomen","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell("Anomen",INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT(WeakestOf(Myself),90)
  See(WeakestOf(Myself))
  OR(2)
    CombatCounter(0)
    HPPercentLT(WeakestOf(Myself),25)
  !StateCheck(WeakestOf(Myself),STATE_INVISIBLE)
  !StateCheck(WeakestOf(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject(WeakestOf(Myself))
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(WeakestOf(Myself),INVISIBILITY_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDLick","LOCALS",3)
  HPPercentLT(MostDamagedOf(Myself),90)
  See(MostDamagedOf(Myself))
  OR(2)
    CombatCounter(0)
    HPPercentLT(MostDamagedOf(Myself),25)
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    MakeUnselectable(2)
    MoveToObject(MostDamagedOf(Myself))
    IncrementGlobal("GBMDLick","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(MostDamagedOf(Myself),INVISIBILITY_SELF)
END

IF
  CombatCounter(0)
  HaveSpell(CLERIC_AID)
  See(MostDamagedOf(Myself))
  !StateCheck(LastSeenBy(Myself),STATE_AID)
  !HasBounceEffects(MostDamagedOf(Myself))
  !StateCheck(MostDamagedOf(Myself),STATE_INVISIBLE)
  !StateCheck(MostDamagedOf(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    Spell(MostDamagedOf(Myself),CLERIC_AID)
END

IF
  HotKey(F)
  Global("GBFleetofFoot","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,44441)  // ~Run away!  Run away!  Ha ha ha!!~
    SetGlobal("GBFleetofFoot","LOCALS",1)
END

IF
  HotKey(F)
  !Global("GBFleetofFoot","LOCALS",0)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,24713)  // ~I will not hide from such filth as you. Come and die, if you are brave enough!~
    SetGlobal("GBFleetofFoot","LOCALS",0)
END

IF
  !Global("GBFleetofFoot","LOCALS",0)
  GlobalLT("GBFoFRunning","LOCALS",4)
  !InParty(LastAttackerOf(Myself))
  See(NearestEnemyOf(Myself))
  Range(LastAttackerOf(Myself),10)
  HPGT(LastAttackerOf(Myself),1)
  !GlobalTimerNotExpired("GBFleetFootTimer","LOCALS")
THEN
  RESPONSE #100
    DisplayStringHead(Myself,44441)  // ~Run away!  Run away!  Ha ha ha!!~
    SetGlobalTimer("GBFleetFootTimer","LOCALS",TWO_ROUNDS)
    IncrementGlobal("GBFoFRunning","LOCALS",1)
    RandomWalkContinuous()
END

IF
  GlobalTimerNotExpired("GBFleetFootTimer","LOCALS")
  GlobalLT("GBFoFRunning","LOCALS",4)
  !InParty(LastAttackerOf(Myself))
  See(NearestEnemyOf(Myself))
  Range(LastAttackerOf(Myself),10)
  HPGT(LastAttackerOf(Myself),1)
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  GlobalGT("GBFoFRunning","LOCALS",0)
  CombatCounter(0)
  !Detect([EVILCUTOFF])
THEN
  RESPONSE #100
    SetGlobal("GBFoFRunning","LOCALS",0)
END

IF
  !See(NearestEnemyOf(Myself))
  !Detect([EVILCUTOFF])
  CombatCounter(0)
THEN
  RESPONSE #100
END

IF
  CombatCounter(0)
  Detect([EVILCUTOFF])
  HPGT([EVILCUTOFF],1)
THEN
  RESPONSE #100
    StartCombatCounter()
    Continue()
END

IF
  GlobalTimerNotExpired("GBHalfAttack","LOCALS")
  See(NearestEnemyOf(Myself))
  Range(LastSeenBy(Myself),8)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    Attack(LastSeenBy(Myself))
END

IF
  GlobalTimerNotExpired("GBHalfAttack","LOCALS")
  OR(3)
    See(NearestEnemyOf(Myself))
    See(TenthNearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(TenthNearestEnemyOfType([0.0.0.LONG_BOW]))
  !Range(LastSeenBy(Myself),8)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    EquipRanged()
    Attack(LastSeenBy(Myself))
END

IF
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  See(NearestEnemyOfType([0.0.TROLL]))
  HP(LastSeenBy(Myself),1)
  HasItemEquiped("TROLLDIE",LastSeenBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  See(NearestEnemyOfType([0.0.TROLL]))
  HP(LastSeenBy(Myself),1)
  HasItemEquiped("TROLLDIE",LastSeenBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  HaveSpell(WIZARD_FLAME_ARROW)
  See(NearestEnemyOfType([0.0.TROLL]))
  HP(LastSeenBy(Myself),1)
  HasItemEquiped("TROLLDIE",LastSeenBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  HaveSpell(CLERIC_FLAME_STRIKE)
  See(NearestEnemyOfType([0.0.TROLL]))
  HP(LastSeenBy(Myself),1)
  HasItemEquiped("TROLLDIE",LastSeenBy(Myself))
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
END

IF
  Global("GBIAmDjinn","LOCALS",1)
  Global("GBGeniePrep","LOCALS",0)
  See([ENEMY])
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    ReallyForceSpell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    SetGlobal("GBGeniePrep","LOCALS",1)
END

IF
  Global("GBIAmEfreet","LOCALS",1)
  Global("GBGeniePrep","LOCALS",0)
  See([ENEMY])
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    SetGlobal("GBGeniePrep","LOCALS",1)
END

IF
  Race(Myself,HUMAN)
  Class(Myself,FIGHTER)
  CheckStat(Myself,9,LEVEL)
  CheckStat(Myself,17,STR)
  Alignment(Myself,CHAOTIC_GOOD)
  GlobalLT("GBValhallaBerserker","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("GBValhallaBerserker","LOCALS",1)
    ReallyForceSpell(Myself,BERSERKER_RAGE)
END

IF
  Class(Myself,SPIDER_HUGE)
  GlobalLT("KitthixWeb","LOCALS",2)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBKitthixWeb","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),FIGURINE_SPIDER_WEB)
END

IF
  HaveSpell(CLERIC_TRUE_SIGHT)
  Detect([EVILCUTOFF])
  OR(6)
    !See(LastSeenBy(Myself))
    See(NearestEnemyOfType([EVILCUTOFF.0.0.0.0.ILLUSIONARY]))
    StateCheck([EVILCUTOFF],STATE_INVISIBLE)
    StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
    StateCheck([EVILCUTOFF],STATE_MIRRORIMAGE)
    StateCheck([EVILCUTOFF],STATE_BLUR)
  !HPLT(LastSeenBy(Myself),1)
  !GlobalTimerNotExpired("GBClrTrueSght","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBClrTrueSght","LOCALS",ONE_TURN)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_TRUE_SIGHT)
END

IF
  Detect([EVILCUTOFF])
  OR(6)
    !See(LastSeenBy(Myself))
    See(NearestEnemyOfType([EVILCUTOFF.0.0.0.0.ILLUSIONARY]))
    StateCheck([EVILCUTOFF],STATE_INVISIBLE)
    StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
    StateCheck([EVILCUTOFF],STATE_MIRRORIMAGE)
    StateCheck([EVILCUTOFF],STATE_BLUR)
  Name("Moondog",Myself)
  GlobalLT("GBMDSight","LOCALS",3)
  !GlobalTimerNotExpired("GBTrueSght","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    SetGlobalTimer("GBTrueSght","LOCALS",TWO_ROUNDS)
    IncrementGlobal("GBMDSight","LOCALS",1)
    Spell(Myself,MOON_DOG_HOWL)
END

IF
  HaveSpell(WIZARD_DETECT_INVISIBILITY)
  Detect([EVILCUTOFF])
  OR(3)
    !See(LastSeenBy(Myself))
    StateCheck([EVILCUTOFF],STATE_INVISIBLE)
    StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
  !HPLT(LastSeenBy(Myself),1)
  !GlobalTimerNotExpired("GBWizDetInvs","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBWizDetInvs","LOCALS",FOUR_TURNS)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_DETECT_INVISIBILITY)
END

IF
  StateCheck(Player1,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player1,STATE_INVISIBLE)
  !StateCheck(Player1,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player1,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player2,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player2,STATE_INVISIBLE)
  !StateCheck(Player2,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player2,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player3,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player3,STATE_INVISIBLE)
  !StateCheck(Player3,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player3,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player4,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player4,STATE_INVISIBLE)
  !StateCheck(Player4,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player4,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player5,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player5,STATE_INVISIBLE)
  !StateCheck(Player5,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player5,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player6,STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck(Player6,STATE_INVISIBLE)
  !StateCheck(Player6,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player6,CLERIC_REMOVE_FEAR)
END

IF
  StateCheck([GOODCUTOFF],STATE_PANIC)
  HaveSpell(CLERIC_REMOVE_FEAR)
  !StateCheck([GOODCUTOFF],STATE_INVISIBLE)
  !StateCheck([GOODCUTOFF],STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell([GOODCUTOFF],CLERIC_REMOVE_FEAR)
END

IF
  StateCheck(Player1,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player1,STATE_INVISIBLE)
  !StateCheck(Player1,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player1,CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck(Player2,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player2,STATE_INVISIBLE)
  !StateCheck(Player2,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player2,CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck(Player3,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player3,STATE_INVISIBLE)
  !StateCheck(Player3,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player3,CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck(Player4,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player4,STATE_INVISIBLE)
  !StateCheck(Player4,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player4,CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck(Player5,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player5,STATE_INVISIBLE)
  !StateCheck(Player5,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player5,CLERIC_NEUTRALIZE_POISON)
END

IF
  StateCheck(Player6,STATE_POISONED)
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !StateCheck(Player6,STATE_INVISIBLE)
  !StateCheck(Player6,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Player6,CLERIC_NEUTRALIZE_POISON)
END

IF
  See(NearestEnemyOfType([EVILCUTOFF.UNDEAD]))
  !GlobalTimerNotExpired("GBTurnedUndead","LOCALS")
  CheckStatGT(Myself,12,TURNUNDEADLEVEL)
  Range(LastSeenBy(Myself),8)
  !Kit(Myself,16)
  !Class(Myself,DRUID_ALL)
THEN
  RESPONSE #100
    SetGlobalTimer("GBAutoTurning","LOCALS",ONE_ROUND)
    SetGlobalTimer("GBTurnedUndead","LOCALS",THREE_ROUNDS)
    SetGlobal("GBTurned","LOCALS",1)
    Turn()
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDHowl","LOCALS",3)
  !GlobalTimerNotExpired("GBMDHowl","LOCALS")
  See(NearestEnemyOf(Myself))
  Range(NearestEnemyOf(Myself),8)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBMDHowl","LOCALS",TWO_ROUNDS)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    IncrementGlobal("GBMDHowl","LOCALS",1)
    Spell(Myself,MOON_DOG_FEAR)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDInvis","LOCALS",1)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    IncrementGlobal("GBMDInvis","LOCALS",1)
    Spell(Myself,NON_DETECTION_SELF)
END

IF
  Name("Moondog",Myself)
  GlobalLT("GBMDMirror","LOCALS",3)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    IncrementGlobal("GBMDMirror","LOCALS",1)
    Spell(Myself,HASTE_SELF)
END

IF
  HaveSpell(WIZARD_BLUR)
  !StateCheck(Myself,STATE_BLUR)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_BLUR)
END

IF
  HaveSpell(CLERIC_CLOAK_OF_FEAR)
  See(NearestEnemyOf(Myself))
  Range(NearestEnemyOf(Myself),8)
  !Race(LastSeenBy(Myself),BEHOLDER)
  !Race(LastSeenBy(Myself),WYVERN)
  !Race(LastSeenBy(Myself),KUO-TOA)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !GlobalTimerNotExpired("GBClrFearCloak","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBClrFearCloak","LOCALS",ONE_TURN)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_CLOAK_OF_FEAR)
END

IF
  Global("GBIAmEfreet","LOCALS",1)
  GlobalLT("GBEfreetFireball","LOCALS",3)
  !Range([PC],15)
  See(NearestEnemyOf(Myself))
  RandomNum(3,1)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBEfreetFireball","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_FIREBALL)
END

IF
  Global("GBIAmEfreet","LOCALS",1)
  GlobalLT("GBEfreetFlameStrike","LOCALS",3)
  RandomNum(3,1)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBEfreetFlameStrike","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),CLERIC_FLAME_STRIKE)
END

IF
  Global("GBIAmEfreet","LOCALS",1)
  GlobalLT("GBEfreetFlameArrow","LOCALS",3)
  RandomNum(3,1)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBEfreetFlameArrow","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END

IF
  Global("GBIAmDjinn","LOCALS",1)
  GlobalLT("GBDjinnChain","LOCALS",3)
  RandomNum(3,1)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBDjinnChain","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_CHAIN_LIGHTNING)
END

IF
  Global("GBIAmDjinn","LOCALS",1)
  GlobalLT("GBDjinnLightning","LOCALS",3)
  RandomNum(3,1)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBDjinnLightning","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_LIGHTNING_BOLT)
END

IF
  Global("GBIAmDjinn","LOCALS",1)
  GlobalLT("GBDjinnMagicMissile","LOCALS",3)
  RandomNum(3,1)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    IncrementGlobal("GBDjinnMagicMissile","LOCALS",1)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    ForceSpell(NearestEnemyOf(Myself),WIZARD_FLAME_ARROW)
END

IF
  HaveSpell(WIZARD_HASTE)
  See(NearestEnemyOf(Myself))
  CheckStatLT(Myself,2,FATIGUE)
  !StateCheck(Myself,STATE_HASTED)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_HASTE)
END

IF
  HaveSpell(WIZARD_GHOST_ARMOR)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_GHOST_ARMOR)
END

IF
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  OR(4)
    See(TenthNearestEnemyOfType([0.0.0.BARD_ALL]))
    See(TenthNearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(TenthNearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(TenthNearestEnemyOfType([0.0.0.LONG_BOW]))
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  HaveSpell(CLERIC_SYMBOL_FEAR)
  !Range([PC],10)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !CheckStatLT(LastSeenBy(Myself),5,SAVEVSSPELL)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !Race(LastSeenBy(Myself),BEHOLDER)
  !Race(LastSeenBy(Myself),WYVERN)
  !Race(LastSeenBy(Myself),KUO-TOA)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_SYMBOL_FEAR)
END

IF
  HaveSpell(CLERIC_SYMBOL_DEATH)
  !Range([PC],10)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !CheckStatLT(LastSeenBy(Myself),5,SAVEVSSPELL)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  HPLT(LastSeenBy(Myself),60)
  HPGT(Myself,60)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),TROLL)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_SYMBOL_DEATH)
END

IF
  HaveSpell(CLERIC_HOLY_WORD)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Alignment(LastSeenBy(Myself),MASK_EVIL)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_HOLY_WORD)
END

IF
  HaveSpell(CLERIC_FIRE_STORM)
  !Range([PC],10)
  See(NearestEnemyOf(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTFIRE)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !Range([PC],8)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(NearestEnemyOf(Myself),CLERIC_FIRE_STORM)
END

IF
  False()
  HaveSpell(CLERIC_EARTHQUAKE)
  !Range([PC],10)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !Range([PC],8)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(NearestEnemyOf(Myself),CLERIC_EARTHQUAKE)
END

IF
  HaveSpell(CLERIC_INSECT_PLAGUE)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
END

IF
  HaveSpell(WIZARD_MAGIC_MISSILE)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  HaveSpell(WIZARD_MELF_ACID_ARROW)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTACID)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_MELF_ACID_ARROW)
END

IF
  HaveSpell(WIZARD_FLAME_ARROW)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTFIRE)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  HaveSpell(CLERIC_FLAME_STRIKE)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTFIRE)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
END

IF
  HaveSpell(WIZARD_AGANNAZAR_SCORCHER)
  See(NearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),8)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTFIRE)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_AGANNAZAR_SCORCHER)
END

IF
  HaveSpell(WIZARD_CHAOS)
  See(NearestEnemyOf(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_CHAOS)
END

IF
  HaveSpell(WIZARD_LIGHTNING_BOLT)
  See(NearestEnemyOf(Myself))
  !Range(LastSeenBy(Myself),12)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTELECTRICITY)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_LIGHTNING_BOLT)
END

IF
  HaveSpell(CLERIC_CAUSE_SERIOUS_WOUNDS)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Range(LastSeenBy(Myself),8)
  !HasItemSlot(Myself,SLOT_MISC19)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    Spell(Myself,CLERIC_CAUSE_SERIOUS_WOUNDS)
    Attack(LastSeenBy(Myself))
END

IF
  HaveSpell(CLERIC_MISCAST_MAGIC)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_MISCAST_MAGIC)
END

IF
  HaveSpell(CLERIC_CALL_LIGHTNING)
  AreaType(OUTDOOR)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),25,RESISTELECTRICITY)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CALL_LIGHTNING)
END

IF
  HaveSpell(CLERIC_HOLD_PERSON)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  General(LastSeenBy(Myself),HUMANOID)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_HOLD_PERSON)
END

IF
  HaveSpell(CLERIC_BARKSKIN)
  See(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("GBClrBarkskin","LOCALS")
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBClrBarkskin","LOCALS",90)
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_BARKSKIN)
END

IF
  HaveSpell(CLERIC_MENTAL_DOMINATION)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !Race(LastSeenBy(Myself),WYVERN)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_MENTAL_DOMINATION)
END

IF
  HaveSpell(CLERIC_CONFUSION)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CONFUSION)
END

IF
  HaveSpell(NYMPH_CONFUSION)
  See(NearestEnemyOf(Myself))
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),NYMPH_CONFUSION)
END

IF
  HaveSpell(WIZARD_HOLD_MONSTER)
  See(NearestEnemyOf(Myself))
  !HasBounceEffects(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !Race(LastSeenBy(Myself),BEHOLDER)
  !Race(LastSeenBy(Myself),WYVERN)
  !Race(LastSeenBy(Myself),KUO-TOA)
  !General(LastSeenBy(Myself),UNDEAD)
  !Race(LastSeenBy(Myself),SLIME)
  !Race(LastSeenBy(Myself),DRAGON)
  !Race(LastSeenBy(Myself),TROLL)
  !Race(LastSeenBy(Myself),RAKSHASA)
  !Race(LastSeenBy(Myself),DEMONIC)
  !CheckStatGT(Myself,35,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("GBHalfAttack","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_HOLD_MONSTER)
END

IF
  HasItemEquiped("NISHRUU",Myself)
  OR(4)
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.LONG_BOW]))
THEN
  RESPONSE #100
    Attack(LastSeenBy(Myself))
END

IF
  OR(3)
    See(NearestEnemyOf(Myself))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.LONG_BOW]))
  Range(LastSeenBy(Myself),8)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    Attack(LastSeenBy(Myself))
END

IF
  OR(3)
    See(NearestEnemyOf(Myself))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.LONG_BOW]))
  !Range(LastSeenBy(Myself),8)
  !InParty(LastSeenBy(Myself))
  !Class(LastSeenBy(Myself),INNOCENT)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
  RESPONSE #100
    EquipRanged()
    Attack(LastSeenBy(Myself))
END

