IF
        See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("EXTENSIVECONTINGENCY","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("EXTENSIVECONTINGENCY","LOCALS",60)
                DisplayStringHead(Myself,@80)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_COLD)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_FIRE)
                ApplySpell(Myself,WIZARD_SPIRIT_ARMOR)
                ApplySpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
                ApplySpell(Myself,WIZARD_MISLEAD)
END

IF
        See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,WIZARD_SPELL_TRAP)
        GlobalLT("WSPT","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WSPT","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_TRAP)
END

IF
        See("RU_ASIM")
        ReceivedOrder(Myself,1)
THEN
	RESPONSE #100
		ReallyForceSpell("RU_ASIM",PHASE_SPIDER_TELEPORT)
                Wait(2)
                ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_DISPEL_MAGIC)
END

IF
        See("RU_CLOZE")
        ReceivedOrder(Myself,2)
THEN
	RESPONSE #100
		ReallyForceSpell("RU_CLOZE",PHASE_SPIDER_TELEPORT)
                Wait(2)
                ReallyForceSpell(NearestEnemyOf(Myself),WIZARD_DISPEL_MAGIC)
END

IF
        See(NearestEnemyOf(Myself))
	Global("Prep","LOCALS",0)
THEN
	RESPONSE #100
		ApplySpell(Myself,WIZARD_STONE_SKIN)
		ApplySpell(Myself,WIZARD_SPELL_TRAP)
		SetGlobal("Prep","LOCALS",1)
END

IF
        See(NearestEnemyOf(Myself))
	StateCheck(Myself,STATE_SILENCED)
        GlobalLT("WV","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WV","LOCALS",1)
		ForceSpell(Myself,WIZARD_VOCALIZE)
END

IF
        Global("TRIGGER","LOCALS",0)
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                SetGlobal("TRIGGER","LOCALS",1)
                DisplayString(Myself,39968)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
                Wait(6)
                Continue()
END

IF
        Allegiance(LastSeenBy(Myself),PC)
        OR(13)
          StateCheck(LastSeenBy(Myself), STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself), STATE_IMPROVEDINVISIBILITY)
          StateCheck(LastSeenBy(Myself), STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself), STATE_HASTED)
	  HasBounceEffects(LastSeenBy(Myself))
	  HasImmunityEffects(LastSeenBy(Myself))
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          CheckStatGT(LastSeenBy(Myself),0,IMPROVEDHASTE)
        GlobalLT("PENE","LOCALS",20)
THEN
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WARDING_WHIP)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_SECRET_WORD)
                Continue()
	RESPONSE #25
                IncrementGlobal("PENE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
        Global("spellTurn","LOCALS",0)
THEN
	RESPONSE #100
		ForceSpell(Myself,BEHOLDER_SPELL_TURNING)
		SetGlobal("spellTurn","LOCALS",1)
END

IF
	See([ANYONE.0.0.MAGE])
        !InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
		FaceObject(LastSeenBy(Myself))
		ReallyForceSpell(LastSeenBy(Myself),BEHOLDER_ANTIMAGIC_RAY)
                Continue()
END

IF
        See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		FaceObject(NearestEnemyOf(Myself))
		ForceSpell(NearestEnemyOf(Myself),BEHOLDER_SLOW)
		Continue()
END

IF
	See([GOODCUTOFF.0.0.0.0.SUMMONED])
THEN
	RESPONSE #100
		FaceObject(LastSeenBy(Myself))
		ForceSpell(LastSeenBy(Myself),BEHOLDER_PARALYZATION)
		ReallyForceSpell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

IF
        See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		FaceObject(NearestEnemyOf(Myself))
		ReallyForceSpell(NearestEnemyOf(Myself),BEHOLDER_CAUSE_SERIOUS_WOUNDS)
		Continue()
END

IF
        See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		FaceObject(NearestEnemyOf(Myself))
		ForceSpell(NearestEnemyOf(Myself),BEHOLDER_DEATH_RAY)
		Continue()
END

IF
        See(NearestEnemyOf(Myself))
THEN
	RESPONSE #100
		FaceObject(NearestEnemyOf(Myself))
		ForceSpell(NearestEnemyOf(Myself),BEHOLDER_FLESH_TO_STONE)
		Continue()
END

IF
        OR(2)
          StateCheck(NearestEnemyOf(Myself),STATE_INVISIBLE)
          StateCheck(NearestEnemyOf(Myself),STATE_IMPROVEDINVISIBILITY)
        !GlobalTimerNotExpired("TRUE_SIGHT","LOCALS")
        GlobalLT("WTR","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WTR","LOCALS",1)
                SetGlobalTimer("TRUE_SIGHT","LOCALS",30)
                ForceSpell(Myself,WIZARD_TRUE_SIGHT)
END

IF
        See([ENEMY])
        CheckStatGT(LastSeenBy(Myself), 0, RESISTMAGIC)
        GlobalLT("WLR","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WLR","LOCALS",1)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_LOWER_RESISTANCE)
END

IF
        See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WGM","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WGM","LOCALS",1)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WPMW","LOCALS",6)
        CheckStat(Myself,0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                IncrementGlobal("WPMW","LOCALS",1)
                ForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WST","LOCALS",6)
        !CheckStatGT(Myself, 0, STONESKINS)
THEN
	RESPONSE #100
                IncrementGlobal("WST","LOCALS",1)
                ForceSpell(Myself,WIZARD_STONE_SKIN)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WMI","LOCALS",6)
	!StateCheck(Myself,STATE_MIRRORIMAGE)
THEN
	RESPONSE #100
                IncrementGlobal("WMI","LOCALS",1)
                ForceSpell(Myself,WIZARD_MIRROR_IMAGE)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WFS","LOCALS",3)
        !GlobalTimerNotExpired("FIRESHIELD","LOCALS")
THEN
	RESPONSE #100
                IncrementGlobal("WFS","LOCALS",1)
                SetGlobalTimer("FIRESHIELD","LOCALS",60)
                ForceSpellRES("SPPR730",Myself)
END

IF
        See(NearestEnemyOf(Myself))
        GlobalLT("WSS","LOCALS",6)
        !CheckStat(Myself,1,WIZARD_SPELL_SHIELD)
THEN
	RESPONSE #100
                IncrementGlobal("WSS","LOCALS",1)
                ForceSpell(Myself,WIZARD_SPELL_SHIELD)
END

IF
        !GlobalTimerNotExpired("IMPRISONMENT","LOCALS")
        See(NearestEnemyOf(Myself))
        Range(LastSeenBy(Myself),3)
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WIMPR","LOCALS",3)
THEN
	RESPONSE #100
                IncrementGlobal("WIMPR","LOCALS",1)
                SetGlobalTimer("IMPRISONMENT","LOCALS",24)
                ReallyForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
END

IF
        See([ENEMY])
        !GlobalTimerNotExpired("MAZE","LOCALS")
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WM","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WM","LOCALS",1)
                SetGlobalTimer("MAZE","LOCALS",30)
                ForceSpell(LastSeenBy(Myself),WIZARD_MAZE)
END

IF
        See([ENEMY])
        HPLT(LastSeenBy(Myself), 90)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
	!StateCheck(LastSeenBy(Myself),STATE_STUNNED)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WPS","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WPS","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_STUN)
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        HPLT(LastSeenBy(Myself), 60)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WPK","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("WPK","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_POWER_WORD_KILL)
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, RESISTFIRE)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WDB","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WDB","LOCALS",1)
                ForceSpellRES("SPWI922",LastSeenBy(Myself))
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, RESISTFIRE)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WCOMET","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WCOMET","LOCALS",1)
                ForceSpellRES("SPWI925",LastSeenBy(Myself))
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, RESISTCRUSHING)
	!InMyGroup(LastSeenBy(Myself))
        GlobalLT("WBBCH","LOCALS",4)
THEN
	RESPONSE #100
                IncrementGlobal("WBBCH","LOCALS",1)
                ForceSpellRES("SPWI918",LastSeenBy(Myself))
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself), 30, RESISTMAGIC)
        CheckStatGT(LastSeenBy(Myself), 10, SAVEVSDEATH)
        GlobalLT("WWB","LOCALS",4)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WWB","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
END

IF
        See(NearestEnemyOf(Myself))
        CheckStatLT(LastSeenBy(Myself), 100, MAGICDAMAGERESISTANCE)
        CheckStatLT(LastSeenBy(Myself), 100, RESISTMAGIC)
        GlobalLT("WABI","LOCALS",5)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                IncrementGlobal("WABI","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
END

IF
	See(NearestEnemyOf(Myself))
        Global("SUMMON","LOCALS",0)
THEN
	RESPONSE #100
                SetGlobal("SUMMON","LOCALS",1)
                ForceSpellRES("SPWI923",Myself)
END

IF
	!InActiveArea(Myself)
        OR(24)
          GlobalGT("spellTurn","LOCALS",0)
          GlobalGT("SUMMON","LOCALS",0)
          GlobalGT("TRIGGER","LOCALS",0)
          GlobalGT("Prep","LOCALS",0)
          GlobalGT("WIMPR","LOCALS",0)
          GlobalGT("WBBCH","LOCALS",0)
          GlobalGT("WCOMET","LOCALS",0)
          GlobalGT("WWB","LOCALS",0)
          GlobalGT("WDB","LOCALS",0)
          GlobalGT("WABI","LOCALS",0)
          GlobalGT("WPK","LOCALS",0)
          GlobalGT("WPS","LOCALS",0)
          GlobalGT("WM","LOCALS",0)
          GlobalGT("WSS","LOCALS",0)
          GlobalGT("WFS","LOCALS",0)
          GlobalGT("WMI","LOCALS",0)
          GlobalGT("WST","LOCALS",0)
          GlobalGT("WPMW","LOCALS",0)
          GlobalGT("WGM","LOCALS",0)
          GlobalGT("WLR","LOCALS",0)
          GlobalGT("WTR","LOCALS",0)
          GlobalGT("PENE","LOCALS",0)
          GlobalGT("WV","LOCALS",0)
          GlobalGT("WSPT","LOCALS",0)
THEN
	RESPONSE #100
          SetGlobal("spellTurn","LOCALS",0)
          SetGlobal("SUMMON","LOCALS",0)
          SetGlobal("TRIGGER","LOCALS",0)
          SetGlobal("Prep","LOCALS",0)
          SetGlobal("WIMPR","LOCALS",0)
          SetGlobal("WBBCH","LOCALS",0)
          SetGlobal("WCOMET","LOCALS",0)
          SetGlobal("WWB","LOCALS",0)
          SetGlobal("WDB","LOCALS",0)
          SetGlobal("WABI","LOCALS",0)
          SetGlobal("WPK","LOCALS",0)
          SetGlobal("WPS","LOCALS",0)
          SetGlobal("WM","LOCALS",0)
          SetGlobal("WSS","LOCALS",0)
          SetGlobal("WFS","LOCALS",0)
          SetGlobal("WMI","LOCALS",0)
          SetGlobal("WST","LOCALS",0)
          SetGlobal("WPMW","LOCALS",0)
          SetGlobal("WGM","LOCALS",0)
          SetGlobal("WLR","LOCALS",0)
          SetGlobal("WTR","LOCALS",0)
          SetGlobal("PENE","LOCALS",0)
          SetGlobal("WV","LOCALS",0)
          SetGlobal("WSPT","LOCALS",0)
END