How do I remove an Active Effect via script?

Post » Wed Jun 26, 2013 4:28 pm

Ok, first thing you should know is that I am VERY new to scripting and modding in general.

Second, my mod is already working fantastically, but with only one slight irritation(or two).

I made this mod to add a new summon spell into the game. More specifically, it summons a shield into the players left hand in much the same way that bound weapons are.

I want it to function entirely the same way as bound weapons (except visually of course, it doesn't need any of their summon animations)

That means dispelling and removing them when unequipped. So far I've accomplished it perfectly with a few minor issues.

The first problem I had was while casting the spell in the right hand when the shield is already summoned.

It would remove the currently equipped shield but not place a new one into the empty shield-hand. I overcame this by making the spell a left-hand slot item only. The vanilla bound weapons never run into this scenario for an obvious reason (Bow and Axe must be sheathed or dispelled before recasting, and bound sword just places the sword into the casting hand. So I'm skeptical that there is even a solution.) I'm content to leave it as a left handed spell in its final form, but if you know of a solution, I'm all ears.

The second problem I still have is how to dispel the Summon-Shield Spell's corresponding Active Effect from the Active Effect list (the one seen at the bottom of the player's magic inventory). I have an Object Reference Script attached to the shield that governs the OnUnequipped event, and I don't know how to have the Active Effect end or dispel when this event takes place.

The ObjectReference Script Attached to the Shield

Spoiler
 Scriptname ArmorEtherWard01Script extends ObjectReference Armor Property ArmorEtherWard01 AutoEVENT OnUnequipped(Actor akActor)      akActor.removeitem(ArmorEtherWard01, akActor.GetItemCount(ArmorEtherWard01), TRUE)endEVENT 

The ActiveMagicEffect script governing the Spell itself:

Spoiler
 Scriptname MagEtherWard01Script extends ActiveMagicEffect Armor Property ArmorEtherWard01  Auto MagicEffect Property MagEtherWard01  Auto  EVENT OnEffectStart(Actor Target, Actor Caster)      caster.additem(ArmorEtherWard01, 1, TRUE)      caster.equipItem(ArmorEtherWard01, TRUE, TRUE)endEVENT EVENT onLoad()       if !(getCasterActor().hasMagicEffect(MagEtherWard01))         dispel()      endifendEVENT EVENT OnEffectFinish(Actor Target, Actor Caster)       caster.removeitem(ArmorEtherWard01, caster.GetItemCount(ArmorEtherWard01), TRUE)endEVENT 

Both scripts compile, and pull off the effect I want in game superbly; but I'm need to have that active magic effect disappear from the list when it needs to. I'm trying to polish this mod, so I can upload it to Steam.

Another thing I would like to know(but don't necessarily need), is how to have the "Summon Spell" re-equipped to the left hand after the effect wears off; like how the vanilla bound weapons do it. However, this isn't too concerning considering a likely scenario; one where the shield wears off in the middle of a fight and you want to block (if you have a sword out while it wears off, the free hand would allow you to block with the sword instead of the now disappeared shield; going into a casting animation because of reflex could be disasterous).

Thank you for your time.

User avatar
QuinDINGDONGcey
 
Posts: 3369
Joined: Mon Jul 23, 2007 4:11 pm

Post » Wed Jun 26, 2013 9:45 pm

This is what I use for my bound armor.
Scriptname _SoT_BoundArmorScript extends activemagiceffect  Armor Property BoundArmor Autobool AllowDispelEvent OnEffectStart(Actor akTarget, Actor akCaster)    while akTarget.GetItemCount(BoundArmor)        Utility.Wait(0.1) ;wait for armor to be removed and previous magic effect to be dispelled    endWhile    akTarget.AddItem(BoundArmor, absilent = true)    akTarget.EquipItem(BoundArmor, absilent = true) ;can only remove it by equipping something over it    AllowDispel = trueendEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)    if akBaseObject == BoundArmor && AllowDispel        Dispel()    endIfendEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)    akTarget.UnequipItem(BoundArmor, true, true)    akTarget.RemoveItem(BoundArmor, absilent = true)endEvent
You shouldn't need the while loop or the bool, which are both safeguards for dispelling/reapplying the magic effect at the same time. The while loop checks to make sure that the first armor is being removed before applying the second. The bool is there so that the second script doesn't prematurely dispel from removing the armor from the first. Again, you shouldn't need this as you made your spell left hand only (I set up my bound shield this way as well), so there should be no way that you'd have a shield spell activating and dispelling at the same time. No ObjectReference script is needed, as ActiveMagicEffect can recieve Actor events (OnObjectUnequipped). By having this event in your magic effect, you can specifically dispel that effect.

Also, if you want to force the player to re-equip the spell, your script could look like this...

Scriptname _test_Testscript extends ActiveMagicEffect  Armor Property BoundArmor AutoSPELL Property SummonSpell Autobool bPrematureEvent OnEffectStart(Actor akTarget, Actor akCaster)    akTarget.AddItem(BoundArmor, absilent = true)    akTarget.EquipItem(BoundArmor, absilent = true) ;can only remove it by equipping something over itendEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)    if akBaseObject == BoundArmor        bPremature = true        Dispel()    endIfendEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)    akTarget.UnequipItem(BoundArmor, true, true)    akTarget.RemoveItem(BoundArmor, absilent = true)    if !bPremature        akTarget.EquipSpell(SummonSpell, 0) ;0 = left hand    endIf         endEvent
The player would re-equip the spell as long as he didn't dispel the shield by equipping something over it.
User avatar
josh evans
 
Posts: 3471
Joined: Mon Jun 04, 2007 1:37 am


Return to V - Skyrim