Background for Skyrim SE
Member of the ObjectReference script
eventOnHit(ObjectReferenceakAggressor, FormakSource, ProjectileakProjectile, boolabPowerAttack, boolabSneakAttack, boolabBashAttack, boolabHitBlocked)

Description

Wiki Description

Event called when the object reference is hit by a weapon or projectile.

Documentation Comment

Event received when this object is hit by a source (weapon, spell, explosion) or projectile attack


Caveats

CK Wiki - Notes

akSource and akProjectile can be None under various circumstances:

  • This reference is an Actor:

    • akSource can be None if hit by a projectile attack where the projectile was not fired by a weapon or spell
    • akSource can be None if hit by a bash attack from a carried light object (e.g., a torch)
    • akProjectile can be None if hit by a melee attack.
      • In fact, at least in SE, akProjectile appears to always be None if the reference is an Actor, although it does work as expected for some other types, such as Activators.
  • This reference is not an Actor:

    • akSource can be None if hit by a projectile attack where the projectile was not fired by a weapon (for example, a magic spell with a projectile component).
    • akProjectile can be None if hit by a melee attack.

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

  • This event is called multiple times when akSource has associated magic effects. If a sword has an enchantment with 2 effects, OnHit will be called 3 times - once for the physical damage of the sword and once for each magic effect. In all cases, akSource is the sword and not the enchantment. This also applies to spells (one hit for the spell projectile, and one for each associated magic effect).
  • Keep in mind, that akAggressor data is somewhat restricted in this event, and not all functions can be run on it. For instance, you cannot call ObjectReference.GetAnimationVariableBool(...) and its variations on akAggressor.

Parameters

ObjectReferenceakAggressor

CK Wiki Description

The ObjectReference that attacked this reference.

FormakSource

CK Wiki Description

The Weapon, Spell, Explosion, Ingredient, Potion, or Enchantment that hit this reference.

ProjectileakProjectile

CK Wiki Description

The Projectile that hit this reference.

boolabPowerAttack

CK Wiki Description

Was the hit caused by a power attack?

boolabSneakAttack

CK Wiki Description

Was the hit caused by a sneak attack?

boolabBashAttack

CK Wiki Description

Was the hit caused by a bash attack?

boolabHitBlocked

CK Wiki Description

Was the hit blocked?


Examples

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
  bool abBashAttack, bool abHitBlocked)
  Debug.Trace("We were hit by " + akAggressor)
EndEvent

Auto-Generated Example

Scriptname MyCoolScript extends ObjectReference

event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
    Debug.trace("Event received - OnHit: akAggressor = " + akAggressor + " akSource = " + akSource + " akProjectile = " + akProjectile + " abPowerAttack = " + abPowerAttack + " abSneakAttack = " + abSneakAttack + " abBashAttack = " + abBashAttack + " abHitBlocked = " + abHitBlocked)
endEvent

Related Pages


Additional References

View this event’s page on the Skyrim Creation Kit Wiki

Some data provided by the Skyrim Creation Kit Wiki. Licensed under the Creative Commons Attribution-ShareAlike license.