Skip to content

Using events

Leaxx edited this page Oct 25, 2024 · 4 revisions

Events are not yet available for Jalopy <= v1.0!

Introduction

Events provide a powerful mechanism for communication between different parts of your mod, other mods, the modloader, or even the game. The EventsManager allows scripts to subscribe to various events and respond accordingly. Let's explore how you can leverage these events to enhance the functionality of your mod.

Available events

Game Events

  • OnMenuLoad: Triggered when the in-game menu is loaded.
  • OnLoadStart: Signifies the start of the game loading process.
  • OnGameLoad: Indicates that the game has finished loading.
  • OnGameUnload: Occurs when the game finishes unloading (player quits to menu)
  • OnSave: Triggered when the game is saved.
  • OnException: Triggered whenever any exception is thrown.

Transaction Events

  • OnTransaction: Occurs when the player commits any transaction.

Travel Events

  • OnRouteGenerated: Fired when a travel route is generated.

Miscellaneous Events

  • OnSettingsLoaded: Triggered when modloader settings are successfully loaded.
  • OnSettingsSaved: Indicates that modloader settings have been saved.
  • OnCustomObjectsRegisterFinished: Occurs after the registration of custom objects is completed.
  • OnUILoadFinished: Fires when the JaLoader UI finishes loading.

Subscribing to Events

You can subscribe to these events by using the += operator, and unsubscribe using -=. For example:

void Start()
{
    EventsManager.Instance.OnTransaction += OnPlayerTransaction; // subscribe to it
}

void AnotherFunction()
{
    EventsManager.Instance.OnTransaction -= OnPlayerTransaction; // unsubscribe from it
}

Clone this wiki locally