shaynethecoker Posted July 23, 2013 Share Posted July 23, 2013 Hi all. I am trying to script a simple spell that casts another spell on the player if the target dies during its effect. So far I have: Scriptname CastSpellOnDying extends activemagiceffect Spell property SpellRef auto actor CasterActor Event OnDeath(Actor Killer) Debug.Notification("Ouch!") SpellRef.cast(CasterActor, CasterActor) EndEventWhen I attached this to my spell and kill the target in-game nothing happens, the debug message doesn't even pop up. Can anyone point out where my errors are? Thanks Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 23, 2013 Share Posted July 23, 2013 I think you need to dynamically add a script to your target and run the OnDeath event there. Don't think OnDeath event works from a magic effect script.http://www.creationkit.com/Dynamically_Attaching_Scripts Link to comment Share on other sites More sharing options...
shaynethecoker Posted July 24, 2013 Author Share Posted July 24, 2013 I think you need to dynamically add a script to your target and run the OnDeath event there. Don't think OnDeath event works from a magic effect script.http://www.creationkit.com/Dynamically_Attaching_Scripts This is probably what I'm looking for, thank you. The Soul Tear script from the Dawnguard dlc does use the OnDeath command within the context of an activemagiceffect, which is what I was basing this off of, but I don't think I can use it the way that I hoped. Again thank you for the link, I am new to scripting and I think this page will be very helpful. Couldn't find it when I was looking through the wiki earlier. Link to comment Share on other sites More sharing options...
shaynethecoker Posted July 24, 2013 Author Share Posted July 24, 2013 Scriptname CastSpellOnDying extends activemagiceffect Spell property SpellRef auto Actor Caster Event OnEffectStart(Actor akTarget, Actor akCaster) RegisterForSingleUpdate(0.25) EndEvent Event OnUpdate() RegisterForSingleUpdate(0.25) EndEvent Event OnDying(Actor akKiller) Caster = Game.GetPlayer() Debug.Notification("Ouch!") SpellRef.Cast(Caster, Caster) Debug.Trace("Spell " + SpellRef + "supposedly cast on " + Caster) EndEvent Event OnDeath(Actor akKiller) Self.Dispel() Debug.Trace("Effect suspended, unregistering for update") UnregisterForUpdate() EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) Debug.Trace("Effect suspended, unregistering for update") UnregisterForUpdate() EndEvent This works in-game. Very basic. Working on giving it some conditionals to give it some added utility and bug checking. Link to comment Share on other sites More sharing options...
steve40 Posted July 24, 2013 Share Posted July 24, 2013 a) your OnUpdate event does nothing but waste CPU cycles. It serves no purpose.b) when the magic effect finishes the script will automatically unregister for any updates regardless.c) Magic Effects should automatically dispel on death unless you ticked "no death dispel" on the effect form in the CK. This should work equally well: Scriptname CastSpellOnDying extends activemagiceffect Spell property SpellRef auto Actor Caster Event OnEffectStart(Actor akTarget, Actor akCaster) Caster = akCaster EndEvent Event OnDying(Actor akKiller) Debug.Notification("Ouch!") SpellRef.Cast(Caster, Caster) Debug.Trace("Spell " + SpellRef + "supposedly cast on " + Caster) EndEvent Link to comment Share on other sites More sharing options...
EnaiSiaion Posted July 24, 2013 Share Posted July 24, 2013 You really should tick "no death dispel" even if you do intend it to go away on death (and even if it is an ability). Instead, just put Dispel() into your script. Otherwise you get a race condition and unreliable behaviour. OnDeath() is a fairly bugged event, always use OnDying() instead. Link to comment Share on other sites More sharing options...
shaynethecoker Posted July 24, 2013 Author Share Posted July 24, 2013 (edited) a) your OnUpdate event does nothing but waste CPU cycles. It serves no purpose.b) when the magic effect finishes the script will automatically unregister for any updates regardless.c) Magic Effects should automatically dispel on death unless you ticked "no death dispel" on the effect form in the CK. This should work equally well: Scriptname CastSpellOnDying extends activemagiceffect Spell property SpellRef auto Actor Caster Event OnEffectStart(Actor akTarget, Actor akCaster) Caster = akCaster EndEvent Event OnDying(Actor akKiller) Debug.Notification("Ouch!") SpellRef.Cast(Caster, Caster) Debug.Trace("Spell " + SpellRef + "supposedly cast on " + Caster) EndEvent Thank you. There isn't any updating variable to keep track of, so yes it makes sense that the update cycle is superfluous. I will try using Caster = akCaster again, wasn't working before so I set the value to equal the player just to test that my intended spell effect would work. You really should tick "no death dispel" even if you do intend it to go away on death (and even if it is an ability). Instead, just put Dispel() into your script. Otherwise you get a race condition and unreliable behaviour. OnDeath() is a fairly bugged event, always use OnDying() instead. I do have "no death dispel" ticked since I noticed it was a fairly consistent workaround to bugs in various tutorials. Also, yeah OnDeath() doesn't seem to work at all for this, so OnDying() it is. Edited July 24, 2013 by shaynethecoker Link to comment Share on other sites More sharing options...
Recommended Posts