Event Handlers – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Some wiki formatting)
(Add Script Invoker guidelines)
Line 1: Line 1:
{{TOC|side}}
__NOEDITSECTION__{{TOC|side}}
== Script Invokers ==
 
An Event Handler can be created using the {{Link/Enfusion|armaR|ScriptInvoker}} class; it is good practice to '''not''' instanciate them on instance creation but rather create them on request (using its getter):
<enforce>
class TAG_Example
{
protected ScriptInvoker m_OnEvent; // do not create it by default as ScriptInvokers take some RAM (and might be numerous)
 
ScriptInvoker GetOnEvent()
{
if (!m_OnEvent)
m_OnEvent = new ScriptInvoker();
 
return m_OnEvent;
}
 
void Event()
{
if (m_OnEvent) // if it does not exist, do not create it - it simply means no one subscribed to it
m_OnEvent.Invoke();
}
}
</enforce>
 
{{Feature|informative|
For a tutorial on how to use Script Invokers, see {{Link|Arma Reforger:ScriptInvoker Usage|ScriptInvoker Usage}}.<br>
For the proper way to define an event with parameters, see <!-- the {{hl|SCR_ScriptInvokerHelper}} class and e.g {{Link/Enfusion|armaR|ScriptInvokerIntMethod}: -->{{Link|Arma Reforger:ScriptInvoker Usage#Signature Declaration}}.
}}
 
 
== Common Event Handlers ==
== Common Event Handlers ==



Revision as of 19:09, 19 May 2023

Script Invokers

An Event Handler can be created using the ScriptInvoker class; it is good practice to not instanciate them on instance creation but rather create them on request (using its getter):

class TAG_Example { protected ScriptInvoker m_OnEvent; // do not create it by default as ScriptInvokers take some RAM (and might be numerous) ScriptInvoker GetOnEvent() { if (!m_OnEvent) m_OnEvent = new ScriptInvoker(); return m_OnEvent; } void Event() { if (m_OnEvent) // if it does not exist, do not create it - it simply means no one subscribed to it m_OnEvent.Invoke(); } }

For a tutorial on how to use Script Invokers, see ScriptInvoker Usage.
For the proper way to define an event with parameters, see ScriptInvoker Usage - Signature Declaration.


Common Event Handlers

The following table is a list of the most useful events and is not an extensive list of each event handlers.
Class Event Description

OnDestroyed

DamageManagerComponent when default hitzone is set to destroyed

OnADSChanged

CharacterControllerComponent on player character which switches to ADS

OnInspectionModeChanged

on player character which switches in/out of inspection mode

OnMagazineCountChanged

InventoryStorageManagerComponent

OnCompartmentEntered

BaseCompartmentManagerComponent

OnCompartmentLeft

OnAmmoCountChanged

BaseMuzzleComponent Both weapon and character can raise the event (see BaseWeaponManagerComponent)

OnAmmoCountChanged

BaseWeaponManagerComponent Both weapon and character can raise the event (see BaseMuzzleComponent)

OnWeaponChanged

OnMagazineChanged

OnMuzzleChanged

BaseWeaponComponent

OnFiremodeChanged

BaseMuzzleComponent

OnZeroingChanged

BaseSightsComponent currently does not carry currentMuzzle

OnWeaponAttachmentChanged

WeaponComponent isAttached is true if attachmentEntity was attached to the weapon, and false if it was detached.

OnTurretReload

TurretControllerComponent isFinished is true when reload is done and false when it started.


Entity Event Handlers

The following events are present and available in the IEntity class - read the code documentation to learn more about them and how to use them.

E in e.g EOnInit stands for Event (not Entity).
Event Description

EOnInit

Event after the entity is allocated and initialized.

EOnVisible

This event triggers when the entity is made visible (versus being invisible).

EOnFrame

This event, as its name suggests, triggers on each simulation frame.

EOnPostFrame

Triggers after physics update.

EOnFixedFrame

EOnFixedPostFrame

EOnAnimEvent

Event from the animation system

EOnPhysicsActive

Triggers on (de)activation of the RigidBody's physics.

EOnPhysicsMove

Triggers when the physics engine moves this entity.

EOnSimulate

Happens before physics engine iteration - called from sub-iterations.

EOnPostSimulate

Happens after physics engine iteration. Happens once per frame.

EOnJointBreak

Triggers when a joint attached to this entity's RigidBody is broken.

EOnTouch

Event when touched by another entity. It requires the entity to have TouchComponent.

EOnContact

Triggers when contact with another RigidBody has been registered.

EOnDiag

Happens every frame after EOnFrame when "Entity Diag" is enabled in the Diag Menu (e.g Workbench).

EOnUser0

EOnUser1

EOnUser2

EOnUser3

EOnUser4