IF
  Global("Lunar","GLOBAL",1)
  OR(5)
    See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
    See(NearestEnemyOfType([0.0.0.BARD_ALL]))
    See(NearestEnemyOfType([0.0.0.LONG_BOW]))
    See(NearestEnemyOfType)
THEN
  RESPONSE #100
    SetGlobal("Lunar","GLOBAL",2)
    ReallyForceSpellRES("balth06",LastSeenBy(Myself))  // ~Magic Missile~
END

IF
  Global("Lunar","GLOBAL",1)
  !See(NearestEnemyOfType([0.0.0.DRUID_ALL]))
  !See(NearestEnemyOfType([0.0.0.CLERIC_ALL]))
  !See(NearestEnemyOfType([0.0.0.BARD_ALL]))
  !See(NearestEnemyOfType([0.0.0.LONG_BOW]))
  !See(NearestEnemyOfType)
  See(SixthNearestEnemyOf(Myself))
THEN
  RESPONSE #100
    SetGlobal("Lunar","GLOBAL",2)
    ReallyForceSpellRES("balth06",LastSeenBy(Myself))  // ~Magic Missile~
END

IF
  Global("Lunar","GLOBAL",2)
  OR(4)
    See(NearestEnemyOfType([0.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([0.0.0.PALADIN_ALL]))
    See(NearestEnemyOfType)
    See(NearestEnemyOfType([0.0.0.FIGHTER_ALL]))
THEN
  RESPONSE #100
    SetGlobal("Lunar","GLOBAL",0)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_BIGBYS_CLENCHED_FIST)
    ReallyForceSpellRES("balth07",LastSeenBy(Myself))  // ~Greater Malison~
END

IF
  Global("Lunar","GLOBAL",2)
  !See(NearestEnemyOfType([0.0.0.RANGER_ALL]))
  !See(NearestEnemyOfType([0.0.0.PALADIN_ALL]))
  !See(NearestEnemyOfType)
  !See(NearestEnemyOfType([0.0.0.FIGHTER_ALL]))
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    SetGlobal("Lunar","GLOBAL",0)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_BIGBYS_CLENCHED_FIST)
    ReallyForceSpellRES("balth07",LastSeenBy(Myself))  // ~Greater Malison~
END

IF
  See(NearestEnemyOf(Myself))
  HPPercentLT(Myself,25)
  HPGT(Myself,1)
  !GlobalTimerNotExpired("Whined","LOCALS")
THEN
  RESPONSE #50
    SetGlobalTimer("Whined","LOCALS",6)
    DisplayStringHead(Myself,46151)  // ~help!~
    Shout(124)
    Continue()
  RESPONSE #50
    SetGlobalTimer("Whined","LOCALS",6)
    DisplayStringHead(Myself,49763)  // ~I require assistance~
    Shout(124)
    Continue()
  RESPONSE #50
    SetGlobalTimer("Whined","LOCALS",6)
    DisplayStringHead(Myself,49764)  // ~Defend me!~
    Shout(124)
    Continue()
  RESPONSE #50
    SetGlobalTimer("Whined","LOCALS",6)
    DisplayStringHead(Myself,49765)  // ~Slay my attacker!~
    Shout(124)
    Continue()
END

IF
  Allegiance(Myself,ALLY)
  Global("FirstTeleport","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("FirstTeleport","LOCALS",1)
END

IF
  Allegiance(Myself,ALLY)
  CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  !GlobalTimerNotExpired("DefensiveParry","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("DefensiveParry","LOCALS",18)
    DisplayStringHead(Myself,12090)  // ~Chant~
    ForceSpellRES("balth11",Myself)  // ~Chant~
END

IF
  Allegiance(Myself,ALLY)
  Range(NearestEnemyOf(Myself),8)
  Range(SecondNearestEnemyOf(Myself),8)
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  RandomNum(2,1)
  !GlobalTimerNotExpired("DefensiveParry","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("DefensiveParry","LOCALS",18)
    DisplayStringHead(Myself,12090)  // ~Chant~
    ForceSpellRES("balth11",Myself)  // ~Chant~
END

IF
  HPPercentLT(Myself,20)
  Global("SecondWind","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SecondWind","LOCALS",1)
    DisplayStringHead(Myself,73944)  // ~Second wind!~
    ReallyForceSpell(Myself,CLERIC_HEAL)
END

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

IF
  HPPercentLT(Myself,50)
  !Range(NearestEnemyOf(Myself),5)
  HaveSpell(MONK_LAY_ON_HANDS)
  !GlobalTimerNotExpired("LayOnHands","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("LayOnHands","LOCALS",6)
    Spell(Myself,MONK_LAY_ON_HANDS)
END

IF
  HPPercentLT(Myself,50)
  OR(2)
    HaveSpell(MONK_LAY_ON_HANDS)
    HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
  Range(NearestEnemyOf(Myself),10)
  Global("TimeToMove","LOCALS",0)
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #100
    Continue()
END

IF
  Range(NearestEnemyOf(Myself),8)
  Range(SecondNearestEnemyOf(Myself),8)
  Global("TimeToMove","LOCALS",0)
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #100
    Continue()
END

IF
  HPPercentLT(Myself,50)
  !HaveSpell(MONK_LAY_ON_HANDS)
  !HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
  Range(NearestEnemyOf(Myself),6)
  Global("TimeToMove","LOCALS",0)
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("TimeToMove","LOCALS",1)
    Continue()
  RESPONSE #200
    Continue()
END

IF
  Global("TimeToMove","LOCALS",1)
  !Range("ThroneR",25)  // ThroneR
  !Range("ThroneC",25)  // ThroneC
  !Range("ThroneL",25)  // ThroneL
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[854.1021])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1601.1129])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1328.654])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneR",25)  // ThroneR
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[854.1021])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1328.654])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneC",25)  // ThroneC
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[854.1021])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1601.1129])
END

IF
  Global("TimeToMove","LOCALS",1)
  Range("ThroneL",25)  // ThroneL
  !GlobalTimerNotExpired("BalthTeleport","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1601.1129])
  RESPONSE #100
    SetGlobalTimer("BalthTeleport","LOCALS",12)
    SetGlobal("TimeToMove","LOCALS",0)
    DisplayStringHead(Myself,73941)  // ~Faster Than the Eye!~
    ReallyForceSpellPointRES("balth08",[1328.654])
END

IF
  StateCheck(Myself,STATE_INVISIBLE)
  HPPercentLT(Myself,100)
  !GlobalTimerNotExpired("RunInvisible","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("RunInvisible","LOCALS",4)
    SetInterrupt(FALSE)
    ApplySpellRES("runrun",Myself)
    RunAwayFrom(NearestEnemyOf(Myself),45)
    SetInterrupt(TRUE)
    Continue()
END

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

IF
  CombatCounter(0)
THEN
  RESPONSE #100
    NoAction()
END

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

IF
  Range("finmel01",20)  // ~Melissan~
  See("finmel01")  // ~Melissan~
THEN
  RESPONSE #100
    Continue()
END

IF
  AttackedBy([ANYONE],DEFAULT)
  See(LastAttackerOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

IF
  Range(NearestEnemyOf(Myself),4)
  See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    Continue()
END

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

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

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

IF
  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
  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
  RandomNum(2,1)
  !GlobalTimerNotExpired("ChangeStance","LOCALS")
  Range(LastSeenBy(Myself),20)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("ChangeStance","LOCALS",6)
    Shout(126)
    DisplayStringHead(Myself,72906)  // ~Solar Stance!~
    ReallyForceSpellRES("balth01",Myself)  // ~Solar Stance!~
  RESPONSE #100
    SetGlobalTimer("ChangeStance","LOCALS",6)
    DisplayStringHead(Myself,72908)  // ~Lunar Stance!~
    ReallyForceSpellRES("balth02",Myself)  // ~Lunar Stance!~
END

IF
  RandomNum(3,1)
  HPPercentLT(Myself,75)
  Range(LastSeenBy(Myself),10)
  Global("Lunar","GLOBAL",0)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,0)
  !GlobalTimerNotExpired("ShadowStance","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ShadowStance","LOCALS",30)
    DisplayStringHead(Myself,73943)  // ~Shadow Stance!~
    ReallyForceSpellRES("balth10",Myself)  // ~Shadow Stance!~
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),4)
  RandomNum(3,1)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",3)
    DisplayStringHead(Myself,73942)  // ~Shadowless Kick!~
    FaceObject(LastSeenBy(Myself))
    SwingOnce()
    PlaySound("BALTHA02")
    ReallyForceSpellRES("balth09",LastSeenBy(Myself))  // ~Shadowless Kick!~
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),10)
  RandomNum(2,1)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",12)
    DisplayStringHead(Myself,72915)  // ~Dragon Fist~
    ForceSpellRES("balth03",Myself)  // ~Dragon Fist~
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),10)
  RandomNum(2,2)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",12)
    DisplayStringHead(Myself,72916)  // ~Tiger Strike~
    ForceSpellRES("balth04",Myself)  // ~Tiger Strike~
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  Range(LastSeenBy(Myself),5)
  RandomNum(2,1)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",6)
    DisplayStringHead(Myself,71989)  // ~Hand of Murder~
    ForceSpellRES("balth05",Myself)  // ~Hand of Murder~
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  HaveSpell(MONK_QUIVERING_PALM)
  RandomNum(2,2)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",5)
    DisplayStringHead(Myself,72936)  // ~Hyo-o-cha!~
    ForceSpell(Myself,MONK_QUIVERING_PALM)
    Continue()
END

IF
  !GlobalTimerNotExpired("MonkTimer","LOCALS")
  !StateCheck(Myself,STATE_INVISIBLE)
  HaveSpell(MONK_STUNNING_BLOW)
  RandomNum(2,1)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("MonkTimer","LOCALS",9)
    DisplayStringHead(Myself,72937)  // ~Kyai-ya!~
    ForceSpell(Myself,MONK_STUNNING_BLOW)
    Continue()
END

IF
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  HPPercentLT(Myself,100)
  Range(NearestEnemyOf(Myself),8)
  Range(SecondNearestEnemyOf(Myself),8)
  RandomNum(2,1)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  CheckStat(Myself,0,SCRIPTINGSTATE5)
  HPPercentLT(Myself,100)
  CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  RandomNum(2,1)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(Myself),45)
END

IF
  HPPercentLT(Myself,50)
  OR(3)
    HasItem("POTN55",Myself)  // ~Potion of Superior Healing~
    HaveSpell(MONK_LAY_ON_HANDS)
    Range(NearestMyGroupOfType,10)
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    RunAwayFrom(NearestEnemyOf(Myself),45)
END

IF
  Global("Lunar","GLOBAL",0)
THEN
  RESPONSE #100
    AttackReevaluate(LastSeenBy(Myself),30)
END

