EPHHall Posted February 12, 2017 Share Posted February 12, 2017 (edited) I'm trying to make Invisibility recast itself whenever it is broken (such as when the player activates something, casts a spell, etc.). To do this, I tried using the OnUpdate event; however, after testing the script in game, OnUpdate doesn't seem to be called when it theoretically should. I'm very new to Papyrus, and so any help would be greatly appreciated. Here's my code (I got the basis for it from the creation kit website's page on OnUpdate): Scriptname ChameleonInvisibility extends activemagiceffect Spell Property Invisibility auto function SomeFunction()registerforsingleupdate(5.0)endFunction event onUpdate() Invisibility.cast(game.getplayer(), game.getplayer()) registerForSingleUpdate(5.0)endEvent BTW, I made the code simple so that I could test whether OnUpdate is working. I'm aware that it wouldn't work exactly how I described it in my first sentence, in case anyone wasn't sure. And, of course, if I've left out some information that's potentially important to solving this problem, please let me know and I'll try to fix that. Edited February 12, 2017 by EPHHall Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 12, 2017 Share Posted February 12, 2017 It isn't working because nothing is calling SomeFunction() to run. That SomeFunction on the CK wiki is just an example usage with a bit of psuedo code rather than actual usage. You should try the OnEffectStart event to register for the update. You may want to try the following to achieve what you want. Spell Property Invisibility Auto Actor MyTarget Actor PlayerRef MagicEffect SelfEffect Event OnEffectStart(Actor akTarget, Actor akCaster) If akCaster == Game.GetPlayer() PlayerRef = akCaster RegisterForSingleUpdate(5.0) MyTarget = akTarget SelfEffect = Self as MagicEffect EndIf EndEvent Event OnUpdate() If MyTarget.HasMagicEffect(SelfEffect) RegisterForSingleUpdate(5.0) Else Invisibility.Cast(PlayerRef.MyTarget) Endif EndEvent However, I think that it won't work because the magic effect will be gone when the spell is broken and magic effects automatically unregister for updates when they end or are dispelled. You'll probably need to use a quest with a player alias with a script that uses OnMagicEffectApply to register for the update and then check to see if the player is still under the effect or not. Tho that might trigger with potion use so you may need to work with OnSpellCast and confirm that the player has the effect in place before registering for the update. Another alternative would be to create a repeatable non-start enabled quest. All it would have on it would be a single script which uses the OnInit event to confirm that the player is under the magic effect, if they are register for the update, when they aren't re-cast. The magic effect in turn would have the quest as a property and stops the quest if started then starts the quest anew. And the more I think about it, simply use OnEffectFinish event on the magic effect and re-cast the spell. You will need to store current time in the OnEffectStart event and compare time when the effect ends so that you only re-cast when the spell has been broken rather than constantly re-casting when the spell ends normally. *************************TL;DR Can't use OnUpdate to recast when the effect is gone because the registration is hardcoded to be unregistered upon effect dispel / end. Offered some other possible methods of approach. Link to comment Share on other sites More sharing options...
EPHHall Posted February 12, 2017 Author Share Posted February 12, 2017 Thank you, I'll try your suggestions tomorrow. Link to comment Share on other sites More sharing options...
Masterofnet Posted February 12, 2017 Share Posted February 12, 2017 If you are going to post a script. Please post it like this. Scriptname ChameleonInvisibility extends activemagiceffect Spell Property Invisibility auto function SomeFunction() registerforsingleupdate(5.0) endFunction event onUpdate() Invisibility.cast(game.getplayer(), game.getplayer()) registerForSingleUpdate(5.0) endEvent It is much easier to read. Are you aware you can create an invisibility spell that does not dispel when the player activates something? That may be a better solution for you. Link to comment Share on other sites More sharing options...
lofgren Posted February 12, 2017 Share Posted February 12, 2017 I use this script attached to an invisibility effect in order to recast it when broken: Scriptname DefaultDelayRecast extends activemagiceffect {Waits a certain amount of time after an effect ends, then casts it again.} float property fDelay = 3.0 auto {The amount of time to wait. Default 3.0} spell property SpellToCast auto {The spell to cast.} Event OnEffectFinish(Actor akTarget, Actor akCaster) ; debug.notification("Recast delay triggered!") utility.wait(fDelay) SpellToCast.Cast(akCaster, akTarget) endEvent This will make the invisibility reapply 3 seconds after it is broken. Link to comment Share on other sites More sharing options...
EPHHall Posted February 12, 2017 Author Share Posted February 12, 2017 (edited) If you are going to post a script. Please post it like this. Scriptname ChameleonInvisibility extends activemagiceffect Spell Property Invisibility auto function SomeFunction() registerforsingleupdate(5.0) endFunction event onUpdate() Invisibility.cast(game.getplayer(), game.getplayer()) registerForSingleUpdate(5.0) endEvent It is much easier to read. Are you aware you can create an invisibility spell that does not dispel when the player activates something? That may be a better solution for you.That's basically what i'm trying to do. Do you know how to make an unbreakable invisibility spell, or are you just telling me it's possible? Either way, thanks. Edited February 12, 2017 by EPHHall Link to comment Share on other sites More sharing options...
Masterofnet Posted February 12, 2017 Share Posted February 12, 2017 Yes, Have a look through the Magic effects. I think I found one called constant invisibility and duplicated it. I may have needed to make a few adjustments to it. Link to comment Share on other sites More sharing options...
lofgren Posted February 12, 2017 Share Posted February 12, 2017 If you use a peak value modifier archetype effect instead of an invisibility archetype effect, you can select invisibility for the actor value. Then give it a magnitude of at least 1. This will make the actor invisible to other NPCs without applying the visual effect and without being broken by activating or attacking. Link to comment Share on other sites More sharing options...
Masterofnet Posted February 12, 2017 Share Posted February 12, 2017 If you use a peak value modifier archetype effect instead of an invisibility archetype effect, you can select invisibility for the actor value. Then give it a magnitude of at least 1. This will make the actor invisible to other NPCs without applying the visual effect and without being broken by activating or attacking. Why would anyone do that? The person said very clearly they wanted an invisibility spell that does not break when the player activates something. Link to comment Share on other sites More sharing options...
lofgren Posted February 12, 2017 Share Posted February 12, 2017 ...And that is exactly what I gave them... Link to comment Share on other sites More sharing options...
Recommended Posts