Revolverocelot11 Posted June 21, 2013 Share Posted June 21, 2013 Hi all, I've been trying to create a sword & shield combo at a friends request but after a few days of trying and failing to get this working I've decided to ask for help. The idea for the shield is to reflect weapon damage, spells and "duplicate" enchant damage. I have this scripted, I have that attached to a Magic effect I have created in the Creation Kit. Then I created an enchant and added it to the shield. This is the code I had for the shield: Scriptname ASAbilityReflect Extends ActiveMagicEffect Weapon Property ASWeap05 Auto Enchantment Property ASWeapE05JA Auto Actor Caster Actor Target Int Count Event OnEffecStart (Actor akTarget, Actor akCaster) akTarget = Target akCaster = Caster ;Sets Target and Caster to be used outside of this function. EndEvent Event OnHit(ObjectReference akAgressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) If ((akAgressor as Form).GetType() == 43 || (akAgressor as Form).GetType() == 62) Int Random = Utility.RandomInt() ;Random Chance on hit If (Random == 0) (akAgressor as Actor).Kill(Caster) ;~1% chance to instantly kill the agressor with the caster getting blamed ElseIf (Random >= 1 && Random <= 50) ;50% chance to return the blow back to the agressor If (akSource.GetType() == 41) ;Checks to see if the source is a Weapon Int ReflectAmmount =(akSource as Weapon).GetBaseDamage() * 2 ;Gets the strength of the weapon and doubles it (akAgressor as Actor).DamageAV("Health", ReflectAmmount) ;Deals that damage back ElseIf (akSource.GetType() == 22 || akSource.GetType() == 119) ;Checks to see if the souce was a spell or shout Spell ReCast = (akSource as Spell) ;Sets the spell to be reflected to the spell that was cast If (recast.IsHostile() == True) ;Checks to see if you are about to reflect a hostile spell. If your not then don't reflect it If (Caster != akAgressor) ;Checks to make sure the shield owner didn't cast a spell at himself recast.RemoteCast(Caster, Caster, akAgressor) ;Caster casts the spell, he is responsible for the spell, and it's cast at the aggressor. Even if it fires where the actor is aiming that is ok, and actually ;preferable) Utility.Wait(2.5) ;Wait for the spell to have time to cast Caster.InterruptCast() ;Stop the cast Utility.Wait(1) ;Wait so sound effects finish Else EndIf Else EndIf ElseIf (akSource.GetType() == 21) ;Checks to see if the source is an enchantment. Has yet to be tested BorrowedEnchant = (akSource as Enchantment) ;Sets BorrowedEnchant as the enchant that damaged the player RegisterForSingleUpdate(2) ;registers for update EndIf ;ElseIf (Random >= 51 && Random <= 75) ; Int ReflectAmmount = ASWeap05.GetBaseDamage() ; (akAgressor as Actor).DamageAV("Health", ReflectAmmount) ;ElseIf (Random >= 76 && Random <= 100) ;25% chacne of nothing happening ;Else ; debug.Notification("Something odd happened, Random count exceeded 100 or ws less than 0") EndIf EndIf EndIf EndEvent Event OnUpdate() ASWeap05.SetEnchantment(BorrowedEnchant) ;Sets the weapon's enchant to the borrowed one While (ASWeap05.GetEnchantment() == BorrowedEnchant) ;While the enchant is set to the weapon If(!RegisterForAnimationEvent(Caster, "WeaponLeftSwing") && !RegisterForAnimationEvent(Caster, "WeaponSwing")) ;nothing happens while the caster is not swinging ElseIf(RegisterForAnimationEvent(Caster, "WeaponLeftSwing") || RegisterForAnimationEvent(Caster, "WeaponSwing")) ;As soon as a swing event is registered this block triggers Utility.Wait(1.5) ;waits enough time for the swing to finish ASWeap05.SetEnchantment(ASWeapE05JA) ;returns the original enchant to the weapon EndIf EndWhile EndIf EndEvent I know SOME of the script is working, as the weapon reflect and small chance of instant-kill effects have been tested and working. The Spell reflect is not working at all and I'm not actually sure if the enchant part is working as I have not tested it yet. I should also mention that the reflect damage effect only activates on block (via conditional function on the enchant), which is also working properly. I have tried this as a Perk and passive ability and I always have the same issue. The weapon damage reflect effect and chance at instant death work but the spell reflect does not. I've looked over a couple similar scripts but everything I have tried so far has not worked, so if anyone has any ideas on how to get the spell reflect working I would really appreciate it. And sorry if the code is a bit messy, I'm not that talented at coding. Link to comment Share on other sites More sharing options...
Revolverocelot11 Posted June 24, 2013 Author Share Posted June 24, 2013 Managed to get the reflect to work, not sure what I did but after re-writing it, it seemed to work. Must have been something I overlooked. The enchant does not work (as I expected) but it's not a big deal at this point, I'm not gonna include it. But if anyone has an idea to get it working then feel free to post, I'd love to try it out in a future mod. Link to comment Share on other sites More sharing options...
Recommended Posts