Scripting Question about Dispelling a Magic Effect

Post » Sun Dec 29, 2013 12:55 am

Hello,

I have a potion that I am working on which uses a script. And that script is not working. I am hoping someone knows what I am doing wrong.

The potion is intended to give a timed effect, with the end result similar to the Perk: Avoid Death. The idea being you can drink the potion, and for the next X period of time if a hit brings you to less than 10% of your health, it will heal you.

Overall, I have this working just fine.

What I cannot get to work is that once the it heals you, I want the overall potions effect to be dispelled.

The potion has a magic effect as normal. The magic effect runs the script. The script then does an OnHit event to cast the healing spell - and hopefully to ultimately dispel its own magic effect.

The script's code is:

Scriptname GBobMagicItemPotionAvoidDeath extends ActiveMagicEffect  ; based upon Avoid Death perk and script in Vanilla SkyrimSpell Property HealSpell  Auto  float Property PercentHealth = 100.0 Auto  MagicEffect Property EffectToDispel Auto; ready to heal youEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked ); ;	debug.trace(self + " Enter Bleedout");		; cast heal spell	PercentHealth = GetTargetActor().GetAVPercentage("Health")	If (PercentHealth < 0.1)		HealSpell.Cast(GetTargetActor())		if (GetTargetActor().hasMagicEffect(EffectToDispel)=1)			GetTargetActor().EffectToDispel.Dispel()		endif	EndIfendEvent

The lines:

if (GetTargetActor().hasMagicEffect(EffectToDispel)=1)
GetTargetActor().EffectToDispel.Dispel()
endif

... are the overall problem that I cannot get to work as it does not compile. I believe I am using the whole MagicEffect and dispel incorrectly, but cannot find a good reference or example on how to do it.

Essentially, it is this ActiveMagicEffect that I want to remove (dispel, etc) immediately after the healing spell is cast.

Does anyone have any advice?

Thanks in advance!

User avatar
FITTAS
 
Posts: 3381
Joined: Sat Jan 13, 2007 4:53 pm

Post » Sun Dec 29, 2013 3:01 am

You're going to like the simplicity of this solution. Instead of:

HealSpell.Cast(GetTargetActor())if (GetTargetActor().hasMagicEffect(EffectToDispel)=1)   GetTargetActor().EffectToDispel.Dispel()endif

Just put this in your code:

HealSpell.Cast(GetTargetActor())dispel()

And you can ditch the MagicEffect property altogether. You've been trying to dispel the base MagicEffect, which is just a template on which this active effect is based. Using the "dispel()" command (or "self.dispel()" will do the same thing) will instead dispel this particular effect.

User avatar
Irmacuba
 
Posts: 3531
Joined: Sat Mar 31, 2007 2:54 am


Return to V - Skyrim