Detecting ActiveMagicEffects from RefAlias script?

Post » Thu Aug 15, 2013 1:22 pm

I am implementing a script that responds to various ActiveMagicEffects when they are applied to the player via enchanted items. I have already written a version of the script that can be attached to every individual magic effect, and it achieves the desired results. I am a bit concerned, however, that such a method will be very unfriendly to uninstallation--since the script will be attached to so many individual magic effects, and will likely throw up log errors whenever any of those effects is active.

Assuming that this concern is justified, I would like to make a version of the script that instead can be attached to a single player-filled reference alias, and still respond to all the different effects.

However, I am having trouble finding the necessary functions/events. After looking through ObjectReference, Actor, and ReferenceAlias scripts, the only thing that looks promising is ObjectReference's OnMagicEffectApply()--but this only returns the base MagicEffect, not the specific reference of the ActiveMagicEffect applied to the player, from what I can tell. I need to be able to gain access to ActiveMagicEffect's script functions after detecting a new effect on the player, so that I can manipulate that active effect. Is there any way to use this event (or another method) to detect and respond to ActiveMagicEffects applied to the player, or to somehow detect the active effect?

Or else: would an alternative method of making all the enchantments I want to manipulate use new, custom, magic effects duplicated from the originals work? (I assume all these custom effects along with their scripts would then be removed upon uninstall, when the enchantments revert to using vanilla effects?)

User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Wed Aug 14, 2013 11:21 pm

You're going to get log errors thrown at the user whether you use RefAliases or directly applied Effects. The ideal scenario would be to provide an uninstallation routine for the player in-game that dispels these effects before they uninstall the mod.

But more to your point, things that work on Actors should also work on a ReferenceAlias filled by that Actor. The actor will raise the event to any ReferenceAliases it belongs to. So I can, for instance, use OnObjectEquipped() on a ReferenceAlias filled by the player, where ordinarily I would have no way to capture that event without attaching a script directly to the Player reference (a huge no-no).


Not sure I follow. The "specific reference" of the ActiveMagicEffect? If you have a script tied to a ReferenceAlias, and that ReferenceAlias responds to an OnMagicEffectApply() event, you know:

* Who the effect is on (the ReferenceAlias)
* What the effect is
* Who applied it

And in most circumstances that's all you need to know. ActiveMagicEffects don't usually need a "reference" to them because they are non-transferable; they are essentially a property of the actor they are applied to.
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Thu Aug 15, 2013 4:22 am

Is this helpful?

http://www.creationkit.com/HasMagicEffect_-_Actor
User avatar
Austin Suggs
 
Posts: 3358
Joined: Sun Oct 07, 2007 5:35 pm

Post » Thu Aug 15, 2013 1:05 am

Make a quest, add player as reference alias under "quest aliases", attach a script to player alias and check for "hasmagiceffect".

You can put your effects in a formlist (CE navigaten panel -> miscellenaus -> formlist) and use "OnEffectStart" to scan for new mageiceffects cast on player.

When that event triggers, you can use "Find" from FormList Script to check if the attached effect is in your wanted effect list. Find will return the position as int (formlists are like arrays) or -1 if it's not in it. I Use formlists if I have tons of spells/effects to check for and don't want the scripts with all those data to go into saves directly.

Rule: let scripts do minimum work

You also can use Properties, just Type in Script:

MagicEffect Property my_effect Auto

If you replace my_effect with the name you used for your magic_effect, you can press auto-fill and it will do the clicking for you.

When OnEffectStart trigger, just do if clauses:

if (magiceffect1)

....do stuff

elseif (magiceffect2)

....do stuff

.....

endif

----------------

For Uninstall I use SkyUI to give users a "disable" mod Option, that Options triggers a function in my script which uninstalls all data.

Simply said, you can disable Quest based references using quest.start() and quest.stop()

If you have scripts applied to NPCs you can't access after spell application, think ahead and place an "if check" into all npc scripts to check for a global variable. If that variable is changed (by skyui for example) that npc script could wipe itself.

Tested this the whole day attaching visible lights to npcs + spawn items oninit(). Using Spells with a set duration to apply magiceffects+script and using "registerforsingleupdate" only, will remove the magic effect when player zones - npcs won't shine whe I reenter and my script will be reapplied (multiple items in their inventory). Adding script by Spell set to Ability, it won't unload ever (overkill for save size), they always shine no matter where the player goes - and they only have 1 item.

User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Thu Aug 15, 2013 10:51 am

Thanks everyone for the swift and very thorough replies! I think perhaps I was (incorrectly?) assuming that I wouldn't be able to use ActiveMagicEffect's script functions on a MagicEffect, since they (seem to be) different types. Though, now, a closer look at the wiki reveals that ActiveMagicEffects are "(http://www.creationkit.com/MagicEffect_Script currently attached to an http://www.creationkit.com/Actor_Script)," so maybe they are really the same "thing," so to speak. Will give it a test run though.

Moreover, the idea of simply dispelling all effects before uninstall should have occurred to me--thank you for that Chesko. Perhaps the setup I already have will work then in this case. And re:blacky-, I was hoping to have an uninstall option similar to the one you describe implemented, disabling all active quests related to the mod, I just was worried specifically about the scripts on the magic effects sticking around if I didn't put them somehow into a quest alias.

One related question, while we're discussing uninstallation procedure:

Uninstalling the scripts related to QUESTs and MGEFs seems straightforward to me now. But what about scripts attached to objectReference base objects (i.e. the enchanting table base object). I tested an uninstallation and the script remains on the table. Would it be better to use a quest with a reference alias that fills the "closest" "in loaded area" enchanting table, and just update it every time onLocationChange() to avoid putting the script directly on the table base object? Or is there another way to ensure clean uninstallation?

User avatar
Lucky Boy
 
Posts: 3378
Joined: Wed Jun 06, 2007 6:26 pm


Return to V - Skyrim