Scriptname WeaponThatCastsSpellsScript extends ObjectReferenceimport GameImport UtilitySpell Property WhatSpellToCast Auto{What spell will the weapon use?}ObjectReference Property SpellTarget Auto{This gets set to whatever the script picks as it's valid target.}ObjectReference Property EnemyAVCheck Auto{To store the enemy if we're targetting the weilder, but checking the enemy AV}Bool Property ProcOnHit Auto{Do we try to proc when we are hit?}Bool Property ProcOnLowAV Auto{Do we Proc on a low AV?}String Property AVToDetect Auto{ If so, Which AV are we checking?}Int Property AVLowPoint = 50 Auto{What AV value triggers the Low AV condition?}Bool Property AVOnTarget Auto {Does it check the AV on the hit target? If Not, it checks the AV on the weilder.}Bool Property AffectsWeilder Auto {Does the effect target the wielder of the weapon? If not, it targets the last hit target.}Bool Property CastIfDead Auto{Cast the spell even if the target is dead. Spell affects dead things.}Bool Property StickyEffect Auto{Will the effect continue to proc after it successfully procs once?}int Property StickyDuration Auto{How many times will the proc continue after the first one? A value of -1 means it will continue until the proc target is dead or the weapon is unequipped/sheathed.}Int Property ProcPercentage Auto {Chance for the Proc to go off, expressed as an integer percentage.}Float Property ProcFrequency Auto{Number of seconds between procs for Sticky Procs.}Int ProcCount ; Used to count down the sticky procs.Event OnEquipped(Actor Weilder) if AffectsWeilder SpellTarget = Weilder if ProcOnLowAV && !ProcOnHit ProcCount = StickyDuration; Warning: if it procs on low AV on the weilder and affects the weilder, but is not on an Onhit event, Sticky duration will only work when you equip with a low AV, and only once. RegisterForSingleUpdate(ProcFrequency) endif endifEndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) if !AffectsWeilder SpellTarget = akAggressor if ProcOnHit If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) endif WhatSpellToCast.Cast(SpellTarget) endif elseif ProcOnLowAV && AVOnTarget if (SpellTarget as Actor).GetAV(AVToDetect) < AVLowPoint If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) Endif WhatSpellToCast.Cast(SpellTarget) Endif endif elseif ProcOnLowAV && !AVOnTarget ; Weird case. Checking the AV on the weilder but hitting the enemy. if !EnemyAVCheck if Game.GetPlayer().IsEquipped(self) EnemyAVCheck = Game.GetPlayer() else EnemyAVCheck =FindClosestActorFromRef(Self,1000) ; Should be the weilder. endif Endif if (EnemyAVCheck as Actor).GetAV(AVToDetect) < AVLowPoint If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) Endif WhatSpellToCast.Cast(SpellTarget) Endif endif endif else if !SpellTarget ; Need to find the weilder - he obviously equipped with a hotkey and bypassed the OnEquipped event. if Game.GetPlayer().IsEquipped(self) SpellTarget = Game.GetPlayer() else SpellTarget = FindClosestActorFromRef(Self,1000) ; Should be the weilder. endif endif if ProcOnHit if ProcOnLowAV && AVOnTarget ; odd case. We're checking the ENEMY'S AV, but affecting the weilder. if !EnemyAVCheck EnemyAVCheck = akAggressor Endif if (EnemyAVCheck as Actor).GetAV(AVToDetect) < AVLowPoint If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) Endif WhatSpellToCast.Cast(SpellTarget) Endif endif elseif ProcOnLowAV if (SpellTarget as Actor).GetAV(AVToDetect) < AVLowPoint If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) Endif WhatSpellToCast.Cast(SpellTarget) Endif endif else If ProcPercentage <= Utility.RandomInt(1,100) if StickyEffect ProcCount = StickyDuration RegisterForSingleUpdate(ProcFrequency) Endif WhatSpellToCast.Cast(SpellTarget) Endif endif endif EndifEndEventEvent OnUpdate() ProcCount -= 1 if !(ProcCount == 0) if ProcOnLowAV && AffectsWeilder && !AVOnTarget ; This is the only case we need to check ProcPercentage on in the update. if (SpellTarget as Actor).GetAV(AVToDetect) < AVLowPoint If ProcPercentage <= Utility.RandomInt(1,100) WhatSpellToCast.Cast(SpellTarget) Endif endif elseif ProcOnLowAV && AffectsWeilder ; odd case. We're checking the ENEMY'S AV, but affecting the weilder. if EnemyAVCheck ; Make sure there's an enemy to check AV on. if (EnemyAVCheck as Actor).GetAV(AVToDetect) < AVLowPoint WhatSpellToCast.Cast(SpellTarget) ; We're counting down a sticky proc, but need to check AV anyway. endif endif else ; We're counting down a sticky proc. Proc chance already checked, etc. WhatSpellToCast.Cast(SpellTarget) endif if !(SpellTarget as Actor).IsDead() || CastIfDead if AffectsWeilder && (SpellTarget as Actor).IsEquipped(Self) ; Keeps it from updating if you unequip the item. RegisterForSingleUpdate(ProcFrequency) endif endif EndifEndEvent