IF
	HPLT(Myself,10)
THEN
	RESPONSE #100
		SetGlobal("psFinalQuestToKillMelCounter","GLOBAL",2)
		ClearAllActions()
		Wait(1)
		StartDialogue("psMelEnd", Player1)
END

If
	Global("psSpellUp", "LOCALS", 0)
Then
	Response #100
		ReallyForceSpell(myself, WIZARD_MIRROR_IMAGE)
		ReallyForceSpell(myself, WIZARD_STONE_SKIN)
		ReallyForceSpell(myself, WIZARD_GLOBE_OF_INVULNERABILITY)
		ReallyForceSpell(myself, WIZARD_SPELL_TRAP)
		ReallyForceSpell(myself, WIZARD_FIRE_SHIELD_RED)
		ReallyForceSpell(myself, WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)		
		ReallyForceSpell(myself, WIZARD_TRUE_SIGHT)		
		ReallyForceSpell(myself, 4665)
		SetGlobal("psSpellUp", "LOCALS", 1)
End

If
	TookDamage()
	Global("psMelInitialContToggle", "LOCALS", 0)
Then
	Response #100
		SetGlobal("psMelInitialContToggle", "LOCALS", 1)
		ReallyForceSpell(myself, WIZARD_MIRROR_IMAGE)
		ReallyForceSpell(myself, WIZARD_STONE_SKIN)
		ReallyForceSpell(myself, WIZARD_GLOBE_OF_INVULNERABILITY)
		ReallyForceSpell(myself, WIZARD_SPELL_TRAP)
		ReallyForceSpell(myself, WIZARD_FIRE_SHIELD_RED)
		ReallyForceSpell(myself, WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
		ReallyForceSpell(myself, WIZARD_TRUE_SIGHT)		
End

If
	RandomNum(12, 1)
		GlobalLT("psMelCastMantleCounter", "LOCALS", 8)
Then
	Response #100
		ForceSpell(Myself, WIZARD_ABSOLUTE_IMMUNITY)
		ForceSpell(Myself, WIZARD_STONE_SKIN)
		ForceSpell(Myself, WIZARD_TRUE_SIGHT)
		IncrementGlobal("psMelCastMantleCounter", "LOCALS", 1)
End

If
	RandomNum(18, 1)
	GlobalLT("psMelCastTimestopCounter", "LOCALS", 5)
	GlobalTimerExpired("psMelTimestopTimer", "LOCALS")
Then
	Response #100
		SetGlobalTimer("psMelTimestopTimer", "LOCALS", 18)
		ForceSpell(myself, WIZARD_TIME_STOP)
		IncrementGlobal("psMelCastTimestopCounter", "LOCALS", 1)
		Continue()
End

If
	RandomNum(15, 1)
	GlobalLT("psMelCastRageCounter", "LOCALS", 2)
Then
	Response #100
		ForceSpellRes("SPPSMRA", NearestEnemyOf(Myself))
		IncrementGlobal("psMelCastRageCounter", "LOCALS", 1)
End

If
	RandomNum(12, 1)
	GlobalLT("psMelCastWiltingCounter", "LOCALS", 6)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_ABI_DALZIMS_HORRID_WILTING)
		IncrementGlobal("psMelCastWiltingCounter", "LOCALS", 1)
End

If
	RandomNum(20, 1)
	GlobalLT("psMelCastRainCounter", "LOCALS", 2)
Then
	Response #100
		ForceSpellRes("SPPSMELR", NearestEnemyOf(Myself))
		IncrementGlobal("psMelCastRainCounter", "LOCALS", 1)
End

If
	RandomNum(25, 1)
	GlobalLT("psMelCastPlanatarCounter", "LOCALS", 2)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_SUMMON_PLANATAR_EVIL)
		IncrementGlobal("psMelCastPlanatarCounter", "LOCALS", 1)
End

If
	RandomNum(40, 1)
	GlobalLT("psMelCastSpellstrikeCounter", "LOCALS", 3)
Then
	Response #100
		DisplayStringHead(Myself, @608)
		ReallyForceSpell(Player1, WIZARD_SPELL_STRIKE)
		ReallyForceSpell(Player2, WIZARD_SPELL_STRIKE)
		ReallyForceSpell(Player3, WIZARD_SPELL_STRIKE)
		ReallyForceSpell(Player4, WIZARD_SPELL_STRIKE)
		ReallyForceSpell(Player5, WIZARD_SPELL_STRIKE)
		ReallyForceSpell(Player6, WIZARD_SPELL_STRIKE)
		IncrementGlobal("psMelCastSpellstrikeCounter", "LOCALS", 1)
End

If
	RandomNum(25, 1)
	GlobalLT("psMelCastDispelCounter", "LOCALS", 3)
Then
	Response #100
		DisplayStringHead(Myself, @609)
		ReallyForceSpell(Player1, WIZARD_TRUE_DISPEL_MAGIC)
		ReallyForceSpell(Player2, WIZARD_TRUE_DISPEL_MAGIC)
		ReallyForceSpell(Player3, WIZARD_TRUE_DISPEL_MAGIC)
		ReallyForceSpell(Player4, WIZARD_TRUE_DISPEL_MAGIC)
		ReallyForceSpell(Player5, WIZARD_TRUE_DISPEL_MAGIC)
		ReallyForceSpell(Player6, WIZARD_TRUE_DISPEL_MAGIC)		
		IncrementGlobal("psMelCastDispelCounter", "LOCALS", 1)
End

If
	RandomNum(15, 1)
	GlobalLT("psMelCastBigbysCounter", "LOCALS", 8)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_BIGBYS_CRUSHING_HAND)
		IncrementGlobal("psMelCastBigbysCounter", "LOCALS", 1)
End

If
	RandomNum(15, 1)
	GlobalLT("psMelCastEvilChainComboCounter", "LOCALS", 5)
Then
	Response #100
		ReallyForceSpell(NearestEnemyOf(Myself), WIZARD_GREATER_MALISON)
		ReallyForceSpell(NearestEnemyOf(Myself), WIZARD_CHAIN_LIGHTNING)
		ReallyForceSpell(NearestEnemyOf(Myself), WIZARD_CHAOS)
		IncrementGlobal("psMelCastEvilChainComboCounter", "LOCALS", 1)
End

If
	RandomNum(10, 1)
	Range(NearestEnemyOf(myself), 5)
	GlobalLT("psMelCantCatchMeCounter", "LOCALS", 4)
Then
	Response #100
		IncrementGlobal("psMelCantCatchMeCounter", "LOCALS", 1)
		ReallyForceSpell(Myself, WIZARD_SUN_FIRE)
		Wait(2)
		ReallyForceSpell(Myself, WIZARD_MORDENKAINENS_SWORD)
		ReallyForceSpell(Myself, WIZARD_MORDENKAINENS_SWORD)
		ReallyForceSpell(Myself, WIZARD_INVISIBLE_STALKER)
		ReallyForceSpell(Myself, WIZARD_INVISIBLE_STALKER)
		JumpToPoint([817.769])
End

If
	RandomNum(10, 1)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_SUN_FIRE)
End

If
	RandomNum(5, 1)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_FINGER_OF_DEATH)
End

If
	RandomNum(3, 1)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_MORDENKAINENS_SWORD)
End

If
	RandomNum(2, 1)
Then
	Response #100
		ForceSpell(NearestEnemyOf(Myself), WIZARD_MAGIC_MISSILE)
End

If
	RandomNum(2, 1)
Then
	Response #100
		MoveToObject(Player1)
		Continue()
End