Event System
Almost all inter-plugin communication is done via the ETS2LA EventBus. This bus provides an interface for plugins to listen to, and emit events between each other, as well as the backend. We're also passing in events from the game into this bus, so that the same API can be used for everything.
How does the events system work?
using ETS2LA.Backend.Events;
// Subscriber can listen to that event via a callback function.
Events.Current.Subscribe<float>("ExampleProvider.CurMicroseconds", OnCurMicroseconds);
// Provider will call .Publish to fire an event to all subscribers.
Events.Current.Publish<float>("ExampleProvider.CurMicroseconds", System.DateTime.Now.Microsecond);
void OnCurMicroseconds(float microseconds)
{
Console.WriteLine($"Current microseconds: {microseconds}");
}
And that's pretty much it. Those two commands are everything you need to get access to all the game telemetry data as well as data from 3rd party plugins. I've compiled a list below of the most commonly used events, but keep in mind that at least ETS2LA's official events have a typed way to get their ID as shown below.
- Telemetry Events : (
ETS2LA.Telemetry.)GameTelemetry.Current.EventString- Publishes:
GameTelemetryData, check it's page for more information.
- Publishes:
- Backend Plugin State Changes : (
ETS2LA.Backend.)Enabled/Disabled- Publishes:
stringthat contains the plugin's name - Alternatively
.Enabled/Disabled.PluginNamefor events specific to a single plugin.
- Publishes:
- Game SDK Updates : (
ETS2LA.SDK.)- Camera Data - Publishes:
CameraDataat.Camera.Data. - Navigation Data - Publishes:
NavigationDataat.Navigation.Data. - Parked Vehicles - Publishes:
ParkedVehicleDataat.ParkedVehicles.Data. - Semaphores - Publishes:
SemaphoreDataat.Semaphores.Data. - Traffic Data - Publishes:
TrafficDataat.Traffic.Data.
- Camera Data - Publishes:
- Game Telemetry Updates : (
ETS2LA.Telemetry.).Data- Publishes:
GameTelemetryData
- Publishes:
- UI Page Changes : (
ETS2LA.UI.).SwitchedPage- Publishes:
stringthat contains the new page's name. - Alternatively
.SwitchedPage.PageNamefor events specific to a single page. - Also
.SwitchedPage.Settings.PageNamefor events specific to a single settings page.
- Publishes:
Ensure that both plugins have access to the same class definitions that are used for events. see the previous page for an example of the problems that you could encounter otherwise!
When calling Events.Publish, all subscribers are handled synchronously. Ensure your subscription functions are simple, as you could be causing slowdowns in other parts of the program otherwise!