IF
  Global("Lunar","GLOBAL",1)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    SetGlobal("Lunar","GLOBAL",0)
    ReallyForceSpellRES("balth07",LastSeenBy(Myself))  // ~Greater Malison~
    ReallyForceSpellRES("balth12",LastSeenBy(Myself))  // ~Glitterdust~
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)
  AttackedBy(NearestEnemyOf(Myself),DEFAULT)
  Range(NearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

IF
  Global("CloseCombat","LOCALS",0)
  AttackedBy(SecondNearestEnemyOf(Myself),DEFAULT)
  Range(SecondNearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

IF
  Global("CloseCombat","LOCALS",0)
  AttackedBy(ThirdNearestEnemyOf(Myself),DEFAULT)
  Range(ThirdNearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

IF
  Global("CloseCombat","LOCALS",0)
  AttackedBy(FourthNearestEnemyOf(Myself),DEFAULT)
  Range(FourthNearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("CloseCombat","LOCALS",1)
    SetGlobal("safe","LOCALS",0)
    SetGlobalTimer("attacked","LOCALS",5)
END

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

IF
  Allegiance(Myself,ENEMY)
  AreaCheck("AR5505")
  Global("FirstTeleport","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("FirstTeleport","LOCALS",1)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[1014.1148])
END

IF
  See(NearestEnemyOf(Myself))
  !GlobalTimerNotExpired("Spell","LOCALS")
  Global("FirstStance","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("FirstStance","LOCALS",1)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,72908)  // ~Lunar Stance!~
    ForceSpellRES("balth02",Myself)  // ~Lunar Stance!~
END

IF
  Range(NearestEnemyOf(Myself),10)
  CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("DefensiveParry","LOCALS")
  !GlobalTimerNotExpired("Spell","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("DefensiveParry","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,12090)  // ~Chant~
    ForceSpellRES("balth11",Myself)  // ~Chant~
END

IF
  Global("CloseCombat","LOCALS",1)
  Range(NearestEnemyOf(Myself),8)
  Range(SecondNearestEnemyOf(Myself),8)
  !StateCheck(Myself,STATE_INVISIBLE)
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("DefensiveParry","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("DefensiveParry","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,12090)  // ~Chant~
    ForceSpellRES("balth11",Myself)  // ~Chant~
  RESPONSE #100
    Continue()
END

IF
  HPPercentLT(Myself,20)
  HPGT(Myself,1)
  !GlobalTimerNotExpired("SecondWind","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SecondWind","LOCALS",1000)
    DisplayStringHead(Myself,73944)  // ~Second wind!~
    DisplayString(Myself,73944)  // ~Second wind!~
    ReallyForceSpell(Myself,CLERIC_HEAL)
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("PotionUse","LOCALS")
  !Range(NearestEnemyOf(Myself),8)
  HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
THEN
  RESPONSE #100
    SetGlobalTimer("PotionUse","LOCALS",6)
    DisplayStringHead(Myself,46150)  // ~quaffs a potion~
    UseItem("POTN55",Myself)  // ~Potion of Superior Healing~
END

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

IF
  Range(NearestEnemyOf(Myself),20)
  CheckStatLT(NearestEnemyOf(Myself),50,RESISTFIRE)
  !CheckStatGT(NearestEnemyOf(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",1)
    Continue()
END

IF
  Range(SecondNearestEnemyOf(Myself),20)
  CheckStatLT(SecondNearestEnemyOf(Myself),50,RESISTFIRE)
  !CheckStatGT(SecondNearestEnemyOf(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",1)
    Continue()
END

IF
  Range(ThirdNearestEnemyOf(Myself),20)
  CheckStatLT(ThirdNearestEnemyOf(Myself),50,RESISTFIRE)
  !CheckStatGT(ThirdNearestEnemyOf(Myself),30,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",1)
    Continue()
END

IF
  Global("CloseCombat","LOCALS",1)
  OR(2)
    Range(SecondNearestEnemyOf(Myself),8)
    Range(ThirdNearestEnemyOf(Myself),20)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",1)
    Continue()
END

IF
  Allegiance(Myself,ALLY)
  Range(Nearest([GOODCUTOFF]),20)
  OR(2)
    !CheckStatGT(Nearest([GOODCUTOFF]),99,RESISTFIRE)
    !CheckStatGT(Nearest([GOODCUTOFF]),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",0)
    Continue()
END

IF
  Allegiance(Myself,ALLY)
  Range(SecondNearest([GOODCUTOFF]),20)
  OR(2)
    !CheckStatGT(SecondNearest([GOODCUTOFF]),99,RESISTFIRE)
    !CheckStatGT(SecondNearest([GOODCUTOFF]),75,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",0)
    Continue()
END

IF
  Allegiance(Myself,ALLY)
  Range(ThirdNearest([GOODCUTOFF]),20)
THEN
  RESPONSE #100
    SetGlobal("UseSolarStance","LOCALS",0)
    Continue()
END

IF
  Global("UseSolarStance","LOCALS",1)
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("SolarStance","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SolarStance","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,72906)  // ~Solar Stance!~
    ForceSpellRES("balth01",Myself)  // ~Solar Stance!~
  RESPONSE #50
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !StateCheck(Myself,STATE_INVISIBLE)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LunarStance","LOCALS")
  OR(2)
    !CheckStatGT(Myself,0,SCRIPTINGSTATE2)
    !CheckStatGT(Myself,0,SCRIPTINGSTATE3)
THEN
  RESPONSE #100
    SetGlobalTimer("LunarStance","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,72908)  // ~Lunar Stance!~
    ForceSpellRES("balth02",Myself)  // ~Lunar Stance!~
  RESPONSE #100
    Continue()
END

IF
  HPPercentLT(Myself,75)
  Global("CloseCombat","LOCALS",1)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,0)
  !GlobalTimerNotExpired("ShadowStance","LOCALS")
  !GlobalTimerNotExpired("Spell","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ShadowStance","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73943)  // ~Shadow Stance!~
    ReallyForceSpellRES("balth10",Myself)  // ~Shadow Stance!~
  RESPONSE #100
    Continue()
END

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

IF
  Global("CloseCombat","LOCALS",1)
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(NearestEnemyOf(Myself),8)
  Range(SecondNearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #200
    Continue()
END

IF
  HPPercentLT(Myself,50)
  !StateCheck(Myself,STATE_INVISIBLE)
  Global("CloseCombat","LOCALS",1)
  Range(NearestEnemyOf(Myself),8)
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #200
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !StateCheck(Myself,STATE_INVISIBLE)
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #400
    Continue()
END

IF
  Global("TimeToMove","LOCALS",1)
  !Range("ThroneR",25)  // ThroneR
  !Range("ThroneC",25)  // ThroneC
  !Range("ThroneL",25)  // ThroneL
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[1401.700])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[764.556])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[370.1023])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneR",25)  // ThroneR
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[764.556])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[370.1023])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneC",25)  // ThroneC
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[1401.700])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[370.1023])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneL",25)  // ThroneL
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[1401.700])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ForceSpellPointRES("balth08",[764.556])
END

IF
  StateCheck(Myself,STATE_INVISIBLE)
  HPPercentLT(Myself,100)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(Myself),45)
END

IF
  Allegiance(Myself,ALLY)
  CombatCounter(0)
  !See(NearestEnemyOf(Myself))
  !Range(Player1,15)
  !Global("FinalFight","AR6200",4)
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

IF
  Global("BalthazarFights","GLOBAL",0)
  !Allegiance(Myself,ENEMY)
THEN
  RESPONSE #100
    NoAction()
END

IF
  Global("BalthazarFights","GLOBAL",1)
  !ActuallyInCombat()
THEN
  RESPONSE #100
    NoAction()
END

IF
  OR(6)
    See(SixthNearestEnemyOf(Myself))
    See(FifthNearestEnemyOf(Myself))
    See(FourthNearestEnemyOf(Myself))
    See(ThirdNearestEnemyOf(Myself))
    See(SecondNearestEnemyOf(Myself))
    See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

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

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

IF
  !StateCheck(SecondNearestEnemyOfType([0.0.0.LONG_BOW]),STATE_SILENCED)
  !StateCheck(SecondNearestEnemyOfType([0.0.0.LONG_BOW]),STATE_STUNNED)
  !StateCheck(SecondNearestEnemyOfType([0.0.0.LONG_BOW]),STATE_PANIC)
  !StateCheck(SecondNearestEnemyOfType([0.0.0.LONG_BOW]),STATE_SLEEPING)
  CheckStatLT(SecondNearestEnemyOfType([0.0.0.LONG_BOW]),100,SPELLFAILUREMAGE)
  See(SecondNearestEnemyOfType([0.0.0.LONG_BOW]))
  False()
THEN
  RESPONSE #100
END

IF
  !StateCheck(NearestEnemyOfType([0.0.0.LONG_BOW]),STATE_SILENCED)
  !StateCheck(NearestEnemyOfType([0.0.0.LONG_BOW]),STATE_STUNNED)
  !StateCheck(NearestEnemyOfType([0.0.0.LONG_BOW]),STATE_PANIC)
  !StateCheck(NearestEnemyOfType([0.0.0.LONG_BOW]),STATE_SLEEPING)
  CheckStatLT(NearestEnemyOfType([0.0.0.LONG_BOW]),100,SPELLFAILUREMAGE)
  See(NearestEnemyOfType([0.0.0.LONG_BOW]))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(SixthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(SixthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SixthNearestEnemyOf(Myself),10)
  !CheckStatLT(SixthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(SixthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(SixthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(FifthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(FifthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FifthNearestEnemyOf(Myself),10)
  !CheckStatLT(FifthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(FifthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(FifthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(FourthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(FourthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FourthNearestEnemyOf(Myself),10)
  !CheckStatLT(FourthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(FourthNearestEnemyOf(Myself),STATE_HELPLESS)
  See(FourthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(ThirdNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(ThirdNearestEnemyOf(Myself),SUMMONED)
    LevelGT(ThirdNearestEnemyOf(Myself),10)
  !CheckStatLT(ThirdNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(ThirdNearestEnemyOf(Myself),STATE_HELPLESS)
  See(ThirdNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(SecondNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(SecondNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SecondNearestEnemyOf(Myself),10)
  !CheckStatLT(SecondNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_HELPLESS)
  See(SecondNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(NearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(NearestEnemyOf(Myself),SUMMONED)
    LevelGT(NearestEnemyOf(Myself),10)
  !CheckStatLT(NearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(NearestEnemyOf(Myself),STATE_HELPLESS)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(SixthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(SixthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SixthNearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(SixthNearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(SixthNearestEnemyOf(Myself),30)
    StateCheck(SixthNearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(SixthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(SixthNearestEnemyOf(Myself),STATE_SLEEPING)
  See(SixthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(FifthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(FifthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FifthNearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(FifthNearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(FifthNearestEnemyOf(Myself),30)
    StateCheck(FifthNearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(FifthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(FifthNearestEnemyOf(Myself),STATE_SLEEPING)
  See(FifthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(FourthNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(FourthNearestEnemyOf(Myself),SUMMONED)
    LevelGT(FourthNearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(FourthNearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(FourthNearestEnemyOf(Myself),30)
    StateCheck(FourthNearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(FourthNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(FourthNearestEnemyOf(Myself),STATE_SLEEPING)
  See(FourthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(ThirdNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(ThirdNearestEnemyOf(Myself),SUMMONED)
    LevelGT(ThirdNearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(ThirdNearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(ThirdNearestEnemyOf(Myself),30)
    StateCheck(ThirdNearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(ThirdNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(ThirdNearestEnemyOf(Myself),STATE_SLEEPING)
  See(ThirdNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(SecondNearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(SecondNearestEnemyOf(Myself),SUMMONED)
    LevelGT(SecondNearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(SecondNearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(SecondNearestEnemyOf(Myself),30)
    StateCheck(SecondNearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(SecondNearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(SecondNearestEnemyOf(Myself),STATE_SLEEPING)
  See(SecondNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Gender(NearestEnemyOf(Myself),ILLUSIONARY)
  OR(2)
    !Gender(NearestEnemyOf(Myself),SUMMONED)
    LevelGT(NearestEnemyOf(Myself),10)
  OR(3)
    CheckStatGT(NearestEnemyOf(Myself),0,ARMORCLASS)
    HPPercentLT(NearestEnemyOf(Myself),30)
    StateCheck(NearestEnemyOf(Myself),STATE_STUNNED)
  !CheckStatLT(NearestEnemyOf(Myself),-9,ARMORCLASS)
  !StateCheck(NearestEnemyOf(Myself),STATE_SLEEPING)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
END

IF
  !Allegiance(Myself,ALLY)
  HPPercentGT(Myself,50)
  !Gender(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),ILLUSIONARY)
  OR(3)
    CheckStatGT(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),0,ARMORCLASS)
    StateCheck(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_STUNNED)
    HPPercentLT(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),30)
  !CheckStatLT(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),-9,ARMORCLASS)
  !StateCheck(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_SLEEPING)
  !StateCheck(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_SILENCED)
  !StateCheck(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]),STATE_PANIC)
  See(Nearest([GOODCUTOFF.0.0.CLERIC_ALL]))
  False()
THEN
  RESPONSE #100
END

IF
  !Allegiance(Myself,ALLY)
  HPPercentGT(Myself,50)
  !Gender(Nearest([GOODCUTOFF.0.0.LONG_BOW]),ILLUSIONARY)
  OR(3)
    CheckStatGT(Nearest([GOODCUTOFF.0.0.LONG_BOW]),0,ARMORCLASS)
    StateCheck(Nearest([GOODCUTOFF.0.0.LONG_BOW]),STATE_STUNNED)
    HPPercentLT(Nearest([GOODCUTOFF.0.0.LONG_BOW]),30)
  !CheckStatLT(Nearest([GOODCUTOFF.0.0.LONG_BOW]),-9,ARMORCLASS)
  !StateCheck(Nearest([GOODCUTOFF.0.0.LONG_BOW]),STATE_SLEEPING)
  !StateCheck(Nearest([GOODCUTOFF.0.0.LONG_BOW]),STATE_SILENCED)
  !StateCheck(Nearest([GOODCUTOFF.0.0.LONG_BOW]),STATE_PANIC)
  See(Nearest([GOODCUTOFF.0.0.LONG_BOW]))
  False()
THEN
  RESPONSE #100
END

IF
  Allegiance(Myself,ALLY)
  Range("finmel01",30)  // ~Melissan~
  See("finmel01")  // ~Melissan~
  False()
THEN
  RESPONSE #100
END

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

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

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

IF
  Allegiance(Myself,ALLY)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  Allegiance(LastSeenBy(Myself),CHARMED)
THEN
  RESPONSE #100
    RunAwayFrom(LastSeenBy(Myself),30)
END

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

IF
  Allegiance(Myself,ALLY)
  !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !See([EVILCUTOFF])
THEN
  RESPONSE #100
    RandomWalkContinuous()
END

IF
  Allegiance(Myself,ALLY)
  Name("Imoen2",LastSeenBy(Myself))
  Allegiance("Imoen2",EVILCUTOFF)  // ~Imoen~
  !InPartySlot(LastAttackerOf("Imoen2"),0)
  OR(3)
    See("finsolar")  // ~Fallen Solar~
    See("finbodh")  // ~Bodhi~
    See("finiren")  // ~Jon Irenicus~
THEN
  RESPONSE #100
    MoveToObject(LastSeenBy(Myself))
END

IF
  Allegiance(Myself,ALLY)
  Name("Imoen2",LastSeenBy(Myself))
  Allegiance("Imoen2",EVILCUTOFF)  // ~Imoen~
  !InPartySlot(LastAttackerOf("Imoen2"),0)
  !See("finsolar")  // ~Fallen Solar~
  !See("finbodh")  // ~Bodhi~
  !See("finiren")  // ~Jon Irenicus~
THEN
  RESPONSE #100
    RunAwayFrom("Imoen2",30)
END

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

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !GlobalTimerNotExpired("DragonFist","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),4)
  OR(4)
    HasImmunityEffects(LastSeenBy(Myself))
    CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
    HasBounceEffects(LastSeenBy(Myself))
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",6)
    SetGlobalTimer("DragonFist","LOCALS",18)
    DisplayStringHead(Myself,72915)  // ~Dragon Fist~
    FaceObject(LastSeenBy(Myself))
    SetSequence(SEQ_ATTACK_JAB)
    PlaySound("HIT_02B")
    ReallyForceSpellRES("balth03",LastSeenBy(Myself))  // ~Dragon Fist~
  RESPONSE #200
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !GlobalTimerNotExpired("HandOfMurder","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),4)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  !CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
  OR(2)
    !CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
    RandomNum(2,1)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",6)
    SetGlobalTimer("HandOfMurder","LOCALS",18)
    DisplayStringHead(Myself,71989)  // ~Hand of Murder~
    ReallyForceSpellRES("balth05",Myself)  // ~Hand of Murder~
    Attack(LastSeenBy(Myself))
  RESPONSE #100
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !GlobalTimerNotExpired("TigerStrike","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),4)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  !CheckStatGT(LastSeenBy(Myself),3,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",12)
    SetGlobalTimer("TigerStrike","LOCALS",24)
    DisplayStringHead(Myself,72916)  // ~Tiger Strike~
    ReallyForceSpellRES("balth04",Myself)  // ~Tiger Strike~
    Attack(LastSeenBy(Myself))
  RESPONSE #100
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !GlobalTimerNotExpired("ShadowlessKick","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),4)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",6)
    SetGlobalTimer("ShadowlessKick","LOCALS",12)
    DisplayStringHead(Myself,73942)  // ~Shadowless Kick!~
    FaceObject(LastSeenBy(Myself))
    SetSequence(SEQ_ATTACK_BACKSLASH)
    ReallyForceSpellRES("balth09",LastSeenBy(Myself))  // ~Shadowless Kick!~
  RESPONSE #100
    Continue()
END

IF
  Global("xyxManeuvered","LOCALS",0)
  GlobalTimerExpired("xyxAttack","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("xyxManeuvered","LOCALS",1)
    RandomWalkContinuous()
END

IF
  OR(2)
    !StateCheck(Myself,STATE_INVISIBLE)
    HPPercentGT(Myself,75)
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
THEN
  RESPONSE #100
    SetGlobalTimer("xyxAttack","LOCALS",5)
    SetGlobal("xyxManeuvered","LOCALS",0)
    SelectWeaponAbility(SLOT_WEAPON0,0)
    Attack(LastSeenBy(Myself))
END

IF
  OR(2)
    !StateCheck(Myself,STATE_INVISIBLE)
    HPPercentGT(Myself,75)
  StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
THEN
  RESPONSE #100
    SetGlobalTimer("xyxAttack","LOCALS",5)
    SetGlobal("xyxManeuvered","LOCALS",0)
    SelectWeaponAbility(SLOT_WEAPON1,0)
    Attack(LastSeenBy(Myself))
END

