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
  GlobalGT("allfive","GLOBAL",0)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  NumInPartyAliveGT(1)
  Difficulty(NORMAL)
  !GlobalTimerNotExpired("ChainContingency","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ChainContingency","LOCALS",1000)
    SetGlobalTimer("MelissanSummonDemon","LOCALS",18)
    DisplayString(Myself,73139)  // ~Contingency - Fired~
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
END

IF
  GlobalGT("allfive","GLOBAL",0)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  Difficulty(HARD)
  !GlobalTimerNotExpired("ChainContingency","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ChainContingency","LOCALS",1000)
    SetGlobalTimer("MelissanSummonDemon","LOCALS",18)
    DisplayString(Myself,73139)  // ~Contingency - Fired~
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
END

IF
  GlobalGT("allfive","GLOBAL",0)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  Difficulty(HARDEST)
  !GlobalTimerNotExpired("ChainContingency","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("ChainContingency","LOCALS",1000)
    SetGlobalTimer("MelissanSummonDemon","LOCALS",18)
    DisplayString(Myself,73139)  // ~Contingency - Fired~
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
    ReallyForceSpellRES("gate5",Myself)  // ~Gate~
END

IF
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  Global("FinalFight","AR6200",8)
  Global("MelInitial","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("MelInitial","LOCALS",1)
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("MelissanSummonDemon","LOCALS",12)
    SetGlobalTimer("DivineMantle","LOCALS",30)
    SetGlobalTimer("DivineShield","LOCALS",30)
    SetGlobalTimer("Cleansing","LOCALS",30)
    CreateCreatureObject("melrat",Myself,0,0,0)  // <Invalid Strref -1>
    ApplySpell(Myself,HEAL_NO_VISUAL)
    ReallyForceSpellRES("melspl01",Myself)  // ~Divine Mantle~
    ReallyForceSpellRES("melspl03",Myself)  // ~Divine Spell Shield~
END

IF
  Difficulty(HARDEST)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  Global("Draw","LOCALS",0)
  Global("SummonSolars","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("SummonSolars","LOCALS",1)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ForceSpellRES("gate7",Myself)  // ~Gate~
END

IF
  HPLT(Myself,20)
  Global("allfive","GLOBAL",0)
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Retreat","LOCALS")
THEN
  RESPONSE #100
    SetGlobal("Draw","LOCALS",1)
    SetInterrupt(FALSE)
    SetGlobalTimer("Retreat","LOCALS",15)
    IncrementGlobal("MelStillImmortal","AR6200",1)
    DisplayStringHead(Myself,67805)  // ~No!  Too strong!  Damn you!  I must take more essence...I must have more power!!~ [FINMEL27]
    ForceSpellPointRES("dimdoor",[1286.1122])
    Face(8)
    ForceSpellRES("melspl02",Myself)  // ~Draw Power~
    SetInterrupt(TRUE)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Freedom","LOCALS")
  Global("Draw","LOCALS",0)
  Global("IMPRISON","GLOBAL",1)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Freedom","LOCALS",30)
    SetInterrupt(FALSE)
    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)
    SetGlobal("SendaiImprisoned","AR6200",0)
    ClearActions(Myself)
    ForceSpell(Myself,WIZARD_FREEDOM)
    SetInterrupt(TRUE)
END

IF
  !HPLT(Myself,20)
  !DifficultyLT(NORMAL)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("Cleansing","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatLT(Myself,200,0)
  OR(10)
    CheckStatGT(Myself,-10,ARMORCLASS)
    CheckStatGT(Myself,-7,THAC0)
    CheckStatGT(Myself,0,SAVEVSSPELL)
    CheckStatLT(Myself,70,RESISTMAGIC)
    CheckStatGT(Myself,0,120)
    CheckStatGT(Myself,0,125)
    CheckStatGT(Myself,0,180)
    StateCheck(Myself,STATE_SILENCED)
    StateCheck(Myself,STATE_SLOWED)
    StateCheck(Myself,STATE_BLIND)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Cleansing","LOCALS",30)
    ReallyForceSpellRES("melspl12",Myself)  // ~Divine Cleansing~
  RESPONSE #50
    Continue()
END

IF
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("DivineMantle","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  Global("CloseCombat","LOCALS",1)
  OR(3)
    GlobalGT("allfive","GLOBAL",0)
    !HasItem("finbalth",Myself)  // <Invalid Strref -1>
    HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("DivineMantle","LOCALS",30)
    ForceSpellRES("melspl01",Myself)  // ~Divine Mantle~
  RESPONSE #50
    Continue()
END

IF
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("DivineShield","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(Myself,0,SCRIPTINGSTATE1)
  CheckStatLT(Myself,70,RESISTMAGIC)
  OR(4)
    See([GOODCUTOFF.0.0.MAGE_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("DivineShield","LOCALS",30)
    ForceSpellRES("melspl03",Myself)  // ~Divine Spell Shield~
  RESPONSE #50
    Continue()
END

IF
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("DivineShield","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(Myself,0,SCRIPTINGSTATE1)
  !CheckStatLT(Myself,70,RESISTMAGIC)
  OR(4)
    See([GOODCUTOFF.0.0.MAGE_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("DivineShield","LOCALS",30)
    ForceSpellRES("melspl03",Myself)  // ~Divine Spell Shield~
  RESPONSE #200
    Continue()
END

IF
  Allegiance(Myself,ENEMY)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(Myself,0,SCRIPTINGSTATE2)
  Range(NearestEnemyOf(Myself),8)
  Global("CloseCombat","LOCALS",1)
  !DifficultyLT(EASY)
  !GlobalTimerNotExpired("GlobeOfBlades","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("GlobeOfBlades","LOCALS",30)
    ForceSpellRES("melis02",Myself)  // ~Blade Barrier~
  RESPONSE #100
    Continue()
END

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("CircleKick","LOCALS")
  Global("Draw","LOCALS",0)
  Range(ThirdNearestEnemyOf(Myself),10)
  Global("CloseCombat","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobalTimer("CircleKick","LOCALS",15)
    ReallyForceSpellRES("dgwhirl",[PC])  // <Invalid Strref -1>
    SetSequence(SEQ_ATTACK_JAB)
  RESPONSE #50
    Continue()
END

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !CheckStatGT(Myself,0,118)
  Global("Draw","LOCALS",0)
  OR(8)
    StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(SecondNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(ThirdNearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
    StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    StateCheck(NearestEnemyOf(Myself),STATE_BLUR)
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
    CheckStatGT([GOODCUTOFF.0.0.LONG_BOW],0,PUPPETTYPE)
    CheckStatGT(SecondNearest([GOODCUTOFF.0.0.LONG_BOW]),0,PUPPETTYPE)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SpellNoDec(Myself,CLERIC_TRUE_SIGHT)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpell(Myself,CLERIC_TRUE_SIGHT)
  RESPONSE #50
    Continue()
END

IF
  !Difficulty(EASIEST)
  !Global("allfive","GLOBAL",0)
  !GlobalLT("TimeStop","LOCALS",15)
  Global("ReactTimeStop","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("ReactTimeStop","LOCALS",1)
    SetGlobalTimer("TimeStop","LOCALS",6)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  See(NearestEnemyOf(Myself))
  DifficultyGT(EASY)
  OR(3)
    Global("safe","LOCALS",1)
    !Range(NearestEnemyOf(Myself),12)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  !GlobalTimerNotExpired("TimeStop","LOCALS")
THEN
  RESPONSE #70
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",100)
    ForceSpell(Myself,WIZARD_TIME_STOP)
  RESPONSE #30
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",100)
    SpellNoDec(Myself,WIZARD_TIME_STOP)
  RESPONSE #100
    Continue()
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  See(NearestEnemyOf(Myself))
  DifficultyLT(NORMAL)
  OR(3)
    Global("safe","LOCALS",1)
    !Range(NearestEnemyOf(Myself),12)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  !GlobalTimerNotExpired("TimeStop","LOCALS")
THEN
  RESPONSE #70
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",1000)
    ForceSpell(Myself,WIZARD_TIME_STOP)
  RESPONSE #30
    SetGlobalTimer("SpellCast","LOCALS",6)
    SetGlobalTimer("TimeStop","LOCALS",1000)
    SpellNoDec(Myself,WIZARD_TIME_STOP)
  RESPONSE #100
    Continue()
END

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("Whirlwind","LOCALS")
  Global("Draw","LOCALS",0)
  Global("CloseCombat","LOCALS",1)
  !DifficultyLT(NORMAL)
  OR(4)
    CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
    CheckStatGT(SecondNearestEnemyOf(Myself),4,NUMBEROFATTACKS)
    Range(ThirdNearestEnemyOf(Myself),8)
    !Global("allfive","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Whirlwind","LOCALS",30)
    ForceSpell(Myself,WARRIOR_GREATER_WHIRLWIND)
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("Whirlwind","LOCALS")
  Global("Draw","LOCALS",0)
  Global("CloseCombat","LOCALS",1)
  DifficultyLT(NORMAL)
  OR(4)
    CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
    CheckStatGT(SecondNearestEnemyOf(Myself),4,NUMBEROFATTACKS)
    Range(ThirdNearestEnemyOf(Myself),8)
    !Global("allfive","GLOBAL",0)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Whirlwind","LOCALS",1000)
    ForceSpell(Myself,WARRIOR_GREATER_WHIRLWIND)
    AttackOneRound(NearestEnemyOf(Myself))
END

IF
  HPPercentLT(Myself,50)
  !Global("allfive","GLOBAL",0)
  Global("TimeToTeleport","LOCALS",0)
  Range(NearestEnemyOf(Myself),8)
  RandomNumLT(6,4)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  HPPercentLT(Myself,50)
  Global("CloseCombat","LOCALS",1)
  Global("TimeToTeleport","LOCALS",0)
  Range(SecondNearestEnemyOf(Myself),8)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),4,NUMBEROFATTACKS)
    CheckStatGT(SecondNearestEnemyOf(Myself),4,NUMBEROFATTACKS)
  RandomNumLT(6,4)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  HPPercentLT(Myself,50)
  Global("CloseCombat","LOCALS",1)
  Global("TimeToTeleport","LOCALS",0)
  CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  Range(ThirdNearestEnemyOf(Myself),8)
  RandomNumLT(6,4)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  HPPercentLT(Myself,50)
  Global("CloseCombat","LOCALS",1)
  Global("TimeToTeleport","LOCALS",0)
  !CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  Range(ThirdNearestEnemyOf(Myself),8)
  RandomNumLT(5,5)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

IF
  Global("TimeToTeleport","LOCALS",0)
  Global("allfive","GLOBAL",1)
  RandomNumLT(8,3)
THEN
  RESPONSE #100
    SetGlobal("TimeToTeleport","LOCALS",1)
END

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

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  !GlobalTimerNotExpired("Spell","LOCALS")
  Global("Draw","LOCALS",0)
  Global("TimeToTeleport","LOCALS",1)
  !Range("melrat",28)  // <Invalid Strref -1>
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobal("TimeToTeleport","LOCALS",0)
    ForceSpellRES("dimdoor","melrat")  // ~Dimension Door~
END

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

IF
  Allegiance(ThirdNearest([0.MONSTER.DEMONIC]),GOODCUTOFF)
  !HPPercentLT(ThirdNearest([0.MONSTER.DEMONIC]),50)
  !Gender(ThirdNearest([0.MONSTER.DEMONIC]),SUMMONED)
  !Global("ControlDemonTarget","LOCALS",1)
  !Global("ControlDemonTarget","LOCALS",2)
  See(ThirdNearest([0.MONSTER.DEMONIC]))
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",1)
END

IF
  Allegiance(ThirdNearest([0.MONSTER.DEMONIC]),GOODCUTOFF)
  !HPPercentLT(ThirdNearest([0.MONSTER.DEMONIC]),50)
  !Gender(ThirdNearest([0.MONSTER.DEMONIC]),SUMMONED)
  !Global("ControlDemonTarget","LOCALS",2)
  OR(2)
    Name("finbalor",ThirdNearest([0.MONSTER.DEMONIC]))
    Name("finmaril",ThirdNearest([0.MONSTER.DEMONIC]))
  See(ThirdNearest([0.MONSTER.DEMONIC]))
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",2)
END

IF
  Allegiance(SecondNearest([0.MONSTER.DEMONIC]),GOODCUTOFF)
  !HPPercentLT(SecondNearest([0.MONSTER.DEMONIC]),50)
  !Gender(SecondNearest([0.MONSTER.DEMONIC]),SUMMONED)
  !Global("ControlDemonTarget","LOCALS",2)
  !Global("ControlDemonTarget","LOCALS",1)
  See(SecondNearest([0.MONSTER.DEMONIC]))
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",1)
END

IF
  Allegiance(SecondNearest([0.MONSTER.DEMONIC]),GOODCUTOFF)
  !HPPercentLT(SecondNearest([0.MONSTER.DEMONIC]),50)
  !Gender(SecondNearest([0.MONSTER.DEMONIC]),SUMMONED)
  !Global("ControlDemonTarget","LOCALS",2)
  OR(2)
    Name("finbalor",SecondNearest([0.MONSTER.DEMONIC]))
    Name("finmaril",SecondNearest([0.MONSTER.DEMONIC]))
  See(SecondNearest([0.MONSTER.DEMONIC]))
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",2)
END

IF
  Allegiance([GOODCUTOFF.MONSTER.DEMONIC],GOODCUTOFF)
  !HPPercentLT([GOODCUTOFF.MONSTER.DEMONIC],50)
  !Gender([GOODCUTOFF.MONSTER.DEMONIC],SUMMONED)
  !Global("ControlDemonTarget","LOCALS",2)
  !Global("ControlDemonTarget","LOCALS",1)
  See([GOODCUTOFF.MONSTER.DEMONIC])
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",1)
END

IF
  !Global("ControlDemonTarget","LOCALS",2)
  !HPPercentLT([GOODCUTOFF.MONSTER.DEMONIC],50)
  !Gender([GOODCUTOFF.MONSTER.DEMONIC],SUMMONED)
  OR(2)
    Name("finbalor",[GOODCUTOFF.MONSTER.DEMONIC])
    Name("finmaril",[GOODCUTOFF.MONSTER.DEMONIC])
  See([GOODCUTOFF.MONSTER.DEMONIC])
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",2)
END

IF
  Global("ControlDemonTarget","LOCALS",2)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("ControlDemon","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobalTimer("ControlDemon","LOCALS",6)
    ForceSpellRES("melspl05",LastSeenBy(Myself))  // ~Command Demon~
  RESPONSE #50
    SetGlobalTimer("ControlDemon","LOCALS",6)
END

IF
  Global("ControlDemonTarget","LOCALS",1)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("ControlDemon","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobalTimer("ControlDemon","LOCALS",6)
    ForceSpellRES("melspl05",LastSeenBy(Myself))  // ~Command Demon~
  RESPONSE #100
    SetGlobalTimer("ControlDemon","LOCALS",6)
END

IF
  GlobalGT("ControlDemonTarget","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("ControlDemonTarget","LOCALS",0)
END

IF
  Allegiance(Myself,EVILCUTOFF)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  See([GOODCUTOFF.0.0.0.0.SUMMONED])
  !HPPercentLT(LastSeenBy(Myself),35)
  LevelGT(LastSeenBy(Myself),10)
  RandomNumLT(4,3)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpellRES("melspl06",LastSeenBy(Myself))  // ~Banish~
END

IF
  Allegiance(Myself,GOODCUTOFF)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  See([EVILCUTOFF.0.0.0.0.SUMMONED])
  !HPPercentLT(LastSeenBy(Myself),35)
  LevelGT(LastSeenBy(Myself),10)
  RandomNumLT(4,3)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpellRES("melspl06",LastSeenBy(Myself))  // ~Banish~
END

IF
  Global("UseRestoration","LOCALS",0)
  LevelLT("finilla",12)  // ~Illasera~
  !Dead("finilla")  // ~Illasera~
  See("finilla")  // ~Illasera~
THEN
  RESPONSE #100
    SetGlobal("UseRestoration","LOCALS",1)
END

IF
  Global("UseRestoration","LOCALS",0)
  LevelLT("finyaga",12)  // ~Yaga-Shura~
  !Dead("finyaga")  // ~Yaga-Shura~
  See("finyaga")  // ~Yaga-Shura~
THEN
  RESPONSE #100
    SetGlobal("UseRestoration","LOCALS",1)
END

IF
  Global("UseRestoration","LOCALS",0)
  LevelLT("finabaz",20)  // ~Abazigal~
  !Dead("finabaz")  // ~Abazigal~
  See("finabaz")  // ~Abazigal~
THEN
  RESPONSE #100
    SetGlobal("UseRestoration","LOCALS",1)
END

IF
  Global("UseRestoration","LOCALS",0)
  LevelLT("finsend",20)  // ~Sendai~
  !Dead("finsend")  // ~Sendai~
  See("finsend")  // ~Sendai~
THEN
  RESPONSE #100
    SetGlobal("UseRestoration","LOCALS",1)
END

IF
  Global("UseRestoration","LOCALS",0)
  LevelLT("finbalth",20)  // ~Balthazar~
  !Dead("finbalth")  // ~Balthazar~
  See("finbalth")  // ~Balthazar~
THEN
  RESPONSE #100
    SetGlobal("UseRestoration","LOCALS",1)
END

IF
  Global("UseRestoration","LOCALS",1)
  !HPPercentLT(Myself,50)
  !CheckStatLT(Myself,16,STR)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  RandomNumLT(9,7)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobal("UseRestoration","LOCALS",0)
    ForceSpellRES("melspl11",LastSeenBy(Myself))  // ~Divine Restoration~
END

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

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  Global("allfive","GLOBAL",1)
  !GlobalTimerNotExpired("MelissanSummonDemon","LOCALS")
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  OR(2)
    NumInPartyAliveGT(1)
    DifficultyGT(NORMAL)
  !DifficultyLT(NORMAL)
  OR(3)
    Global("safe","LOCALS",1)
    !Range(NearestEnemyOf(Myself),12)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  RandomNumLT(12,7)
THEN
  RESPONSE #30
    SetGlobalTimer("MelissanSummonDemon","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    SpellNoDecRES("gate5",Myself)
  RESPONSE #70
    SetGlobalTimer("MelissanSummonDemon","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ForceSpellRES("gate5",Myself)  // ~Gate~
END

IF
  !HPLT(Myself,20)
  Allegiance(Myself,ENEMY)
  Global("allfive","GLOBAL",0)
  !GlobalTimerNotExpired("MelissanSummonDemon","LOCALS")
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  OR(2)
    NumInPartyAliveGT(1)
    DifficultyGT(NORMAL)
  !DifficultyLT(NORMAL)
  OR(3)
    Global("safe","LOCALS",1)
    !Range(NearestEnemyOf(Myself),12)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
  RandomNumLT(12,5)
THEN
  RESPONSE #30
    SetGlobalTimer("MelissanSummonDemon","LOCALS",24)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    SpellNoDecRES("gate5",Myself)
  RESPONSE #70
    SetGlobalTimer("MelissanSummonDemon","LOCALS",24)
    SetGlobalTimer("Spell","LOCALS",6)
    DisplayStringHead(Myself,73244)  // ~Come to your mistress, minions of the Abyss!~
    ForceSpellRES("gate5",Myself)  // ~Gate~
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
  !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
  Global("BalthazarFights","GLOBAL",1)
  Range("balth2",10)  // ~Balthazar~
  !Dead("balth2")  // ~Balthazar~
  See("balth2")  // ~Balthazar~
  False()
THEN
  RESPONSE #100
END

IF
  Range(Player1,15)
  See(Player1)
  False()
THEN
  RESPONSE #100
END

IF
  Range(LastAttackerOf(Myself),8)
  HPGT(LastAttackerOf(Myself),0) 
  Global("CloseCombat","LOCALS",1)
  OR(4)
    !GlobalTimerNotExpired("TimeStop","LOCALS")
    CheckStatGT(LastAttackerOf(Myself),0,SCRIPTINGSTATE1)
    InParty(LastAttackerOf(Myself))
    LevelGT(LastAttackerOf(Myself),12)
  OR(2)
    !CheckStatGT(Myself,0,SCRIPTINGSTATE5)
    !Global("allfive","GLOBAL",0)
  !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])
THEN
  RESPONSE #100
    MoveToObject(Player1)
END

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

IF
  !HPLT(Myself,20)
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Breach","LOCALS")
  !InPartySlot(LastSeenBy(Myself),0)
  OR(13)
    CheckStatGT(LastSeenBy(Myself),0,178)
    CheckStatGT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
    CheckStatGT(LastSeenBy(Myself),50,RESISTMAGICCOLD)
    CheckStatGT(LastSeenBy(Myself),50,RESISTACID)
    CheckStatGT(LastSeenBy(Myself),50,RESISTELECTRICITY)
    CheckStatGT(LastSeenBy(Myself),0,126)
    CheckStatGT(LastSeenBy(Myself),0,130)
    CheckStatGT(LastSeenBy(Myself),0,163)
    CheckStatGT(LastSeenBy(Myself),0,179)
    CheckStatGT(LastSeenBy(Myself),0,181)
    CheckStatGT(LastSeenBy(Myself),0,128)
    CheckStatGT(LastSeenBy(Myself),3,STONESKINS)
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE5)
  RandomNumLT(18,7)
THEN
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Breach","LOCALS",18)
    ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Breach","LOCALS",18)
    SpellNoDec(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  !HPLT(Myself,20)
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Breach","LOCALS")
  InPartySlot(LastSeenBy(Myself),0)
  OR(6)
    CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE1)
    CheckStatGT(LastSeenBy(Myself),0,163)
    CheckStatGT(LastSeenBy(Myself),0,119)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,128)
    CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
  RandomNumLT(21,8)
THEN
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Breach","LOCALS",18)
    ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Breach","LOCALS",18)
    SpellNoDec(LastSeenBy(Myself),WIZARD_BREACH)
END

IF
  !HPLT(Myself,20)
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("PierceShield","LOCALS")
  OR(2)
    CheckStatGT(LastSeenBy(Myself),20,RESISTMAGIC)
    RandomNumLT(11,5)
  OR(9)
    CheckStatGT(LastSeenBy(Myself),0,164)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,164)
    CheckStatGT(LastSeenBy(Myself),29,RESISTMAGIC)
  RandomNumLT(24,9)
THEN
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("PierceShield","LOCALS",18)
    ForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("PierceShield","LOCALS",18)
    SpellNoDec(LastSeenBy(Myself),WIZARD_PIERCE_SHIELD)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  Gender(LastSeenBy(Myself),SUMMONED)
  LevelLT(LastSeenBy(Myself),11)
THEN
  RESPONSE #70
    SetGlobalTimer("SpellCast","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
  RESPONSE #30
    SetGlobalTimer("SpellCast","LOCALS",6)
    SpellNoDec(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("ControlDemon","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  Race(LastSeenBy(Myself),DEMONIC)
  !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  !Gender(LastSeenBy(Myself),SUMMONED)
THEN
  RESPONSE #100
    SetGlobalTimer("ControlDemon","LOCALS",6)
    ForceSpellRES("melspl05",LastSeenBy(Myself))  // ~Command Demon~
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  Gender(LastSeenBy(Myself),SUMMONED)
  LevelGT(LastSeenBy(Myself),10)
THEN
  RESPONSE #100
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpellRES("melspl06",LastSeenBy(Myself))  // ~Banish~
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Unleash","LOCALS")
  Range(ThirdNearestEnemyOf(Myself),10)
  !DifficultyLT(EASY)
  RandomNumLT(27,19)
THEN
  RESPONSE #70
    SetGlobalTimer("Unleash","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    SetSequence(SEQ_ATTACK_JAB)
    ForceSpellRES("melspl08",NearestEnemyOf(Myself))  // ~Unleash~
  RESPONSE #30
    SetGlobalTimer("Unleash","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    SetSequence(SEQ_ATTACK_JAB)
    SpellNoDecRES("melspl08",NearestEnemyOf(Myself))
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("Unleash","LOCALS")
  Range(LastSeenBy(Myself),10)
  Range(SecondNearestEnemyOf(Myself),10)
  !DifficultyLT(EASY)
  RandomNumLT(25,11)
THEN
  RESPONSE #70
    SetGlobalTimer("Unleash","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    SetSequence(SEQ_ATTACK_JAB)
    ForceSpellRES("melspl08",LastSeenBy(Myself))  // ~Unleash~
  RESPONSE #30
    SetGlobalTimer("Unleash","LOCALS",18)
    SetGlobalTimer("Spell","LOCALS",6)
    SetSequence(SEQ_ATTACK_JAB)
    SpellNoDecRES("melspl08",LastSeenBy(Myself))
END

IF
  !HPLT(Myself,20)
  !InPartySlot(LastSeenBy(Myself),0)
  Range(ThirdNearestEnemyOf(Myself),30)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("GreaterCurse","LOCALS")
  Global("Draw","LOCALS",0)
  !DifficultyLT(NORMAL)
  RandomNumLT(30,21)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("GreaterCurse","LOCALS",100)
    SpellNoDecRES("melspl07",Myself)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("GreaterCurse","LOCALS",100)
    ForceSpellRES("melspl07",Myself)  // ~Taint of the Slayer~
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("SymbolSlow","LOCALS")
  Global("Draw","LOCALS",0)
  OR(4)
    StateCheck(LastSeenBy(Myself),STATE_HASTED)
    HPGT(LastSeenBy(Myself),100)
    !Range(LastSeenBy(Myself),15)
    CheckStatGT(LastSeenBy(Myself),4,NUMBEROFATTACKS)
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  RandomNumLT(20,11)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("SymbolSlow","LOCALS",30)
    SpellNoDecRES("SPWI545",LastSeenBy(Myself))
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("SymbolSlow","LOCALS",30)
    ForceSpellRES("SPWI545",LastSeenBy(Myself))  // ~Symbol Slow~
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("UnholyWord","LOCALS")
  Global("Draw","LOCALS",0)
  OR(4)
    LevelLT(LastSeenBy(Myself),11)
    Class(LastSeenBy(Myself),MAGE_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  RandomNumLT(22,12)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("UnholyWord","LOCALS",30)
    SpellNoDec(LastSeenBy(Myself),CLERIC_UNHOLY_WORD)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("UnholyWord","LOCALS",30)
    ForceSpell(LastSeenBy(Myself),CLERIC_UNHOLY_WORD)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Vengeance","LOCALS")
  !GlobalTimerNotExpired("MelissanBigAttack","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),0,130)
  !CheckStatGT(LastSeenBy(Myself),0,163)
  !CheckStatGT(LastSeenBy(Myself),0,126)
  !Range(LastSeenBy(Myself),15)
  RandomNumLT(26,14)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Vengeance","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    SpellNoDec(LastSeenBy(Myself),CLERIC_STORM_OF_VENGEANCE)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Vengeance","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),CLERIC_STORM_OF_VENGEANCE)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Comet","LOCALS")
  !GlobalTimerNotExpired("MelissanBigAttack","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(LastSeenBy(Myself),75,RESISTFIRE)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
    !Range(NearestEnemyOf(Myself),12)
  RandomNumLT(28,15)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Comet","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    SpellNoDec(LastSeenBy(Myself),KAISHAS_CHANGE)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Comet","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),KAISHAS_CHANGE)
END

IF
  !HPGT(LastSeenBy(Myself),70)
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("PWKill","LOCALS")
  Global("Draw","LOCALS",0)
  InParty(LastSeenBy(Myself))
  NumInPartyAliveGT(1)
  !DifficultyLT(EASY)
  !HasItemEquiped("CLCK26",LastSeenBy(Myself))
  !CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
  RandomNumLT(34,18)
THEN
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("PWKill","LOCALS",100)
    DisplayStringHead(Myself,22142)  // ~Power Word, Kill~
    ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("PWKill","LOCALS",100)
    DisplayStringHead(Myself,22142)  // ~Power Word, Kill~
    SpellNoDec(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("Bigby","LOCALS")
  Global("Draw","LOCALS",0)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
    !Range(NearestEnemyOf(Myself),12)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  !CheckStatLT(LastSeenBy(Myself),0,SAVEVSDEATH)
  OR(2)
    HPGT(LastSeenBy(Myself),100)
    HPLT(LastSeenBy(Myself),40)
  RandomNumLT(38,20)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Bigby","LOCALS",1000)
    SpellNoDec(LastSeenBy(Myself),WIZARD_BIGBYS_CRUSHING_HAND)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("Bigby","LOCALS",1000)
    ForceSpell(LastSeenBy(Myself),WIZARD_BIGBYS_CRUSHING_HAND)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("DragonsBreath","LOCALS")
  !GlobalTimerNotExpired("MelissanBigAttack","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(LastSeenBy(Myself),75,RESISTFIRE)
  OR(3)
    Global("safe","LOCALS",1)
    CheckStatGT(Myself,0,SCRIPTINGSTATE5)
    !Range(NearestEnemyOf(Myself),12)
  RandomNumLT(44,23)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("DragonsBreath","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    SpellNoDec(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("DragonsBreath","LOCALS",1000)
    SetGlobalTimer("MelissanBigAttack","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_DRAGONS_BREATH)
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !CheckStatGT(LastSeenBy(Myself),30,RESISTMAGIC)
  !CheckStatGT(LastSeenBy(Myself),50,0)
  RandomNumLT(33,23)
THEN
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpellRES("melspl09",LastSeenBy(Myself))  // ~Unleash~
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SpellNoDecRES("melspl09",LastSeenBy(Myself))
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  Global("Draw","LOCALS",0)
  !GlobalTimerNotExpired("BladesAttack","LOCALS")
  !Range(LastSeenBy(Myself),8)
  !CheckStatGT(LastSeenBy(Myself),50,RESISTSLASHING)
  RandomNumLT(46,24)
THEN
  RESPONSE #70
    SetGlobalTimer("BladesAttack","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    ForceSpellRES("melis01",LastSeenBy(Myself))  // ~Bone Blades~
  RESPONSE #30
    SetGlobalTimer("BladesAttack","LOCALS",12)
    SetGlobalTimer("Spell","LOCALS",6)
    SpellNoDecRES("melis01",LastSeenBy(Myself))
END

IF
  !HPLT(Myself,20)
  !GlobalTimerNotExpired("Spell","LOCALS")
  !GlobalTimerNotExpired("LockTarget","LOCALS")
  !GlobalTimerNotExpired("FingerOfDeath","LOCALS")
  Global("Draw","LOCALS",0)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  !CheckStatLT(LastSeenBy(Myself),0,SAVEVSDEATH)
  !CheckStatGT(LastSeenBy(Myself),0,SCRIPTINGSTATE2)
  HPPercentGT(LastSeenBy(Myself),50)
  RandomNumLT(36,25)
THEN
  RESPONSE #30
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("FingerOfDeath","LOCALS",18)
    SpellNoDec(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
  RESPONSE #70
    SetGlobalTimer("Spell","LOCALS",6)
    SetGlobalTimer("FingerOfDeath","LOCALS",18)
    ForceSpell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

IF
  Global("Draw","LOCALS",0)
  !HPLT(Myself,20)
  HPPercentGT(Myself,50)
  OR(4)
    StateCheck(LastSeenBy(Myself),STATE_STUNNED)
    StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
    StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
    CheckStatGT(LastSeenBy(Myself),0,HELD)
  !CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
    CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END

IF
  Global("Draw","LOCALS",0)
  !HPLT(Myself,20)
  !CheckStatGT(LastSeenBy(Myself),0,128)
  OR(2)
    CheckStatLT(LastSeenBy(Myself),100,RESISTSLASHING)
    CheckStatLT(LastSeenBy(Myself),100,RESISTCOLD)
THEN
  RESPONSE #100
    AttackOneRound(NearestEnemyOf(Myself))
END

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

