Observing weapon hits
Example code for observing a weapon hit
Summary
Created: Oct 08 2025 by mana vortex Last documented update: Oct 08 2025 by mana vortex
This page shows a code sample for reacting to hits on NPCs.
OnWeaponHit
// evt: https://nativedb.red4ext.com/gameHitEvent
@wrapMethod(NPCPuppet)
protected cb func OnHit(evt: ref<gameHitEvent>) -> Bool {
wrappedMethod(evt);
// check that the player was the one who hit this npc
// https://nativedb.red4ext.com/AttackData
let instigator: ref<GameObject> = evt.attackData.instigator;
if IsDefined(instigator) && instigator.IsPlayer() {
let record: ref<WeaponItem_Record> = evt.attackData.weapon.m_weaponRecord; // https://nativedb.red4ext.com/gamedataWeaponItem_Record
let id = record.GetID();
FTLog(s"weapon id: \(TDBID.ToStringDEBUG(id))");
if Equals(id, t"Items.your_string_here") {
FTLog(s"yay");
}
}
}IsCritical
IsKill
Last updated