Scriptname SpellFail extends activemagiceffect Message Property SpellFailedMSG AutoActor Property PlayerREF AutoString Property CasterSkill auto ; fill this string with Alteration, Illusion etc. depending on the spell schoolSpell Property CurrentSpell auto ; fill this with the spell this effect is attached toSpell Property CurrentSpell2 auto ; some effects are attached to more than one spell, the 2nd spell being specific to the left hand [now seriously Beth, WTF?]Event OnEffectStart(Actor akTarget, Actor akCaster) bool righthand = false bool lefthand = false Spell LeftHandSpell = akCaster.GetEquippedSpell(0) Spell RightHandSpell = akCaster.GetEquippedSpell(1) if ( ( LeftHandSpell == CurrentSpell ) || ( RightHandSpell == CurrentSpell ) || ( LeftHandSpell == CurrentSpell2 ) || ( RightHandSpell == CurrentSpell2 ) ) ; this is to prevent scrolls and staves effects to be dispelled int RandomRate = Utility.RandomInt(1, 100) float ActorSkill = akCaster.GetActorValue(CasterSkill) int FailChanceOffset = 30 ; no spell fail if the Actor skill is >= 70 float FailChance FailChance = RandomRate / (ActorSkill + FailChanceOffset) if ( FailChance > 1 ) if Self != NONE ; at this point the effect might be either weared off or non-existing, so we check for its existence to prevent Papyrus complaining on missing entities dispel() endif if ( LeftHandSpell ) ; the following is a convoluted and yet effective way to unequip and reequip a failed spell, so that holding the casting key during a spell fail is useless lefthand = true akCaster.UnequipSpell(LeftHandSpell, 0) endif if ( RightHandSpell ) righthand = true akCaster.UnequipSpell(RightHandSpell, 1) endif if ( lefthand ) akCaster.EquipSpell(LeftHandSpell, 0) endif if ( righthand ) akCaster.EquipSpell(RightHandSpell, 1) endif If ( akCaster == PlayerREF ) SpellFailedMSG.Show() ; your spell failed! LOL! NOOB! EndIf EndIf EndifEndEvent

float Property max autoEvent OnEffectStart(Actor akTarget, Actor akCaster)	; Let's say you want to restore your health through a script.	If (Game.GetPlayer() == akTarget)		If (akTarget.GetActorValuePercentage("health") >= max)			akTarget.InterruptCast()			Debug.Notification("You cannot cast this spell at this time")			; Because your health is at 100% (represented by 1.0) this casting will be interrupted until the condition is met.		ElseIf (akTarget.GetActorValuePercentage("health") <= max)			akTarget.RestoreAV("health", 300)		EndIf	EndIfEndEventfloat Property max autoEvent OnEffectStart(Actor akTarget, Actor akCaster)	; Let's say you want to restore your health through a script.	If (Game.GetPlayer() == akTarget)		If (akTarget.GetActorValuePercentage("health") >= max)			akTarget.InterruptCast()			Debug.Notification("You cannot cast this spell at this time")			; Because your health is at 100% (represented by 1.0) this casting will be interrupted until the condition is met.		ElseIf (akTarget.GetActorValuePercentage("health") <= max)			akTarget.RestoreAV("health", 300)		EndIf	EndIfEndEventScriptname CastingManagement extends activemagiceffect  Message Property SpellFailedMSG Auto					; fill this with something along the lines of "The spell failed."Sound Property MAGFail AutoActor Property PlayerREF AutoKeyword Property MagicSchoolAlteration Auto					; since there's no way to detect beforehand a spell school,Keyword Property MagicSchoolConjuration Auto					; we have to attach these keywords to the spells thatKeyword Property MagicSchoolDestruction Auto					; should be affected by the interrupting abilityKeyword Property MagicSchoolIllusion AutoKeyword Property MagicSchoolRestoration AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)	bool LeftSpellFailed = false					; we use these to check whether we should	bool RightSpellFailed = false					; inform the player that the spell failed or not	float LeftSpellSkill						; we need separate skill checks for either hands	float RightSpellSkill	Spell LeftHandSpell = akCaster.GetEquippedSpell(0)		; first off, get the equipped spells..	Spell RightHandSpell = akCaster.GetEquippedSpell(1)	LeftSpellSkill = GetSpellSkill (LeftHandSpell, akCaster)	; ..then check for the casting actor skill	RightSpellSkill = GetSpellSkill (RightHandSpell, akCaster)	int LeftRandomRate = Utility.RandomInt(1, 100)			; we use two separate random generate numbers,	int RightRandomRate = Utility.RandomInt(1, 100)			; so that the same spell could fail in one hand and have success in the other	int FailChanceOffset = 25					; no spell fail if the Actor skill is >= 75	float LeftFailChance = LeftRandomRate / (LeftSpellSkill + FailChanceOffset)	; the higher the skill, the lower the chance to fail	float RightFailChance = RightRandomRate / (RightSpellSkill + FailChanceOffset)	if ( LeftHandSpell )		if ( LeftFailChance > 1 )			akCaster.UnequipSpell(LeftHandSpell, 0)		; remove the spell and immediately reattach it to the hand,			akCaster.EquipSpell(LeftHandSpell, 0)		; this has the effect of actually preventing the spell from being casted			LeftSpellFailed = true				; without disrupting the gameplay		endif	endif	if ( RightHandSpell )		if ( RightFailChance > 1 )			akCaster.UnequipSpell(RightHandSpell, 1)	; same as above			akCaster.EquipSpell(RightHandSpell, 1)			RightSpellFailed = true		endif	endif	If ( ( akCaster == PlayerREF ) && ( ( LeftSpellFailed ) || ( RightSpellFailed ) ) )		SpellFailedMSG.Show()					; your spell failed! LOL! NOOB!		   	 MAGFail.play(akCaster)	EndIfEndEventFloat Function GetSpellSkill(Spell ActorSpell, Actor CastingActor)	float ActorSkill	if ( ActorSpell.GetNthEffectMagicEffect(0).HasKeyword( MagicSchoolAlteration ) )		ActorSkill = CastingActor.GetActorValue("Alteration")			elseif ( ActorSpell.GetNthEffectMagicEffect(0).HasKeyword( MagicSchoolConjuration ) )		ActorSkill = CastingActor.GetActorValue("Conjuration")	elseif ( ActorSpell.GetNthEffectMagicEffect(0).HasKeyword( MagicSchoolDestruction ) )		ActorSkill = CastingActor.GetActorValue("Destruction")	elseif ( ActorSpell.GetNthEffectMagicEffect(0).HasKeyword( MagicSchoolIllusion ) )		ActorSkill = CastingActor.GetActorValue("Illusion")	elseif ( ActorSpell.GetNthEffectMagicEffect(0).HasKeyword( MagicSchoolRestoration ) )		ActorSkill = CastingActor.GetActorValue("Restoration")	endif			return ActorSkillEndFunction
 forget the first version, no keywords needed anymore and it's missing an important check that throws warnings at the logs.Scriptname CastingManagement extends activemagiceffect  Message Property SpellFailedMSG Auto                ; fill this with something along the lines of "The spell failed."Actor Property PlayerREF AutoSound Property MAGFail AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)    int FailChanceOffset = 25                            ; no spell fail if the Actor skill is >= 75    bool LeftSpellFailed = false                            ; we use these to check whether we should    bool RightSpellFailed = false                            ; inform the player that the spell failed or not    float LeftSpellSkill = 1                                ; we need separate skill checks for either hands    float RightSpellSkill = 1    float LeftFailChance    float RightFailChance    int LeftRandomRate    int RightRandomRate    Spell LeftHandSpell = akCaster.GetEquippedSpell(0)    ; first off, get the equipped spells..    Spell RightHandSpell = akCaster.GetEquippedSpell(1)    if ( LeftHandSpell )        LeftSpellSkill = GetSpellSkill (LeftHandSpell, akCaster)    ; ..then check for the casting actor skill        LeftRandomRate = Utility.RandomInt(1, 100)        ; we use two separate random generate numbers, so that the same spell could fail in one hand and have success in the other        LeftFailChance = LeftRandomRate / (LeftSpellSkill + FailChanceOffset)        ; the higher the skill, the lower the chance to fail        if ( LeftFailChance > 1 )            akCaster.UnequipSpell(LeftHandSpell, 0)        ; remove the spell and immediately reattach it to the hand,            akCaster.EquipSpell(LeftHandSpell, 0)        ; this has the effect of actually preventing the spell from being casted            LeftSpellFailed = true                        ; without disrupting the gameplay        endif    endif    if ( RightHandSpell )        RightSpellSkill = GetSpellSkill (RightHandSpell, akCaster)        RightRandomRate = Utility.RandomInt(1, 100)        RightFailChance = RightRandomRate / (RightSpellSkill + FailChanceOffset)        if ( RightFailChance > 1 )            akCaster.UnequipSpell(RightHandSpell, 1)    ; same as above            akCaster.EquipSpell(RightHandSpell, 1)            RightSpellFailed = true        endif    endif    If ( ( akCaster == PlayerREF ) && ( ( LeftSpellFailed ) || ( RightSpellFailed ) ) )        SpellFailedMSG.Show()                    ; your spell failed! LOL! NOOB!        MAGFail.play(akCaster)    EndIfEndEventFloat Function GetSpellSkill(Spell ActorSpell, Actor CastingActor)    float ActorSkill    if ( ActorSpell.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Alteration" )        ActorSkill = CastingActor.GetActorValue("Alteration")            elseif ( ActorSpell.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Conjuration")        ActorSkill = CastingActor.GetActorValue("Conjuration")    elseif ( ActorSpell.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Destruction")        ActorSkill = CastingActor.GetActorValue("Destruction")    elseif ( ActorSpell.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Illusion" )        ActorSkill = CastingActor.GetActorValue("Illusion")    elseif ( ActorSpell.GetNthEffectMagicEffect(0).GetAssociatedSkill() == "Restoration" )        ActorSkill = CastingActor.GetActorValue("Restoration")    endif            return ActorSkillEndFunction