Event Handlers – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Fix link)
(Add HHMMSS, Fix dupe)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Feature|informative|The following table is a list of the most useful events and is not an extensive list of each event handlers.}}
__NOEDITSECTION__
{{TOC|side}}
{{TOC|subtoc|content=
* 1 {{Link|#Script Invokers}}
* 2 {{Link|#Event Handler Manager Component Events}}
* 3 {{Link|#Entity Event Handlers}}
}}
 
 
== Script Invokers ==
 
* An Event Handler can be created using a '''{{Link|enfusion://ScriptEditor/scripts/Game/Helpers/SCR_ScriptInvokerHelper.c|ScriptInvoker}}''' class.
* Any Script Invoker signature can be created using {{hl|{{Link|Arma Reforger:Scripting: Keywords#typedef|typedef}}}} - see {{Link|Arma Reforger:ScriptInvoker Usage#Signature Declaration}}.
* Using the {{Link/Enfusion|armaR|ScriptInvoker}} class itself is considered bad practice and '''must''' be avoided.
* As Script Invokers are big objects and can be numerous, it is good practice to '''not''' instanciate them by default but to rather create them on request, using their getter - saving memory.
 
{{Feature|informative|
See {{Link|Arma Reforger:ScriptInvoker Usage}} and its {{Link|Arma Reforger:ScriptInvoker Usage#Signature Declaration|Signature Declaration}} section for tutorials on how to use Script Invokers.
}}
 
 
== Event Handler Manager Component Events ==
 
The {{Link/Enfusion|armaR|EventHandlerManagerComponent}} groups the following events under its category:


{| class="wikitable sortable"
{| class="wikitable sortable valign="top"
! Event
! Class
! class="unsortable | Description
|-
|-
! System/Component
| style="font-size: 0.8em" |
! Event Name
=== OnADSChanged ===
! Callback Parameters
| rowspan="3" | {{Link/Enfusion|armaR|CharacterControllerComponent}}
! Description
|
|-
|-
| DamagerManagerComponent
| style="font-size: 0.8em" |
| OnDestroyed
=== OnConsciousnessChanged ===
| IEntity owner
|
| when default hitzone is set to destroyed
|-
|-
| CharacterControllerComponent
| style="font-size: 0.8em" |
| OnADSChanged
=== OnInspectionModeChanged ===
| BaseWeaponComponent currentWeapon, bool Value
| on player character which switches in/out of inspection mode
| on player character which switches to ADS
|-
|-
| CharacterControllerComponent
| style="font-size: 0.8em" |
| OnInspectionModeChanged
=== OnMagazineCountChanged ===
| bool newState
| {{Link/Enfusion|armaR|InventoryStorageManagerComponent}}
| on player character which switches in/out of inspection mode
|
|-
| style="font-size: 0.8em" |
=== OnDestroyed ===
| {{Link/Enfusion|armaR|DamageManagerComponent}}
| when the default hit zone is set to destroyed
|-
| style="font-size: 0.8em" |
=== OnCompartmentEntering ===
| rowspan="4" | {{Link/Enfusion|armaR|BaseCompartmentManagerComponent}}
|
|-
| style="font-size: 0.8em" |
=== OnCompartmentEntered ===
|
|-
|-
| InventoryStorageManagerComponent
| style="font-size: 0.8em" |
| OnMagazineCountChanged
=== OnCompartmentLeft ===
| BaseWeaponComponent currentWeapon, int count, bool isGrenade
|
|
|-
|-
| BaseCompartmentManagerComponent
| style="font-size: 0.8em" |
| OnCompartmentEntered
=== OnCompartmentLeaving ===
| IEntity vehicle, BaseCompartmentManagerComponent manager, IEntity occupant, int managerID, int slotID
|
|
|-
|-
| BaseCompartmentManagerComponent
| style="font-size: 0.8em" |
| OnCompartmentLeft
=== OnLightStateChanged ===
| IEntity vehicle, BaseCompartmentManagerComponent manager, IEntity occupant, int managerID, int slotID
| {{Link/Enfusion|armaR|BaseLightManagerComponent}}
|
|
|-
|-
| BaseMuzzleComponent<br>BaseWeaponManagerComponent
| style="font-size: 0.8em" |
| OnAmmoCountChanged
=== OnTurretReload ===
| BaseWeaponComponent currentWeapon, BaseMuzzleComponent currentMuzzle, BaseMagazineComponent magazine, int ammoCount, bool isChambered
| rowspan="2" | {{Link/Enfusion|armaR|TurretControllerComponent}}
| Both weapon and character can raise the event
| {{hl|isFinished}} is true when reload is done and false when it started
|-
|-
| BaseWeaponManagerComponent
| style="font-size: 0.8em" |
| OnWeaponChanged
=== OnADSChanged ===
| BaseWeaponComponent currentWeapon, BaseWeaponComponent oldWeapon
| on player character which switches to ADS<br>{{Link/Enfusion|armaR|TurretControllerComponent}} can also trigger this event
|-
| style="font-size: 0.8em" |
=== OnWeaponChanged ===
| {{Link/Enfusion|armaR|BaseWeaponManagerComponent}}
|
|
|-
|-
| BaseWeaponManagerComponent
| style="font-size: 0.8em" |
| OnMagazineChanged
=== OnMuzzleChanged ===
| BaseWeaponComponent weapon, BaseMagazineComponent newMagazine, BaseMagazineComponent oldMagazine
| {{Link/Enfusion|armaR|BaseWeaponComponent}}
|
|
|-
|-
| BaseWeaponComponent
| style="font-size: 0.8em" |
| OnMuzzleChanged
=== OnAmmoCountChanged ===
| BaseWeaponComponent weapon, BaseMuzzleComponent newMuzzle, BaseMuzzleComponent oldMuzzle
| rowspan="4" | {{Link/Enfusion|armaR|BaseMuzzleComponent}}
| Both weapon and character can raise this event (see {{hl|BaseWeaponManagerComponent}})
|-
| style="font-size: 0.8em" |
=== OnMagazineChanged ===
|
|
|-
|-
| BaseMuzzleComponent
| style="font-size: 0.8em" |
| OnFiremodeChanged
=== OnProjectileShot ===
| BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, int newFiremode
|
|
|-
|-
| BaseSightsComponent
| style="font-size: 0.8em" |
| OnZeroingChanged
=== OnFiremodeChanged ===
| BaseWeaponComponent weapon, int range
|
|-
| style="font-size: 0.8em" |
=== OnWeaponAttachmentChanged ===
| rowspan="2" | {{Link/Enfusion|armaR|WeaponComponent}}
| {{hl|isAttached}} is true if {{hl|attachmentEntity}} was attached to the weapon, and false if it was detached
|-
| style="font-size: 0.8em" |
=== OnZeroingChanged ===
| currently does not carry currentMuzzle
| currently does not carry currentMuzzle
|-
|-
| WeaponComponent
| style="font-size: 0.8em" |
| OnWeaponAttachmentChanged
=== OnGrenadeThrown ===
| WeaponComponent weapon, bool isAttached, IEntity attachmentEntity
| {{Link/Enfusion|armaR|WeaponSlotComponent}}
| isAttached is true if attachmentEntity was attached to the weapon, and false if it was detached.
|
|-
| style="font-size: 0.8em" |
=== HHMMSS ===
| rowspan="3" | {{Link/Enfusion|armaR|TimeAndWeatherManagerEntity}}
| Triggers based on {{Link/Enfusion|armaR|TimeAndWeatherManagerEntity}}'s {{hl|TIME_EVENT_PERIODICITY}} value:
* 0: never
* 1: every hour
* 2: every minute
* 3: every second
|-
|-
| TurretControllerComponent
| style="font-size: 0.8em" |
| OnTurretReload
=== OnDayStart ===
| BaseWeaponComponent weapon, bool isFinished, TurretControllerComponent turretController
|
| isFinished is true when reload is done and false when it started.
|-
| style="font-size: 0.8em" |
=== OnNightStart ===
|
|}
|}




{{TOC|side}}
== Entity Event Handlers ==
== Entity Event Handlers ==


{{Feature|informative|See also {{Link|Arma Reforger:Entity Lifecycle}}.}}
The following events are present and available in the '''{{Link/Enfusion|armaR|IEntity}}''' class - read the code documentation to learn more about them and how to use them.
{{Feature|informative|'''E''' in e.g '''E'''OnInit stands for Event (not Entity).}}
{{Feature|informative|'''E''' in e.g '''E'''OnInit stands for Event (not Entity).}}


{| class="wikitable sortable valign-top"
! Event
! class="unsortable" | Description
|-
| style="font-size: 0.8em" |
=== EOnInit ===
=== EOnInit ===
 
| Event after the entity is allocated and initialised.
Event after the entity is allocated and initialized.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity
 
=== EOnVisible ===
=== EOnVisible ===
 
| This event triggers when the entity is made visible (versus being invisible).
This event triggers when the entity is made visible (versus being invisible).
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* int frameNumber:
 
=== EOnFrame ===
=== EOnFrame ===
 
| This event, as its name suggests, triggers on each simulation frame.
This event, as its name suggests, triggers on each simulation frame.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity
* float timeSlice: time spent since the last frame, in seconds
 
=== EOnPostFrame ===
=== EOnPostFrame ===
 
| Triggers after physics update.
Triggers after physics update.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* float timeSlice:
 
=== EOnFixedFrame ===
=== EOnFixedFrame ===
 
| {{Feature|warning|This event can be called on another thread than the main thread. This means that you must avoid any modifications on other entities during this event!}}
* IEntity owner: the entity itself
|-
* float timeSlice:  
| style="font-size: 0.8em" |
 
=== EOnFixedPostFrame ===
=== EOnFixedPostFrame ===
 
|
* IEntity owner: the entity itself
|-
* float timeSlice:  
| style="font-size: 0.8em" |
 
=== EOnAnimEvent ===
=== EOnAnimEvent ===
 
| Event from the animation system
Event from the animation system
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* int type:  
* int slot:
 
=== EOnPhysicsActive ===
=== EOnPhysicsActive ===
 
| Triggers on (de)activation of the {{hl|RigidBody}}'s physics.
Triggers on (de)activation of the {{hl|RigidBody}}'s physics.
|-
* IEntity owner: the entity itself
| style="font-size: 0.8em" |
* bool activeState:  
 
=== EOnPhysicsMove ===
=== EOnPhysicsMove ===
 
| Triggers when the physics engine moves this entity.
Triggers when the physics engine moves this entity. {{Wiki|TODO}}
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
 
=== EOnSimulate ===
=== EOnSimulate ===
 
| Happens before physics engine iteration - called from sub-iterations.
Happens before physics engine iteration - called from sub-iterations. {{Wiki|TODO}}
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* float timeSlice:
 
=== EOnPostSimulate ===
=== EOnPostSimulate ===
| Happens after physics engine iteration. Happens once per frame.


Happens after physics engine iteration. Happens once per frame.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* float timeSlice:
 
=== EOnJointBreak ===
=== EOnJointBreak ===
 
| Triggers when a joint attached to this entity's {{hl|RigidBody}} is broken.
Triggers when a joint attached to this entity's {{hl|RigidBody}} is broken.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* IEntity other: the other entity
 
=== EOnTouch ===
=== EOnTouch ===
 
| Event when touched by another entity. It requires the entity to have {{hl|TouchComponent}}.
Event when touched by another entity. It requires the entity to have {{hl|TouchComponent}}. {{Wiki|TODO}}
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* IEntity other: the touched entity
* int touchTypesMask: unused as of {{armaR}} 0.9.5
 
=== EOnContact ===
=== EOnContact ===
 
| Triggers when contact with another {{hl|RigidBody}} has been registered.
Triggers when contact with another {{hl|RigidBody}} has been registered.
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* IEntity other: the other entity
* Contact contact:
 
=== EOnDiag ===
=== EOnDiag ===
 
| Happens every frame after {{Link|#EOnFrame}} when "Entity Diag" is enabled in the [[Arma Reforger:Diag Menu|Diag Menu]] (e.g {{GameCategory|armaR|Modding|Official Tools|text= Workbench}}).
Happens every frame after {{Link|#EOnFrame}} when "Entity Diag" is enabled in the [[Arma Reforger:Diag Menu|Diag Menu]] (e.g [[Arma Reforger:Workbench|Workbench]]).
|-
 
| style="font-size: 0.8em" |
* IEntity owner: the entity itself
* float timeSlice:
 
=== EOnUser0 ===
=== EOnUser0 ===
 
|
* IEntity other:
|-
* int extra:  
| style="font-size: 0.8em" |
 
=== EOnUser1 ===
=== EOnUser1 ===
 
|
* IEntity other:
|-
* int extra:  
| style="font-size: 0.8em" |
 
=== EOnUser2 ===
=== EOnUser2 ===
 
|
* IEntity other:
|-
* int extra:  
| style="font-size: 0.8em" |
 
=== EOnUser3 ===
=== EOnUser3 ===
 
|
* IEntity other:
|-
* int extra:  
| style="font-size: 0.8em" |
 
=== EOnUser4 ===
=== EOnUser4 ===
 
|
* IEntity other:
|}
* int extra:




{{GameCategory|armaR|Modding|Guidelines|Scripting}}
{{GameCategory|armaR|Modding|Guidelines|Scripting}}

Latest revision as of 12:54, 2 September 2024


Script Invokers

  • An Event Handler can be created using a ScriptInvoker class.
  • Any Script Invoker signature can be created using typedef - see ScriptInvoker Usage - Signature Declaration.
  • Using the ScriptInvoker class itself is considered bad practice and must be avoided.
  • As Script Invokers are big objects and can be numerous, it is good practice to not instanciate them by default but to rather create them on request, using their getter - saving memory.
See ScriptInvoker Usage and its Signature Declaration section for tutorials on how to use Script Invokers.


Event Handler Manager Component Events

The EventHandlerManagerComponent groups the following events under its category:

Event Class Description

OnADSChanged

CharacterControllerComponent

OnConsciousnessChanged

OnInspectionModeChanged

on player character which switches in/out of inspection mode

OnMagazineCountChanged

InventoryStorageManagerComponent

OnDestroyed

DamageManagerComponent when the default hit zone is set to destroyed

OnCompartmentEntering

BaseCompartmentManagerComponent

OnCompartmentEntered

OnCompartmentLeft

OnCompartmentLeaving

OnLightStateChanged

BaseLightManagerComponent

OnTurretReload

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

OnADSChanged

on player character which switches to ADS
TurretControllerComponent can also trigger this event

OnWeaponChanged

BaseWeaponManagerComponent

OnMuzzleChanged

BaseWeaponComponent

OnAmmoCountChanged

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

OnMagazineChanged

OnProjectileShot

OnFiremodeChanged

OnWeaponAttachmentChanged

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

OnZeroingChanged

currently does not carry currentMuzzle

OnGrenadeThrown

WeaponSlotComponent

HHMMSS

TimeAndWeatherManagerEntity Triggers based on TimeAndWeatherManagerEntity's TIME_EVENT_PERIODICITY value:
  • 0: never
  • 1: every hour
  • 2: every minute
  • 3: every second

OnDayStart

OnNightStart


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 initialised.

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

This event can be called on another thread than the main thread. This means that you must avoid any modifications on other entities during this event!

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