Background for Fallout 4
Member of the ScriptObject script
voidfunctionRegisterForHitEvent(ScriptObjectakTarget, ScriptObjectakAggressorFilter=NONE, FormakSourceFilter=NONE, FormakProjectileFilter=NONE, intaiPowerFilter=-1, intaiSneakFilter=-1, intaiBashFilter=-1, intaiBlockFilter=-1, boolabMatch=true)Native

Description

Wiki Description

Registers this script to receive a single OnHit event matching the filters given to this function.

Only the script that registers for an event will receive it. Other scripts attached to the same form, alias, or magic effect will not receive the event unless they also register for it.

Documentation Comment

Registers for a single hit event. Filters may be exact forms, base objects of references, keywords, factions, reference aliases,
ref collection aliases, or form lists containing any or all of them. This also filters any remote hit events that come in.
The power/sneak/bash/block filters are -1 for no filter, 0 (or false) for false only, and 1 (or true) for true only.
Targets can be references, ref aliases, or ref collection aliases
If abMatch is false, then it matches anything that DOESN'T match the filter (NOTs the whole thing).
Objects without registrations CANNOT receive hit events!


Caveats

CK Wiki - Notes

  • Registration is removed after the first matching hit. You have to re-register to get another hit.
  • Aliases and quests will automatically unregister for this event when the quest stops. Active magic effects will automatically unregister when they are removed.
  • You can be registered for as many different hit events as you like, but if a hit arrives that matches multiple filters it is undefined which filter will be removed from the list.

Parameters

  1. ScriptObjectakTarget

    CK Wiki Description

  2. ScriptObjectakAggressorFilter=NONE

    CK Wiki Description

    The filter to use for the aggressor.

    • Default:None
    • Reference or actor:Exact match
    • Base object:Base object match
    • Keyword:Keyword match
    • Faction:Actor in faction match
    • Form list:Containing any of the above (not recursed into)
    • Reference alias:Filling this alias
    • Ref collection alias:Filling this alias
    • None:Anything
  3. FormakSourceFilter=NONE

    CK Wiki Description

    The filter to use for the source of the hit (weapon usually)

    • Default:None
    • Base object:Base object match (weapon, explosion, spell, ingredient, potion, enchantment)
    • Keyword:Keyword match
    • Form list:Containing any of the above (not recursed into)
    • None:Anything
  4. FormakProjectileFilter=NONE

    CK Wiki Description

    The filter to use for the projectile involved in the hit

    • Default:None
    • Projectile base object:Base object match
    • Keyword:Keyword match
    • Form list:Containing any of the above (not recursed into)
    • None:Anything
  5. intaiPowerFilter=-1

    CK Wiki Description

    Filter for a power attack

    • Default:-1
    • If 0, then it must NOT be a power attack
    • If >0, then it MUST be a power attack
    • If <0, then it matches both
  6. intaiSneakFilter=-1

    CK Wiki Description

    Filter for a sneak attack

    • Default:-1
    • See power filter for values
  7. intaiBashFilter=-1

    CK Wiki Description

    Filter for a bash attack

    • Default:-1
    • See power filter for values
  8. intaiBlockFilter=-1

    CK Wiki Description

    Filter for a blocked attack

    • Default:-1
    • See power filter for values
  9. boolabMatch=true

    CK Wiki Description

    If true, the filter must match the hit - if false, the filter must NOT match the hit (inverted filter)

    • Default:true

Examples

; Register for when the player is hit by anything
RegisterForHitEvent(Game.GetPlayer())
; Register for when we are hit by anything OTHER then our companion alias
RegisterForHitEvent(self, CompanionAlias, abMatch = false)

Auto-Generated Example

ScriptObject myScriptObject__akTarget
ScriptObject myScriptObject__akAggressorFilter
Form myForm__akSourceFilter
Form myForm__akProjectileFilter
int myInt__aiPowerFilter
int myInt__aiSneakFilter
int myInt__aiBashFilter
int myInt__aiBlockFilter
bool myBool__abMatch

myScriptObject__toCallFunctionOn.RegisterForHitEvent(myScriptObject__akTarget, myScriptObject__akAggressorFilter, myForm__akSourceFilter, myForm__akProjectileFilter, myInt__aiPowerFilter, myInt__aiSneakFilter, myInt__aiBashFilter, myInt__aiBlockFilter, myBool__abMatch)

Related Pages


Additional References

View this function’s page on the Fallout 4 Creation Kit Wiki

Some data provided by the Fallout 4 Creation Kit Wiki. Licensed under the Creative Commons Attribution-Share Alike 4.0 license.