CHEventListenerTemplate
Tracking Issue: #4
Tags: events
Allows mods to set up Event Listener classes with specified Deferral and Priority, similar to X2AbilityTrigger_EventListener.
The AddCHEvent
function accepts up to four arguments:
- Name of the Event to listen for.
- EventFn to run when the event is triggered.
- Optional: Deferral (default deferral is ELD_OnStateSubmitted). Visit the r/xcom2mods wiki for info on Deferrals.
- Optional: Priority (default priority is 50). Event listeners with the larger priority number are executed first.
Example use:
class X2EventListener_YourEventListener extends X2EventListener;
static function array<X2DataTemplate> CreateTemplates()
{
local array<X2DataTemplate> Templates;
// You can create any number of Event Listener templates within one X2EventListener class.
Templates.AddItem(CreateListenerTemplate_YourListener());
return Templates;
}
static function CHEventListenerTemplate CreateListenerTemplate_OnBestGearLoadoutApplied()
{
local CHEventListenerTemplate Template;
`CREATE_X2TEMPLATE(class'CHEventListenerTemplate', Template, 'Your_Custom_BestGearApplied_Listener');
// Whether this Listener should be active during tactical missions.
Template.RegisterInTactical = true;
// Whether this Listener should be active on the strategic layer (while on Avenger)
Template.RegisterInStrategy = true;
Template.AddCHEvent('EventName', YourEventFn_Listener, ELD_Immediate, 50);
return Template;
}
static function EventListenerReturn YourEventFn_Listener(Object EventData, Object EventSource, XComGameState NewGameState, Name Event, Object CallbackData)
{
if (GameState.GetContext().InterruptionStatus == eInterruptionStatus_Interrupt)
{
// Perform actions if the event was triggered during interruption stage.
}
else
{
// Perform actions outside interruption stage (after an ability was successfully activated, for example)
}
return ELR_NoInterrupt;
}