Jump to content

Weapon Event Handler example needed

Recommended Posts

I'm trying to get an event to trigger when a weapon is fired.
I have added an EventHandlerManagerComponent and then my own scripted component (code below) to a cloned m16 weapon entity.

The "weapontestPOSTINIT", "weapontestEINIT" and "weapontestADDEVENT" are all printed after initialization.
However, when I pick up the weapon and fire it, the event method is not run and "testEVENT" is not printed.

What's wrong with my setup?

class EHJ_WeaponEventComponentClass:ScriptComponentClass

class EHJ_WeaponEventComponent: ScriptComponent
	private EventHandlerManagerComponent m_EventHandlerManagerComponent;
	override protected void OnPostInit(IEntity owner)
		owner.SetFlags(EntityFlags.ACTIVE, true);
		SetEventMask(owner, EntityEvent.ALL);
	override protected void EOnInit(IEntity owner)
		m_EventHandlerManagerComponent = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
		if (m_EventHandlerManagerComponent)
			m_EventHandlerManagerComponent.RegisterScriptHandler("OnAmmoCountChanged", this, this.Event_OnAmmoCountChanged, true);
	void ~EHJ_WeaponEventComponent()
		if (m_EventHandlerManagerComponent)
			m_EventHandlerManagerComponent.RemoveScriptHandler("OnAmmoCountChanged", this, this.Event_OnAmmoCountChanged, true);
	void Event_OnAmmoCountChanged(BaseWeaponComponent currentWeapon, BaseMuzzleComponent currentMuzzle, BaseMagazineComponent magazine, int ammoCount, bool isChambered)


Share this post

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now