Difference between revisions of "OnHit - ObjectReference"
m
Some sections of text were improperly flagged as code.
imported>Candoran2 (Seperating discussion of code from code.) |
imported>OpusGlass m (Some sections of text were improperly flagged as code.) |
||
Line 27: | Line 27: | ||
Debug.Trace("We were hit by " + akAggressor) | Debug.Trace("We were hit by " + akAggressor) | ||
EndEvent | EndEvent | ||
</source> | |||
<source lang="papyrus"> | |||
To avoid the hits from enchantments running the code block one must compare the ''akSource'' to the actual reference that hit the actor/object. | To avoid the hits from enchantments running the code block one must compare the ''akSource'' to the actual reference that hit the actor/object. | ||
For instance, say we have a weapon with 2 enchantments called "Fire/Ice Sword." When hit with this sword the hit registers as 3 separate hits, but you have code such as: | For instance, say we have a weapon with 2 enchantments called "Fire/Ice Sword." When hit with this sword the hit registers as 3 separate hits, but you have code such as: | ||
Line 37: | Line 39: | ||
Variable1 -= 100 | Variable1 -= 100 | ||
EndEvent | EndEvent | ||
</source> | |||
This would actually subtract 300 from Variable1 since the event was called 3 times simultaneously, even though the akSource has been cast as a weapon papyrus counts the hit from the enchantments as "weapons" too so the enchantments are reference as (akSource as Weapon) as well. So the solution is to be more explicit. | This would actually subtract 300 from Variable1 since the event was called 3 times simultaneously, even though the akSource has been cast as a weapon papyrus counts the hit from the enchantments as "weapons" too so the enchantments are reference as (akSource as Weapon) as well. So the solution is to be more explicit. | ||
<source lang="papyrus"> | |||
Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \ | Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \ | ||
bool abBashAttack, bool abHitBlocked) | bool abBashAttack, bool abHitBlocked) | ||
Line 73: | Line 77: | ||
EndEvent | EndEvent | ||
</source> | |||
With this code the Actor/Object with the OnHitEvent script could be hit by 5 different weapons but the onhit event will only fire when the weapon has ''TheEnchantment'' and it will only fire once. | With this code the Actor/Object with the OnHitEvent script could be hit by 5 different weapons but the onhit event will only fire when the weapon has ''TheEnchantment'' and it will only fire once. |