Hoping for some help with OnHit script

Post » Tue Jun 19, 2012 11:59 am

Hi all!

I've been working feverishly on the next update for my Dwemer Artificer mod, and I've hit a weird snag . . .

I can't figure out why this script works perfectly:

Scriptname PDAMActivationScript03 extends ObjectReference{Delete inert automata and spawns friendly ones in thier place}ActorBase Property PDAMSpiderGuardian AutoEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)If akAggressor == Game.GetPlayer()self.PlaceActorAtMe(PDAMSpiderGuardian) ;spawns friendlyself.Delete() ;deletes inertDebug.Notification("Spider Guardian Activated!")EndifEndEvent

But this one doesn't do anything

Scriptname PDAMActivationScript03 extends ObjectReference{Delete inert automata and spawns friendly ones in thier place}ActorBase Property PDAMSpiderGuardian AutoEnchantment  Property PDAMActivationEnch Auto ;a custom staff enchantmentEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)If akSource == PDAMActivationEnchself.PlaceActorAtMe(PDAMSpiderGuardian) ;spawns friendlyself.Delete() ;deletes inertDebug.Notification("Spider Guardian Activated!")EndifEndEvent

The idea is that when the object that this script is attached to gets hit by a particular weapon - in this case, a staff with the PDAMActivationEnch on it - it deletes the object and spawns a creature there. I've also tried using the staff itself for akSource, and that didn't work either. :(

As always, I'd be enormously grateful for any pushes in the right direction. :biggrin:

P

EDIT: Just to clarify, both versions compile just fine, but the version that uses akSource doesn't actually do anything in-game.
User avatar
Cheville Thompson
 
Posts: 3404
Joined: Sun Mar 25, 2007 2:33 pm

Post » Tue Jun 19, 2012 4:34 pm

I'd think you want to check for the staff rather than its enchantment. Since OnHit returns akSource as a Form, you might need to cast it to a variable.

Scriptname PDAMActivationScript03 extends ObjectReference{Delete inert automata and spawns friendly ones in thier place}ActorBase Property PDAMSpiderGuardian AutoWeapon Property YourWeapon AutoWeapon HitCheck ;Temporary variable to store last weapon that hitEvent OnHit (ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)HitCheck = akSource as WeaponIf HitCheck == YourWeaponself.PlaceActorAtMe(PDAMSpiderGuardian) ;spawns friendlyself.Delete() ;deletes inertDebug.Notification("Spider Guardian Activated!")EndifEndEvent
User avatar
Darian Ennels
 
Posts: 3406
Joined: Mon Aug 20, 2007 2:00 pm

Post » Tue Jun 19, 2012 7:12 am

Iiiiinteresting . . . I tried your suggestion with the same result, then changed everything back to the enchantment version, keeping the HitCheck variable and still didn't get anywhere, BUT I did discover something interesting:

Your idea works perfectly if "YourWeapon" is melee, so the problem must have something to do with the fact that the attack is coming from a staff. The wiki entry says:

Also, if this reference is an Actor and the projectile was caused by a weapon enchant, the enchanted weapon will be in akWeapon.

Which brings up three questions: 1) wth is akWeapon!? 2) What if my reference isn't an actor? (it isn't) and 3) Does a staff discharge count as a projectile?

Thanks for the advice! I feel like I'm a step closer now. :)
User avatar
sarah simon-rogaume
 
Posts: 3383
Joined: Thu Mar 15, 2007 4:41 am

Post » Tue Jun 19, 2012 4:24 pm

I don't know much about enchant effects. Does the enchantment on the staff fire a visible(or any) projectile? If so you should be able to check for that projectile with OnHit. You could then copy that projectile, give it a unique name, and use that in the enchant effect. That way if OnHit registers that projectile, it must have been hit by the staff enchant effect.
User avatar
Phoenix Draven
 
Posts: 3443
Joined: Thu Jun 29, 2006 3:50 am

Post » Tue Jun 19, 2012 2:36 am

Brilliant! That did it. Thank you so much!!

I didn't really get the projectile thing - I think I was all hung up on arrows, so I didn't think about the projectile property of the spell that my enchantment was based on. I'll list you in my ever-growing list of "thank you"'s in my mod's credits section. :D
User avatar
Code Affinity
 
Posts: 3325
Joined: Wed Jun 13, 2007 11:11 am

Post » Tue Jun 19, 2012 5:53 pm

Happy to help. Sounds like a neat mod idea.
User avatar
Soraya Davy
 
Posts: 3377
Joined: Sat Aug 05, 2006 10:53 pm


Return to V - Skyrim