Scripting Help with Event OnHit

Post » Wed Sep 11, 2013 12:39 pm

I created a new Actor and gave it an Ability. The Ability consists solely of a MagicEffect with a script attached:

Projectile Property SteelArrowProjectile autoSpell Property SpecialSpell autoActor TargetEvent OnEffectStart(Actor akTarget, Actor akCaster)Target = akTargetendEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)if akProjectile == SteelArrowProjectileSpecialSpell.Cast(Target, Target)endifendEvent

Despite properly setting the properties, the Actor never casts the spell when hit by a Steel Arrow.

Am I doing something wrong?

User avatar
Daddy Cool!
 
Posts: 3381
Joined: Tue Aug 21, 2007 5:34 pm

Post » Wed Sep 11, 2013 8:05 am

I remember having issues with using projectile for checking conditions. Use akSource and check for perhaps HasKeyword WeapTypeArrow for example. Something like that should do it.
User avatar
casey macmillan
 
Posts: 3474
Joined: Fri Feb 09, 2007 7:37 pm

Post » Wed Sep 11, 2013 6:01 am

I actually have tried that to no avail. Thanks, though. The script above is really a test script for me. I figure that if I can get it to work, then I can get my other script to work (which has the same issue), which is much longer, but I can post if necessary.

User avatar
Peter P Canning
 
Posts: 3531
Joined: Tue May 22, 2007 2:44 am

Post » Wed Sep 11, 2013 6:16 am

I assume your script extends activeMagicEffect? If so, and if you've filled all the properties correctly, this should be working. Potential problems include: Target may not be a valid target for the spell, or the projectile may not be registering correctly (either the wrong projectile or onHit is returning NONE for it). Another problem might be, if you added the ability to the actor via the CK, onEffectStart might never fire (not sure about that)--you could try using onInit() instead, register for an update after a second or two, and then identify the person the effect is attached to. What you should probably do is insert some debug.notification()s to let you know whether onHit() is triggering, whether Target==none, and whether the projectile is being recognized. If it's a problem with the projectile, try something like

debug.notification("Just got hit! Projectile == " + akProjectile)

User avatar
^~LIL B0NE5~^
 
Posts: 3449
Joined: Wed Oct 31, 2007 12:38 pm

Post » Wed Sep 11, 2013 7:18 am

Here's the whole larger script:

Scriptname BBVamps_VampireResurrectionScript extends activemagiceffect  float Property ToleranceTime autofloat Property FireWaitTime autofloat Property RegularWaitTime autoKeyword Property WeapMaterialSilver autoKeyword Property DLC1DawnguardItem autoKeyword Property DaedricArtifact autoKeyword Property WeapTypeSword autoKeyword Property MagicDamageFire autoSpell Property DLC1SunFire autoSpell Property DLC1SunFireLeft autoSpell Property DLC1SunCloakDamage autoSpell Property DLC1VampiresBane autoSpell Property BaneoftheUndead autoSpell Property DA09DawnbreakerBaneofUndead autoSpell Property DisintegrationSpell autoSpell Property ResurrectionSpell autoProjectile Property SilverBoltProjectile autoVisualEffect Property RecoveryEffect autoActor Vampirebool NoResurrectionfloat WaitTimeEvent OnEffectStart(Actor akTarget, Actor akCaster)Vampire = akTargetNoResurrection = falseendEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)if akSource.HasKeyword(WeapMaterialSilver) == True ;prevents resurrection when hit with Silver weaponsUnRegisterForUpdate()NoResurrection = true;Debug.Trace("NoResurrection set to true") RegisterForUpdate(ToleranceTime)elseif akSource.HasKeyword(DLC1DawnguardItem) == True ;prevents resurrection when hit with DawnguardWeaponsUnRegisterForUpdate()NoResurrection = true;Debug.Trace("NoResurrection set to true") RegisterForUpdate(ToleranceTime)elseif (akSource.HasKeyword(DaedricArtifact) == True) && (akSource.HasKeyword(WeapTypeSword) == True) ;prevents resurrection when hit with DawnbreakerUnRegisterForUpdate()NoResurrection = true Debug.Trace("NoResurrection set to true")RegisterForUpdate(ToleranceTime)elseif (akSource == DLC1SunFire) || (akSource == DLC1SunFireLeft) ;for Sun Fire SpellUnRegisterForUpdate()NoResurrection = true ;Debug.Trace("NoResurrection set to true")RegisterForUpdate(ToleranceTime)elseif akSource == DLC1SunCloakDamage ;for Stendarrs Aura SpellUnRegisterForUpdate()NoResurrection = true ;Debug.Trace("NoResurrection set to true")RegisterForUpdate(ToleranceTime)elseif akSource == DLC1VampiresBane ;for Vampires Bane SpellUnRegisterForUpdate()NoResurrection = true ;Debug.Trace("NoResurrection set to true")RegisterForUpdate(ToleranceTime);elseif (akSource == BaneoftheUndead) || (akSource == DA09DawnbreakerBaneofUndead) ;for Bane of Undead Spells;not necessary since these spells already have a disintegrate script;UnRegisterForUpdate();NoResurrection = true ;Debug.Trace("NoResurrection set to true");RegisterForUpdate(ToleranceTime)elseif akProjectile == SilverBoltProjectileUnRegisterForUpdate()NoResurrection = true ;Debug.Trace("NoResurrection set to true")RegisterForUpdate(ToleranceTime)else;do nothingendifendEventEvent OnUpdate()NoResurrection = false;Debug.Trace("NoResurrection set to false")endEventEvent OnDying(Actor akKiller)if NoResurrection == trueDisintegrationSpell.Cast(Vampire, Vampire)elseif Vampire.HasMagicEffectWithKeyword(MagicDamageFire)WaitTime = FireWaitTimeRecoveryEffect.Play(Vampire)Utility.Wait(WaitTime)RecoveryEffect.Stop(Vampire)ResurrectionSpell.Cast(Vampire, Vampire)elseWaitTime = RegularWaitTimeRecoveryEffect.Play(Vampire)Utility.Wait(WaitTime)RecoveryEffect.Stop(Vampire)ResurrectionSpell.Cast(Vampire, Vampire)endifendifendEvent
Here's what it does when I have it attached to a MagicEffect that is part of an Ability, that is attached to a Vampire:
When the Vampire is hit by a Silver weapon, Dawnguard weapon, Dawnbreaker, damaging Restoration Spell, etc, it runs an UnregisterForUpdate() line, which is not really important yet since there is no RegisterForUpdate() or RegisterForSingleUpdate() to cancel yet. It also sets the NoResurrection bool to true, and Registers for an Update in 5 seconds (ToleranceTime). If another similar event occurs before that Update, then the UnregisterForUpdate() line cancels the previous RegisterForSingleUpdate(), keeps the NoResurrection true, and Registers for another single update in 5 seconds. If another hit from those sources doesn't occur within the 5 seconds, then the OnUpdate event reverts the NoResurrection bool to false. On dying, if the bool is true, then the Vampire disintegrates; if it is false, then the Vampire will resurrect after WaitTime. Everything works, except for the part with the SilverBolt projectile; it just won't set the bool to true, so the Vampire ends up resurrecting instead of disintegrating. If the script seems correct to you, then I'll try looking for any mistakes I made, but I've spent hours trying to find something wrong and I just can't.
User avatar
Markie Mark
 
Posts: 3420
Joined: Tue Dec 04, 2007 7:24 am

Post » Wed Sep 11, 2013 11:35 am

So, I changed "elseif akProjectile == SilverBoltProjectile" to "elseif akProjectile != SilverBoltProjectile" and added "Debug.Notification("Hit with " + akProjectile)" under that line. Weirdly, I found that the Notification popped up as "Hit with None", which seems really ridiculous to me. Did I miss something when I created the projectile?

User avatar
sam smith
 
Posts: 3386
Joined: Sun Aug 05, 2007 3:55 am

Post » Wed Sep 11, 2013 2:34 pm

That either means the projectile property is set up incorrectly, or, more likely, the onHit event simply isn't registering it. I would give B1gBadDaddy's suggestion a try--check if akSource has WeaponTypeArrow or WeaponTypeBow (I think you may need to use the latter, but not sure). If the onHit() wont tell you the projectile you may need to use a workaround where you check if akAggressor has the silver arrows equipped.

User avatar
Louise Andrew
 
Posts: 3333
Joined: Mon Nov 27, 2006 8:01 am


Return to V - Skyrim