IF
  HPLT(Myself,20)
  Global("DeathScriptSend","AR6200",0)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobal("DeathScriptSend","AR6200",1)
    ClearActions(Myself)
    CreateVisualEffectObject("ICRMPARI",Myself)
    CreateVisualEffectObject("SPROTECT",Myself)
    ActionOverride("finmel01",ClearActions(Myself))
    ActionOverride("finmel01",DestroyItem("finsend"))  // <Invalid Strref -1>
    ReallyForceSpellDeadRES("melspl10","finmel01")
    Kill(Myself)
END

IF
  Global("IMPRISON","LOCALS",1)
  Global("SendaiImprisoned","AR6200",0)
THEN
  RESPONSE #100
    ClearActions(Myself)
    SetInterrupt(FALSE)
    SetGlobal("IMPRISON","LOCALS",0)
    SetGlobal("SendaiImprisoned","AR6200",1)
    DisplayStringHead(Myself,46151)  // ~help!~
    SetInterrupt(TRUE)
END

IF
  Global("CloseCombat","LOCALS",1)
  GlobalTimerExpired("attacked","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",0)
    SetGlobalTimer("SafeForAWhile","LOCALS",6)
END

IF
  Global("CloseCombat","LOCALS",0)
  Global("safe","LOCALS",0)
  GlobalTimerExpired("SafeForAWhile","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("safe","LOCALS",1)
END

IF
  Global("CloseCombat","LOCALS",0)
  OR(2)
    HitBy([ANYONE],CRUSHING)
    AttackedBy([ANYONE],DEFAULT)
  Range(NearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

IF
  Detect(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("ChainContingency","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ChainContingency","LOCALS",1000)
    DisplayString(Myself,73139)  // ~Contingency - Fired~
    ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("Contingency","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Contingency","LOCALS",1000)
    DisplayString(Myself,73139)  // ~Contingency - Fired~
    ReallyForceSpell(Myself,CLERIC_HEAL)
END

IF
  Exists(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("SpellTrigger1","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellTrigger1","LOCALS",1000)
    DisplayString(Myself,39968)  // ~Spell Trigger - Fired~
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,CLERIC_RIGHTEOUS_MAGIC)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_HASTE)
END

IF
  HPPercentLT(Myself,100)
  CheckStatLT(Myself,1,STONESKINS)
  !StateCheck(Myself,STATE_HASTED)
  !GlobalTimerNotExpired("SpellSequencer1","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellSequencer1","LOCALS",1000)
    DisplayString(Myself,39969)  // ~Spell Sequencer - Fired~
    ReallyForceSpell(Myself,WIZARD_HASTE)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_BLUE)
END

IF
  CheckStat(Myself,0,STONESKINS)
  CheckStat(Myself,0,128)
  HitBy([ANYONE],CRUSHING)
  !GlobalTimerNotExpired("MinorSequencer1","LOCALS")
  !StateCheck(Myself,STATE_BLUR)
THEN
  RESPONSE #100
    SetGlobalTimer("MinorSequencer1","LOCALS",1000)
    DisplayString(Myself,8635)  // ~Minor Sequencer Activated~
    ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
    ReallyForceSpell(Myself,WIZARD_BLUR)
END

IF
  StateCheck(Myself,STATE_SILENCED)
  HaveSpell(WIZARD_VOCALIZE)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("Running","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,WIZARD_VOCALIZE)
END

IF
  Global("TimeToTeleport","LOCALS",0)
  Global("CloseCombat","LOCALS",1)
  Range(SecondNearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  Global("TimeToTeleport","LOCALS",0)
  Global("CloseCombat","LOCALS",1)
  CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  Global("TimeToTeleport","LOCALS",0)
  HPPercentLT(Myself,50)
  OR(2)
    HaveSpell(CLERIC_HEAL)
    HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  HasItem("SEND01",Myself)  // ~Tell us about the battle!~
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  Global("TimeToTeleport","LOCALS",0)
  Range("finbodh",8)  // ~Bodhi~
  !CheckStatGT(Myself,0,SCRIPTINGSTATE3)
  !CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  Allegiance(Myself,ENEMY)
  Global("TimeToTeleport","LOCALS",1)
  Global("SendaiTelTrack","LOCALS",0)
  GlobalLT("SendaiTeleport","LOCALS",20)
  !GlobalTimerNotExpired("SendaiRing","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",1)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([928.778],WIZARD_DIMENSION_DOOR)
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",2)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1652.811],WIZARD_DIMENSION_DOOR)
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",3)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1296.1278],WIZARD_DIMENSION_DOOR)
END

IF
  Allegiance(Myself,ENEMY)
  Global("TimeToTeleport","LOCALS",1)
  GlobalLT("SendaiTeleport","LOCALS",20)
  Global("SendaiTelTrack","LOCALS",1)
  !GlobalTimerNotExpired("SendaiRing","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",2)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1652.811],WIZARD_DIMENSION_DOOR)
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",3)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1296.1278],WIZARD_DIMENSION_DOOR)
END

IF
  Allegiance(Myself,ENEMY)
  Global("TimeToTeleport","LOCALS",1)
  GlobalLT("SendaiTeleport","LOCALS",20)
  Global("SendaiTelTrack","LOCALS",2)
  !GlobalTimerNotExpired("SendaiRing","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",1)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([928.778],WIZARD_DIMENSION_DOOR)
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",3)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1296.1278],WIZARD_DIMENSION_DOOR)
END

IF
  Allegiance(Myself,ENEMY)
  Global("TimeToTeleport","LOCALS",1)
  GlobalLT("SendaiTeleport","LOCALS",20)
  Global("SendaiTelTrack","LOCALS",3)
  !GlobalTimerNotExpired("SendaiRing","LOCALS")
THEN
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",1)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([928.778],WIZARD_DIMENSION_DOOR)
  RESPONSE #100
    IncrementGlobal("SendaiTeleport","LOCALS",1)
    SetGlobal("SendaiTelTrack","LOCALS",2)
    SetGlobalTimer("SendaiRing","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    DisplayStringHead(Myself,73938)  // ~Twists onyx ring~
    ReallyForceSpellPoint([1652.811],WIZARD_DIMENSION_DOOR)
END

IF
  Global("TimeToTeleport","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",0)
END

IF
  DifficultyLT(HARD)
  !Difficulty(EASIEST)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TIME_STOP)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("TimeStop","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",36)
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  Global("BalthazarFights","GLOBAL",1)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TIME_STOP)
  DifficultyGT(NORMAL)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("TimeStop","LOCALS")
  OR(4)
    Dead("balth2")  // ~Balthazar~
    !CheckStatGT("balth2",0,SCRIPTINGSTATE3)  // ~Balthazar~
    HPPercentLT(Myself,75)
    Global("FinalFight","AR6200",8)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",36)
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  Global("BalthazarFights","GLOBAL",0)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  See(NearestEnemyOf(Myself))
  HaveSpell(WIZARD_TIME_STOP)
  DifficultyGT(NORMAL)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("TimeStop","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",36)
    Spell(Myself,WIZARD_TIME_STOP)
END

IF
  HasItem("SDScrl1",Myself)  // <Invalid Strref -1>
  !DifficultyLT(NORMAL)
  !CheckStatGT(Myself,0,AURACLEANSING)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("Alacrity","LOCALS")
  OR(2)
    GlobalTimerNotExpired("TimeStop","LOCALS")
    !HaveSpell(WIZARD_TIME_STOP)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("PreventAttack","LOCALS",18)
    SetGlobalTimer("Alacrity","LOCALS",18)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    UseItem("SDScrl1",Myself)  // <Invalid Strref -1>
    SetInterrupt(TRUE)
END

IF
  Allegiance(Myself,ENEMY)
  !Difficulty(EASIEST)
  CheckStatLT(Myself,1,STONESKINS)
  HaveSpell(WIZARD_STONE_SKIN)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  RandomNumLT(3,3)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,WIZARD_STONE_SKIN)
END

IF
  Allegiance(Myself,ENEMY)
  CheckStatLT(Myself,1,STONESKINS)
  HaveSpell(CLERIC_IRONSKIN)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  RandomNumLT(6,5)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_IRONSKIN)
END

IF
  Global("HealMyself","LOCALS",0)
  OR(4)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    CheckStatGT(Myself,0,128)
    !Range(NearestEnemyOf(Myself),20)
  !Range(ThirdNearestEnemyOf(Myself),8)
  OR(2)
    !Range(SecondNearestEnemyOf(Myself),8)
    CheckStatLT(SecondNearestEnemyOf(Myself),5,NUMBEROFATTACKS)
  OR(2)
    !Range(NearestEnemyOf(Myself),8)
    CheckStatLT(NearestEnemyOf(Myself),5,NUMBEROFATTACKS)  
  OR(3)
    Global("CloseCombat","LOCALS",0)
    CheckStatGT(Myself,0,STONESKINS)
    CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobal("HealMyself","LOCALS",1)
END

IF
  Global("HealMyself","LOCALS",0)
  GlobalTimerNotExpired("TimeStop","LOCALS")
  !Range("balth2",8)  // ~Balthazar~
  !Range(Player1,8)
THEN
  RESPONSE #100
    SetGlobal("HealMyself","LOCALS",1)
END

IF
  HPPercentLT(Myself,20)
  !HasItem("SEND01",Myself)  // ~Tell us about the battle!~
  Global("HealMyself","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("HealMyself","LOCALS",1)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  Global("HealMyself","LOCALS",1)
  HPPercentLT(Myself,50)
  HaveSpell(CLERIC_HEAL)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("HealMyself","LOCALS",0)
    Spell(Myself,CLERIC_HEAL)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  Global("HealMyself","LOCALS",1)
  HPPercentLT(Myself,50)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("HealMyself","LOCALS",0)
    Spell(Myself,CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !DifficultyLT(NORMAL)
  Global("HealMyself","LOCALS",1)
  !HaveSpell(CLERIC_HEAL)
  !HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  HPPercentLT(Myself,50)
  HasItem("SEND01",Myself)  // ~Tell us about the battle!~
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("HealMyself","LOCALS",0)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("SEND01",Myself)  // ~Tell us about the battle!~
    SetInterrupt(TRUE)
END

IF
  Global("HealMyself","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("HealMyself","LOCALS",0)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !DifficultyLT(NORMAL)
  Global("HealMyself","LOCALS",0)
  HPPercentLT(Myself,50)
  HasItem("SEND01",Myself)  // ~Tell us about the battle!~
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("SEND01",Myself)  // ~Tell us about the battle!~
    SetInterrupt(TRUE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    LevelLT(Myself,20)
    HPPercentLT(Myself,50)
  OR(2)
    LevelLT("finilla",12)  // ~Illasera~
    HPPercentLT("finilla",50)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  HasItem("SDScrl2",Myself)  // <Invalid Strref -1>
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    UseItem("SDScrl2",Myself)  // <Invalid Strref -1>
    SetInterrupt(TRUE)
  RESPONSE #50
    Continue()
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    LevelLT(Myself,20)
    HPPercentLT(Myself,50)
  OR(2)
    LevelLT("finabaz",20)  // ~Abazigal~
    HPPercentLT("finabaz",50)  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  HasItem("SDScrl2",Myself)  // <Invalid Strref -1>
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    UseItem("SDScrl2",Myself)  // <Invalid Strref -1>
    SetInterrupt(TRUE)
  RESPONSE #50
    Continue()
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    LevelLT(Myself,20)
    HPPercentLT(Myself,50)
  OR(2)
    LevelLT("finyaga",15)  // ~Yaga-Shura~
    HPPercentLT("finyaga",50)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  HasItem("SDScrl2",Myself)  // <Invalid Strref -1>
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    UseItem("SDScrl2",Myself)  // <Invalid Strref -1>
    SetInterrupt(TRUE)
  RESPONSE #50
    Continue()
END

IF
  OR(6)
    Dead("finilla")  // ~Illasera~
    Dead("finabaz")  // ~Abazigal~
    Dead("finyaga")  // ~Yaga-Shura~
    Dead("finbalth")  // ~Balthazar~
    Dead("fingrom")  // ~Gromnir Il-Khan~
    Dead("finsarev")  // ~Sarevok~
  Global("IMPRISON","GLOBAL",1)
  HasItem("SDScrl3",Myself)  // ~Freedom~
  !GlobalTimerNotExpired("Spell","LOCALS")
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,46153)  // ~uses a scroll~
    UseItem("SDScrl3",Myself)  // ~Freedom~
    SetGlobal("IMPRISON","GLOBAL",0)
    SetGlobal("IllaseraImprisoned","AR6200",0)
    SetGlobal("AbazigalImprisoned","AR6200",0)
    SetGlobal("YagaImprisoned","AR6200",0)
    SetGlobal("BalthImprisoned","AR6200",0)
    SetGlobal("GromnirImprisoned","AR6200",0)
    SetGlobal("SarevokImprisoned","AR6200",0)
    SetInterrupt(TRUE)
END

IF
  Allegiance(Myself,ENEMY)
  See("finbodh")  // ~Bodhi~
  Allegiance("finbodh",GOODCUTOFF)  // ~Bodhi~
  !CheckStatGT(Myself,0,SCRIPTINGSTATE3)
  HaveSpell(CLERIC_NEGATIVE_PLANE_PROTECTION)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  RandomNumLT(4,3)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_NEGATIVE_PLANE_PROTECTION)
END

IF
  Allegiance(Myself,ENEMY)
  !CheckStatGT(Myself,0,118)
  HaveSpell(WIZARD_TRUE_SIGHT)
  OR(8)
    !See([GOODCUTOFF])
    !See(LastAttackerOf(Myself))
    StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    StateCheck(NearestEnemyOf(Myself),0x60400010)
    StateCheck(NearestEnemyOf(Myself),STATE_BLUR)
    Gender(NearestEnemyOf(Myself),ILLUSIONARY)
    Specifics(NearestEnemyOf(Myself),207)
    Specifics(NearestEnemyOf(Myself),205)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("TrueSight","LOCALS")
  RandomNumLT(8,5)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TrueSight","LOCALS",30)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  OR(2)
    CheckStatGT(Myself,0,WEB)
    CheckStatGT(Myself,0,ENTANGLE)
  HaveSpell(CLERIC_FREE_ACTION)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  RandomNumLT(10,6)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_FREE_ACTION)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_HEAL)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finyaga")  // ~Yaga-Shura~
  HPPercentLT("finyaga",50)  // ~Yaga-Shura~
  HPPercentGT("finyaga",20)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  RandomNumLT(12,7)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finyaga",CLERIC_HEAL)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_HEAL)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finabaz")  // ~Abazigal~
  HPPercentLT("finabaz",50)  // ~Abazigal~
  HPPercentGT("finabaz",20)  // ~Abazigal~
  !Dead("finyaga")  // ~Yaga-Shura~
  RandomNumLT(14,8)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finabaz",CLERIC_HEAL)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_HEAL)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finilla")  // ~Illasera~
  HPPercentLT("finilla",50)  // ~Illasera~
  HPPercentGT("finilla",20)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  RandomNumLT(16,9)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finyaga",CLERIC_HEAL)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finyaga")  // ~Yaga-Shura~
  HPPercentLT("finyaga",50)  // ~Yaga-Shura~
  HPPercentGT("finyaga",20)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  RandomNumLT(18,10)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finyaga",CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finabaz")  // ~Abazigal~
  HPPercentLT("finabaz",50)  // ~Abazigal~
  HPPercentGT("finabaz",20)  // ~Abazigal~
  !Dead("finyaga")  // ~Yaga-Shura~
  RandomNumLT(20,11)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finabaz",CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    HPPercentGT(Myself,50)
    Global("safe","LOCALS",1)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  Global("CloseCombat","LOCALS",0)
  !GlobalTimerNotExpired("WaitHeal","LOCALS")
  OR(3)
    !Range(NearestEnemyOf(Myself),8)
    Global("safe","LOCALS",1)
    HPPercentGT(Myself,90)
  See("finilla")  // ~Illasera~
  HPPercentLT("finilla",50)  // ~Illasera~
  HPPercentGT("finilla",20)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  RandomNumLT(22,12)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("WaitHeal","LOCALS",12)
    Spell("finyaga",CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  StateCheck(Myself,STATE_BLIND)
  HaveSpell(CLERIC_CURE_DISEASE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_CURE_DISEASE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    StateCheck("finyaga",STATE_BLIND)  // ~Yaga-Shura~
    StateCheck("finyaga",STATE_FEEBLEMINDED)  // ~Yaga-Shura~
  Global("CloseCombat","LOCALS",0)
  See("finyaga")  // ~Yaga-Shura~
  !HPPercentLT("finyaga",35)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  HaveSpell(CLERIC_CURE_DISEASE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    ActionOverride("finyaga",MoveToObject("finsend"))
    Spell("finyaga",CLERIC_CURE_DISEASE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    StateCheck("finabaz",STATE_BLIND)  // ~Abazigal~
    StateCheck("finabaz",STATE_FEEBLEMINDED)  // ~Abazigal~
  Global("CloseCombat","LOCALS",0)
  See("finabaz")  // ~Abazigal~
  !HPPercentLT("finabaz",35)  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  HaveSpell(CLERIC_CURE_DISEASE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    ActionOverride("finabaz",MoveToObject("finsend"))
    Spell("finabaz",CLERIC_CURE_DISEASE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    StateCheck("finilla",STATE_BLIND)  // ~Illasera~
    StateCheck("finilla",STATE_FEEBLEMINDED)  // ~Illasera~
  Global("CloseCombat","LOCALS",0)
  See("finilla")  // ~Illasera~
  !HPPercentLT("finilla",35)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  HaveSpell(CLERIC_CURE_DISEASE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    ActionOverride("finilla",MoveToObject("finsend"))
    Spell("finilla",CLERIC_CURE_DISEASE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  OR(2)
    StateCheck("finbalth",STATE_BLIND)  // ~Balthazar~
    StateCheck("finbalth",STATE_FEEBLEMINDED)  // ~Balthazar~
  Global("CloseCombat","LOCALS",0)
  See("finbalth")  // ~Balthazar~
  !HPPercentLT("finbalth",35)  // ~Balthazar~
  !Dead("finbalth")  // ~Balthazar~
  HaveSpell(CLERIC_CURE_DISEASE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    ActionOverride("finbalth",MoveToObject("finsend"))
    Spell("finbalth",CLERIC_CURE_DISEASE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !Range("finyaga",15)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    !Range(NearestEnemyOf(Myself),8)
  OR(5)
    StateCheck("finyaga",STATE_CONFUSED)  // ~Yaga-Shura~
    StateCheck("finyaga",STATE_PANIC)  // ~Yaga-Shura~
    StateCheck("finyaga",STATE_STUNNED)  // ~Yaga-Shura~
    StateCheck("finyaga",STATE_HELPLESS)  // ~Yaga-Shura~
    StateCheck("finyaga",STATE_SLEEPING)  // ~Yaga-Shura~
  HaveSpell(WIZARD_TRUE_DISPEL_MAGIC)
  RandomNumLT(24,13)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell("finyaga",WIZARD_TRUE_DISPEL_MAGIC)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !Range("finabaz",15)  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    !Range(NearestEnemyOf(Myself),8)
  OR(5)
    StateCheck("finabaz",STATE_CONFUSED)  // ~Abazigal~
    StateCheck("finabaz",STATE_PANIC)  // ~Abazigal~
    StateCheck("finabaz",STATE_STUNNED)  // ~Abazigal~
    StateCheck("finabaz",STATE_HELPLESS)  // ~Abazigal~
    StateCheck("finabaz",STATE_SLEEPING)  // ~Abazigal~
  HaveSpell(WIZARD_TRUE_DISPEL_MAGIC)
  RandomNumLT(24,13)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell("finabaz",WIZARD_TRUE_DISPEL_MAGIC)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !Range("finilla",15)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    !Range(NearestEnemyOf(Myself),8)
  OR(5)
    StateCheck("finilla",STATE_CONFUSED)  // ~Illasera~
    StateCheck("finilla",STATE_PANIC)  // ~Illasera~
    StateCheck("finilla",STATE_STUNNED)  // ~Illasera~
    StateCheck("finilla",STATE_HELPLESS)  // ~Illasera~
    StateCheck("finilla",STATE_SLEEPING)  // ~Illasera~
  HaveSpell(WIZARD_TRUE_DISPEL_MAGIC)
  RandomNumLT(24,13)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell("finilla",WIZARD_TRUE_DISPEL_MAGIC)
END

IF
  HaveSpell(WIZARD_RESIST_FEAR)
  StateCheck(SecondNearest([EVILCUTOFF]),STATE_PANIC)
  See(SecondNearest([EVILCUTOFF]))
  OR(3)
    CheckStatGT(Myself,0,128)
    CheckStatGT(Myself,2,STONESKINS)
    Global("safe","LOCALS",1)
  !CheckStatGT(LastSeenBy(Myself),0,0)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_REMOVE_FEAR)
END

IF
  StateCheck("finilla",0)  // ~Illasera~
  See("finilla")  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  HaveSpell(CLERIC_FREE_ACTION)
  RandomNumLT(26,14)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_FREE_ACTION)
END

IF
  Global("BalthazarFights","GLOBAL",0)
  StateCheck("finbalth",0)  // ~Balthazar~
  See("finbalth")  // ~Balthazar~
  !Dead("finbalth")  // ~Balthazar~
  HaveSpell(CLERIC_FREE_ACTION)
  RandomNumLT(26,14)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_FREE_ACTION)
END

IF
  StateCheck("finabaz",0)  // ~Abazigal~
  See("finabaz")  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  HaveSpell(CLERIC_FREE_ACTION)
  RandomNumLT(26,14)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_FREE_ACTION)
END

IF
  Global("DefensiveStance","LOCALS",0)
  !CheckStatGT(Myself,0,126)
  !CheckStatGT(Myself,0,128)
  !CheckStatGT(Myself,0,164)
  !HasBounceEffects(Myself)
  !CheckStatGT(Myself,0,MINORGLOBE)
  !StateCheck(Myself,0)
  !StateCheck(Myself,STATE_HASTED)
  !Global("safe","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",1)
END

IF
  Global("DefensiveStance","LOCALS",0)
  Global("safe","LOCALS",1)
  RandomNumLT(10,4)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",1)
END

IF
  Global("DefensiveStance","LOCALS",0)
  OR(7)
    CheckStatGT(Myself,0,126)
    CheckStatGT(Myself,0,128)
    CheckStatGT(Myself,0,164)
    HasBounceEffects(Myself)
    CheckStatGT(Myself,0,MINORGLOBE)
    StateCheck(Myself,0)
    StateCheck(Myself,STATE_HASTED)
  HPPercentGT(Myself,75)
  RandomNumLT(10,8)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",1)
END

IF
  Global("DefensiveStance","LOCALS",0)
  OR(7)
    CheckStatGT(Myself,0,126)
    CheckStatGT(Myself,0,128)
    CheckStatGT(Myself,0,164)
    HasBounceEffects(Myself)
    CheckStatGT(Myself,0,MINORGLOBE)
    StateCheck(Myself,0)
    StateCheck(Myself,STATE_HASTED)
  !HPPercentGT(Myself,75)
  HPPercentGT(Myself,50)
  RandomNumLT(10,6)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",1)
END

IF
  Global("DefensiveStance","LOCALS",0)
  OR(5)
    CheckStatGT(Myself,0,126)
    CheckStatGT(Myself,0,128)
    CheckStatGT(Myself,0,164)
    HasBounceEffects(Myself)
    CheckStatGT(Myself,0,MINORGLOBE)
  StateCheck(Myself,0)
  StateCheck(Myself,STATE_HASTED)
  !HPPercentGT(Myself,50)
  RandomNumLT(10,8)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",1)
END

IF
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_MIRROR_IMAGE)
  RandomNumLT(12,7)
  OR(5)
    Range([GOODCUTOFF.0.0.THIEF_ALL],8)
    Range([GOODCUTOFF.0.0.FIGHTER_ALL],8)
    Range([GOODCUTOFF.0.0.PALADIN_ALL],8)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    HitBy([ANYONE],MISSILE)
  !StateCheck(Myself,STATE_MIRRORIMAGE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("DefensiveStance","LOCALS",0)
    Spell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
  Global("DefensiveStance","LOCALS",1)
  OR(2)
    See(NearestEnemyOf(Myself))
    Range(NearestEnemyOf(Myself),20)
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  RandomNumLT(14,8)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !CheckStatGT(Myself,0,AURACLEANSING)
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("TimeStop","LOCALS")
  !CheckStatGT(NearestEnemyOf(Myself),0,118)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,118)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,118)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,118)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("DefensiveStance","LOCALS",0)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_HASTE)
  RandomNumLT(16,9)
  !StateCheck(Myself,STATE_HASTED)
  !GlobalTimerNotExpired("TimeStop","LOCALS")
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("DefensiveStance","LOCALS",0)
    Spell(Myself,WIZARD_HASTE)
END

IF
  Global("DefensiveStance","LOCALS",1)
  !GlobalTimerNotExpired("TimeStop","LOCALS")
  StateCheck(Myself,STATE_HASTED)
  HaveSpell(WIZARD_HASTE)
  RandomNumLT(18,7)
  See(SecondNearest([EVILCUTOFF]))
  !StateCheck(LastSeenBy(Myself),STATE_HASTED)
  !StateCheck(LastSeenBy(Myself),0)
  !StateCheck(LastSeenBy(Myself),STATE_IMPROVEDINVISIBILITY)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  HPGT(LastSeenBy(Myself),0)
  !Range(LastSeenBy(Myself),10)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_HASTE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  CheckStatLT(Myself,18,STR)
  HaveSpell(CLERIC_RIGHTEOUS_MAGIC)
  RandomNumLT(21,8)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_RIGHTEOUS_MAGIC)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  CheckStatLT(Myself,18,STR)
  HaveSpell(CLERIC_HOLY_POWER)
  !HaveSpell(CLERIC_RIGHTEOUS_MAGIC)
  RandomNumLT(24,9)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(Myself,CLERIC_HOLY_POWER)
END

IF
  Allegiance(Myself,EVILCUTOFF)
  Global("NeedWeaponImmunity","LOCALS",0)
  OR(5)
    Global("CloseCombat","LOCALS",1)
    See([GOODCUTOFF.0.0.FIGHTER_ALL])
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    Detect([GOODCUTOFF.0.0.THIEF_ALL])
  !CheckStatGT(Myself,0,128)
  !CheckStatGT(Myself,3,STONESKINS)
  RandomNumLT(27,19)
THEN
  RESPONSE #100
    SetGlobal("NeedWeaponImmunity","LOCALS",1)
END

IF
  Allegiance(Myself,GOODCUTOFF)
  Global("NeedWeaponImmunity","LOCALS",0)
  OR(5)
    Global("CloseCombat","LOCALS",1)
    See([EVILCUTOFF.0.0.FIGHTER_ALL])
    See([EVILCUTOFF.0.0.RANGER_ALL])
    See([EVILCUTOFF.0.0.PALADIN_ALL])
    Detect([EVILCUTOFF.0.0.THIEF_ALL])
  !CheckStatGT(Myself,0,128)
  !CheckStatGT(Myself,3,STONESKINS)
  RandomNumLT(27,19)
THEN
  RESPONSE #100
    SetGlobal("NeedWeaponImmunity","LOCALS",1)
END

IF
  Global("NeedWeaponImmunity","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_IMPROVED_MANTLE)
  !CheckStatGT(Myself,0,128)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedWeaponImmunity","LOCALS",0)
    Spell(Myself,WIZARD_IMPROVED_MANTLE)
END

IF
  Global("NeedWeaponImmunity","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_MANTLE)
  !CheckStatGT(Myself,0,128)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedWeaponImmunity","LOCALS",0)
    Spell(Myself,WIZARD_MANTLE)
END

IF
  Global("NeedWeaponImmunity","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
  !CheckStatGT(Myself,0,128)
  !Global("CloseCombat","LOCALS",1)
  Detect(NearestEnemyOf(Myself))
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedWeaponImmunity","LOCALS",0)
    Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
  Global("NeedWeaponImmunity","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("NeedWeaponImmunity","LOCALS",0)
END

IF
  Allegiance(Myself,EVILCUTOFF)
  Global("NeedSpellProtection","LOCALS",0)
  OR(5)
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    RandomNumLT(30,10)
  !CheckStatGT(Myself,0,164)
THEN
  RESPONSE #100
    SetGlobal("NeedSpellProtection","LOCALS",1)
END

IF
  Allegiance(Myself,GOODCUTOFF)
  Global("NeedSpellProtection","LOCALS",0)
  OR(5)
    See([EVILCUTOFF.0.0.DRUID_ALL])
    See([EVILCUTOFF.0.0.BARD_ALL])
    See([EVILCUTOFF.0.0.CLERIC_ALL])
    See([EVILCUTOFF.0.0.LONG_BOW])
    RandomNumLT(30,10)
  !CheckStatGT(Myself,0,164)
THEN
  RESPONSE #100
    SetGlobal("NeedSpellProtection","LOCALS",1)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_SPELL_TRAP)
  !CheckStatGT(Myself,0,164)
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,116)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_SPELL_TRAP)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
  !CheckStatGT(Myself,0,164)
  !CheckStatGT(Myself,0,129)
  !CheckStatGT(Myself,0,116)
  !CheckStatGT(Myself,0,126)
  !CheckStatGT(Myself,0,163)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_PROTECTION_FROM_ENERGY)
  !CheckStatGT(Myself,0,164)
  !CheckStatGT(Myself,0,129)
  !CheckStatGT(Myself,0,116)
  !CheckStatGT(Myself,0,126)
  !CheckStatGT(Myself,0,163)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_SPELL_TURNING)
  !CheckStatGT(Myself,0,129)
  !CheckStat(Myself,2,116)
  !CheckStatGT(Myself,0,164)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_GLOBE_OF_INVULNERABILITY)
  !CheckStatGT(Myself,0,164)
  !CheckStat(Myself,2,128)
  !CheckStat(Myself,2,116)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_GLOBE_OF_INVULNERABILITY)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_MINOR_SPELL_TURNING)
  !CheckStatGT(Myself,0,164)
  !CheckStatGT(Myself,0,129)
  !CheckStatGT(Myself,0,116)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_MINOR_SPELL_TURNING)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
  Global("DefensiveStance","LOCALS",1)
  HaveSpell(WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
  !CheckStatGT(Myself,0,164)
  !CheckStatGT(Myself,0,129)
  !CheckStatGT(Myself,0,116)
  !CheckStatGT(Myself,0,MINORGLOBE)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("NeedSpellProtection","LOCALS",0)
    Spell(Myself,WIZARD_MINOR_GLOBE_OF_INVULNERABILITY)
END

IF
  Global("NeedSpellProtection","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("NeedSpellProtection","LOCALS",0)
END

IF
  Global("DefensiveStance","LOCALS",1)
  CheckStatLT(Myself,40,RESISTMAGIC)
  HaveSpell(CLERIC_MAGIC_RESISTANCE)
  !Global("CloseCombat","LOCALS",1)
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobal("DefensiveStance","LOCALS",0)
    Spell(Myself,CLERIC_MAGIC_RESISTANCE)
END

IF
  Global("DefensiveStance","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("DefensiveStance","LOCALS",0)
END

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

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

IF
  !CheckStatGT(SixthNearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(SixthNearestEnemyOf(Myself),0,129)
  !CheckStatGT(SixthNearestEnemyOf(Myself),0,164)
  !CheckStatGT(SixthNearestEnemyOf(Myself),0,177)
  !CheckStatGT(SixthNearestEnemyOf(Myself),0,116)
  !CheckStatGT(SixthNearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(SixthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SixthNearestEnemyOf(Myself),9)
  See(SixthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !CheckStatGT(FifthNearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(FifthNearestEnemyOf(Myself),0,129)
  !CheckStatGT(FifthNearestEnemyOf(Myself),0,164)
  !CheckStatGT(FifthNearestEnemyOf(Myself),0,177)
  !CheckStatGT(FifthNearestEnemyOf(Myself),0,116)
  !CheckStatGT(FifthNearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(FifthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FifthNearestEnemyOf(Myself),9)
  See(FifthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !CheckStatGT(FourthNearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,129)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,164)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,177)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,116)
  !CheckStatGT(FourthNearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(FourthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FourthNearestEnemyOf(Myself),9)
  See(FourthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !CheckStatGT(ThirdNearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,129)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,164)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,177)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,116)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(ThirdNearestEnemyOf(Myself),SUMMONED)
    LevelGT(ThirdNearestEnemyOf(Myself),9)
  See(ThirdNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !CheckStatGT(SecondNearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,129)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,164)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,177)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,116)
  !CheckStatGT(SecondNearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(SecondNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SecondNearestEnemyOf(Myself),9)
  See(SecondNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !CheckStatGT(NearestEnemyOf(Myself),30,RESISTMAGIC)
  !CheckStatGT(NearestEnemyOf(Myself),0,129)
  !CheckStatGT(NearestEnemyOf(Myself),0,164)
  !CheckStatGT(NearestEnemyOf(Myself),0,177)
  !CheckStatGT(NearestEnemyOf(Myself),0,116)
  !CheckStatGT(NearestEnemyOf(Myself),0,162)
  OR(2)
    !Gender(NearestEnemyOf(Myself),SUMMONED)
    LevelGT(NearestEnemyOf(Myself),9)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  HPPercentLT("finyaga",50)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  Range(LastAttackerOf("finyaga"),20)  // ~Yaga-Shura~
  HPGT(LastAttackerOf("finyaga"),0)
  !StateCheck(LastAttackerOf("finyaga"),STATE_STUNNED)  // ~Yaga-Shura~
  !StateCheck(LastAttackerOf("finyaga"),STATE_SLEEPING)  // ~Yaga-Shura~
  !StateCheck(LastAttackerOf("finyaga"),STATE_HELPLESS)  // ~Yaga-Shura~
  !StateCheck(LastAttackerOf("finyaga"),STATE_CONFUSED)  // ~Yaga-Shura~
  RandomNum(2,1)
  See(LastAttackerOf("finyaga"))  // ~Yaga-Shura~
  False()
THEN
  RESPONSE #100
END

IF
  HPPercentLT("finabaz",50)  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  Range(LastAttackerOf("finabaz"),20)  // ~Abazigal~
  HPGT(LastAttackerOf("finabaz"),0)
  !StateCheck(LastAttackerOf("finabaz"),STATE_STUNNED)  // ~Abazigal~
  !StateCheck(LastAttackerOf("finabaz"),STATE_SLEEPING)  // ~Abazigal~
  !StateCheck(LastAttackerOf("finabaz"),STATE_HELPLESS)  // ~Abazigal~
  !StateCheck(LastAttackerOf("finabaz"),STATE_CONFUSED)  // ~Abazigal~
  RandomNum(2,1)
  See(LastAttackerOf("finabaz"))  // ~Abazigal~
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck([GOODCUTOFF.0.0.BARD_ALL],STATE_SILENCED)
  !StateCheck([GOODCUTOFF.0.0.BARD_ALL],STATE_STUNNED)
  !StateCheck([GOODCUTOFF.0.0.BARD_ALL],STATE_PANIC)
  !StateCheck([GOODCUTOFF.0.0.BARD_ALL],STATE_SLEEPING)
  CheckStatLT([GOODCUTOFF.0.0.BARD_ALL],30,SPELLFAILUREMAGE)
  See([GOODCUTOFF.0.0.BARD_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck([GOODCUTOFF.0.0.DRUID_ALL],STATE_SILENCED)
  !StateCheck([GOODCUTOFF.0.0.DRUID_ALL],STATE_STUNNED)
  !StateCheck([GOODCUTOFF.0.0.DRUID_ALL],STATE_PANIC)
  !StateCheck([GOODCUTOFF.0.0.DRUID_ALL],STATE_SLEEPING)
  CheckStatLT([GOODCUTOFF.0.0.DRUID_ALL],30,SPELLFAILUREPRIEST)
  See([GOODCUTOFF.0.0.DRUID_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck([GOODCUTOFF.0.0.CLERIC_ALL],STATE_SILENCED)
  !StateCheck([GOODCUTOFF.0.0.CLERIC_ALL],STATE_STUNNED)
  !StateCheck([GOODCUTOFF.0.0.CLERIC_ALL],STATE_PANIC)
  !StateCheck([GOODCUTOFF.0.0.CLERIC_ALL],STATE_SLEEPING)
  CheckStatLT([GOODCUTOFF.0.0.CLERIC_ALL],30,SPELLFAILUREPRIEST)
  See([GOODCUTOFF.0.0.CLERIC_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]),STATE_SILENCED)
  !StateCheck(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]),STATE_STUNNED)
  !StateCheck(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]),STATE_PANIC)
  !StateCheck(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]),STATE_SLEEPING)
  CheckStatLT(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]),30,SPELLFAILUREMAGE)
  See(SecondNearest([GOODCUTOFF.0.0.MAGE_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck([GOODCUTOFF.0.0.MAGE_ALL],STATE_SILENCED)
  !StateCheck([GOODCUTOFF.0.0.MAGE_ALL],STATE_STUNNED)
  !StateCheck([GOODCUTOFF.0.0.MAGE_ALL],STATE_PANIC)
  !StateCheck([GOODCUTOFF.0.0.MAGE_ALL],STATE_SLEEPING)
  CheckStatLT([GOODCUTOFF.0.0.MAGE_ALL],30,SPELLFAILUREMAGE)
  See([GOODCUTOFF.0.0.MAGE_ALL])
  False()
THEN
  RESPONSE #100
END

IF
  Range(LastAttackerOf(Myself),8)
  HPGT(LastAttackerOf(Myself),0)
  Global("CloseCombat","LOCALS",1)
  !StateCheck(LastAttackerOf(Myself),STATE_PANIC)
  !StateCheck(LastAttackerOf(Myself),STATE_STUNNED)
  !StateCheck(LastAttackerOf(Myself),STATE_HELPLESS)
  !StateCheck(LastAttackerOf(Myself),STATE_SLEEPING)
  See(LastAttackerOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  Range(SecondNearestEnemyOf(Myself),8)
  CheckStatGT(SecondNearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  StateCheck(SecondNearestEnemyOf(Myself),STATE_HASTED)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_PANIC)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_STUNNED)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_HELPLESS)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_SLEEPING)
  See(SecondNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  Range(NearestEnemyOf(Myself),8)
  CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  StateCheck(NearestEnemyOf(Myself),STATE_HASTED)
  !StateCheck(NearestEnemyOf(Myself),STATE_PANIC)
  !StateCheck(NearestEnemyOf(Myself),STATE_STUNNED)
  !StateCheck(NearestEnemyOf(Myself),STATE_HELPLESS)
  !StateCheck(NearestEnemyOf(Myself),STATE_SLEEPING)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  See([GOODCUTOFF])
THEN
  RESPONSE #100
    MoveToObject([GOODCUTOFF])
END

IF
  OR(2)
    !Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    !See([GOODCUTOFF])
  !Range(Player1,15)
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  OR(2)
    !Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    !See([GOODCUTOFF])
  Range(Player1,15)
THEN
  RESPONSE #100
    RandomWalk()
END

IF
  StateCheck(LastSeenBy(Myself),STATE_DEAD)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  StateCheck(LastSeenBy(Myself),STATE_DEAD)
  !See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("SecretWord","LOCALS")
  HaveSpell(WIZARD_SECRET_WORD)
  OR(6)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStat(LastSeenBy(Myself),1,129)
    CheckStatGT(LastSeenBy(Myself),0,164)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    CheckStatGT(Myself,0,128)
  RandomNumLT(33,12)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("SecretWord","LOCALS",18)
    Spell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("PierceMagic","LOCALS")
  HaveSpell(WIZARD_PIERCE_MAGIC)
  OR(2)
    CheckStatGT(LastSeenBy(Myself),20,RESISTMAGIC)
    RandomNumLT(34,18)
  OR(5)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStat(LastSeenBy(Myself),1,129)
  CheckStatGT(LastSeenBy(Myself),0,164)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    CheckStatGT(Myself,0,128)
  RandomNumLT(36,19)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("PierceMagic","LOCALS",18)
    Spell(LastSeenBy(Myself),WIZARD_PIERCE_MAGIC)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("RubyRay","LOCALS")
  HaveSpell(WIZARD_RUBY_RAY_OF_REVERSAL)
  OR(5)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,129)
  CheckStatGT(LastSeenBy(Myself),0,164)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,2,STONESKINS)
    CheckStatGT(Myself,0,128)
  RandomNumLT(38,20)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("RubyRay","LOCALS",18)
    Spell(LastSeenBy(Myself),WIZARD_RUBY_RAY_OF_REVERSAL)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_DEATH_SPELL)
  Gender(LastSeenBy(Myself),SUMMONED)
  LevelLT(LastSeenBy(Myself),11)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  !HPGT(LastSeenBy(Myself),70)
  HaveSpell(WIZARD_POWER_WORD_KILL)
  RandomNumLT(40,21)
  InParty(LastSeenBy(Myself))
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,22142)  // ~Power Word, Kill~
    Spell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RandomNumLT(42,29)
  !Range(LastSeenBy(Myself),15)
  !Global("CloseCombat","LOCALS",1)
  !CheckStatGT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  !Range(LastSeenBy(Myself),15)
  !Global("CloseCombat","LOCALS",1)
  !CheckStatGT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_IMPLOSION)
  RandomNumLT(44,23)
  !HPLT(LastSeenBy(Myself),40)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTCRUSHING)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    PlaySound("SENDAI02")
    Spell(LastSeenBy(Myself),CLERIC_IMPLOSION)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(ENEMY_CLERIC_HARM)
  RandomNumLT(45,16)
  Range(LastSeenBy(Myself),10)
  HPGT(LastSeenBy(Myself),60)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),ENEMY_CLERIC_HARM)
    FaceObject(LastSeenBy(Myself))
    SetSequence(SEQ_ATTACK_SLASH)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_BOLT_OF_GLORY)
  RandomNumLT(48,17)
  OR(2)
    Race(LastSeenBy(Myself),DEMONIC)
    General(LastSeenBy(Myself),UNDEAD)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_BOLT_OF_GLORY)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_CREEPING_DOOM)
  RandomNumLT(51,18)
  OR(4)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),DRUID_ALL)
  OR(3)
    !Range(LastSeenBy(Myself),12)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,3,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    PlaySound("SENDAI03")
    Spell(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
END

IF
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_LOWER_RESISTANCE)
  RandomNumLT(54,19)
  CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_GREATER_MALISON)
  RandomNumLT(57,20)
  !CheckStatGT(LastSeenBy(Myself),0,180)
  !GlobalTimerNotExpired("Malison","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("Malison","LOCALS",18)
    Spell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_UNHOLY_BLIGHT)
  RandomNumLT(58,30)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatLT(LastSeenBy(Myself),-2,SAVEVSSPELL)
  Alignment(LastSeenBy(Myself),MASK_GOOD)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_UNHOLY_BLIGHT)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HasItem("WAND19",Myself)  // ~Wand of Cursing~
  RandomNumLT(60,21)
  !StateCheck(LastSeenBy(Myself),STATE_BLIND)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  !CheckStatGT(LastSeenBy(Myself),0,129)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatLT(LastSeenBy(Myself),5,SAVEVSSPELL)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,31971)  // ~uses a wand~
    UseItem("WAND19",LastSeenBy(Myself))  // ~Wand of Cursing~
    SetInterrupt(TRUE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HasItem("WAND11",Myself)  // ~Wand of the Heavens~
  RandomNumLT(63,22)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTFIRE)
  !CheckStatLT(LastSeenBy(Myself),5,SAVEVSWANDS)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,31971)  // ~uses a wand~
    UseItem("WAND11",LastSeenBy(Myself))  // ~Wand of the Heavens~
    SetInterrupt(TRUE)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_INSECT_PLAGUE)
  !HaveSpell(CLERIC_CREEPING_DOOM)
  RandomNumLT(66,23)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  OR(4)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),DRUID_ALL)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
END

IF
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_SILENCE_15_FOOT)
  RandomNumLT(69,24)
  OR(4)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),DRUID_ALL)
  !Range(LastSeenBy(Myself),15)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !HasItemEquiped("AMUL21",LastSeenBy(Myself))
  !CheckStatLT(LastSeenBy(Myself),0,SAVEVSSPELL)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_SILENCE_15_FOOT)
END

IF
  OR(2)
    GlobalTimerNotExpired("Alacrity","LOCALS")
    !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_MISCAST_MAGIC)
  RandomNumLT(70,36)
  OR(4)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),DRUID_ALL)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatLT(LastSeenBy(Myself),0,SAVEVSSPELL)
  !CheckStatGT(LastSeenBy(Myself),0,SPELLFAILUREMAGE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_MISCAST_MAGIC)
END

IF
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(CLERIC_FINGER_OF_DEATH)
  RandomNumLT(72,25)
  !HPPercentLT(LastSeenBy(Myself),25)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatLT(LastSeenBy(Myself),0,SAVEVSDEATH)
  !CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

IF
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_CHAOS)
  RandomNumLT(75,26)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
  !StateCheck(LastSeenBy(Myself),STATE_CONFUSED)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CHAOS)
END

IF
  !Range(LastSeenBy(Myself),12)
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_SKULL_TRAP)
  RandomNumLT(76,20)
  !CheckStatGT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
END

IF
  GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_SKULL_TRAP)
  RandomNumLT(78,40)
  !CheckStatGT(LastSeenBy(Myself),50,MAGICDAMAGERESISTANCE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_SKULL_TRAP)
END

IF
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  HaveSpell(WIZARD_CONE_OF_COLD)
  RandomNumLT(81,28)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTCOLD)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CONE_OF_COLD)
END

IF
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,129)
  HaveSpell(WIZARD_MAGIC_MISSILE)
  RandomNumLT(84,29)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,129)
  HaveSpell(WIZARD_MAGIC_MISSILE)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_MAGIC_MISSILE)
END

IF
  OR(2)
    !GlobalTimerNotExpired("SpellCast","LOCALS")
    GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,129)
  HaveSpell(WIZARD_CHROMATIC_ORB)
  RandomNumLT(87,30)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_CHROMATIC_ORB)
END

IF
  !GlobalTimerNotExpired("SpellCast","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,129)
  HaveSpell(WIZARD_FLAME_ARROW)
  RandomNumLT(90,31)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  GlobalTimerNotExpired("Alacrity","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,129)
  HaveSpell(WIZARD_FLAME_ARROW)
THEN
  RESPONSE #100
    SetGlobalTimer("SpellCast","LOCALS",6)
    Spell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
END

IF
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  See(NearestEnemyOf(Myself))
  See(LastSeenBy([EVILCUTOFF]))
  RandomNumGT(5,2)
  See(WorstAC)
  RandomNumGT(7,3)
  See([GOODCUTOFF.0.ELF])
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(Myself,ILLUSIONARY)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  RandomNumGT(4,1)
  See([GOODCUTOFF.HUMANOID])
  CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
  HPGT(LastSeenBy(Myself),41)
  !Class(LastSeenBy(Myself),SORCERER)
  See(SecondNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
  HPGT(LastSeenBy(Myself),41)
  !Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  See(ThirdNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
  HPGT(LastSeenBy(Myself),41)
  !Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  See(FourthNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
  HPGT(LastSeenBy(Myself),41)
  !Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  See(FifthNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-4,ARMORCLASS)
  HPGT(LastSeenBy(Myself),41)
  !Class(LastSeenBy(Myself),SORCERER)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  !CheckStatGT(LastSeenBy(Myself),0,HELD)
  See([GOODCUTOFF.HUMANOID])
  CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
  HPGT(LastSeenBy(Myself),61)
  !Class(LastSeenBy(Myself),MAGE_ALL)
  See(SecondNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
  HPGT(LastSeenBy(Myself),61)
  !Class(LastSeenBy(Myself),MAGE_ALL)
  See(ThirdNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
  HPGT(LastSeenBy(Myself),61)
  !Class(LastSeenBy(Myself),MAGE_ALL)
  See(FourthNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
  HPGT(LastSeenBy(Myself),61)
  !Class(LastSeenBy(Myself),MAGE_ALL)
  See(FifthNearest([GOODCUTOFF.HUMANOID]))
  CheckStatLT(LastSeenBy(Myself),-8,ARMORCLASS)
  HPGT(LastSeenBy(Myself),61)
  !Class(LastSeenBy(Myself),LONG_BOW)
  See([GOODCUTOFF.HUMANOID])
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
  See(SecondNearest([GOODCUTOFF.HUMANOID]))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
  See(ThirdNearest([GOODCUTOFF.HUMANOID]))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
  See(FourthNearest([GOODCUTOFF.HUMANOID]))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
  See(FifthNearest([GOODCUTOFF.HUMANOID]))
  !Class(LastSeenBy(Myself),CLERIC_ALL)
  !Class(LastSeenBy(Myself),DRUID_ALL)
  !Class(LastSeenBy(Myself),BARD_ALL)
  CheckStatLT(LastSeenBy(Myself),-11,ARMORCLASS)
  See([GOODCUTOFF.HUMANOID])
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(LastSeenBy(Myself),STATE_DEAD)
  !Gender(LastSeenBy(Myself),SUMMONED)
  OR(3)
    HPGT(LastSeenBy(Myself),60)
    !HaveSpell(WIZARD_POWER_WORD_KILL)
    !HPGT(LastSeenBy(Myself),25)
  OR(4)
    StateCheck(LastSeenBy(Myself),STATE_STUNNED)
    StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
    StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
    CheckStatGT(LastSeenBy(Myself),0,HELD)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,128)
  CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
THEN
  RESPONSE #100
    SetGlobalTimer("LockTarget","LOCALS",6)
    SetGlobalTimer("SpellCast","LOCALS",6)
    DisplayStringHead(Myself,13736)  // ~  Die here, you will!~
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  HasItemEquiped("MAGE01",LastSeenBy(Myself))
  !HasItemEquiped("STALKER",LastSeenBy(Myself))
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  OR(2)
    HPGT(LastSeenBy(Myself),60)
    !HaveSpell(WIZARD_POWER_WORD_KILL)
  !GlobalTimerNotExpired("PreventAttack","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("Alacrity","LOCALS")
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,128)
  !HasItemEquiped("shld24",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,122)
  OR(3)
    CheckStatLT(LastSeenBy(Myself),100,RESISTMISSILE)
    CheckStatLT(LastSeenBy(Myself),100,MAGICDAMAGERESISTANCE)
    !CheckStatLT(LastSeenBy(Myself),4,SAVEVSWANDS)
THEN
  RESPONSE #80
    SelectWeaponAbility(SLOT_WEAPON1,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #10
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(2)
    Range(NearestEnemyOf(Myself),7)
    Global("CloseCombat","LOCALS",1)
  OR(2)
    HPGT(LastSeenBy(Myself),60)
    !HaveSpell(WIZARD_POWER_WORD_KILL)
  !GlobalTimerNotExpired("PreventAttack","LOCALS")
  Range(LastSeenBy(Myself),13)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
THEN
  RESPONSE #70
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #30
    SelectWeaponAbility(SLOT_WEAPON0,0)
    RunAwayFrom(NearestEnemyOf(Myself),5)
END

IF
  !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(2)
    Range(NearestEnemyOf(Myself),7)
    Global("CloseCombat","LOCALS",1)
  OR(2)
    HPGT(LastSeenBy(Myself),60)
    !HaveSpell(WIZARD_POWER_WORD_KILL)
  !GlobalTimerNotExpired("PreventAttack","LOCALS")
  !Range(LastSeenBy(Myself),13)
  !StateCheck(Myself,STATE_SLOWED)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
THEN
  RESPONSE #50
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #50
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  !GlobalTimerNotExpired("PreventAttack","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  OR(2)
    Allegiance(LastSeenBy(Myself),GOODCUTOFF)
    InParty(LastSeenBy(Myself))
  OR(2)
    HPGT(LastSeenBy(Myself),60)
    !HaveSpell(WIZARD_POWER_WORD_KILL)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
THEN
  RESPONSE #100
    SelectWeaponAbility(SLOT_WEAPON0,0)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  True()
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

