FivePD API
Singletons

EventHandlerDictionary

Injects the same EventHandlerDictionary instance as the one available with the name of EventHandlers when extending the CitizenFX.Core.BaseScript class.

public class Main : BaseScript
{
  private readonly EventHandlerDictionary _eventHandlerDictionary;

  public Main()
  {
    // Obviously assigning it is pointless when you're creating your own resource, it's just an example
    this._eventHandlerDictionary = this.EventHandlers;
  }
}

Usage in an addon:

using CitizenFX.Core;
using FivePD.Server.API;
using FivePD.Server.Interfaces;

namespace MyAwesomeAddon;

public class MyAwesomeExtension : IExtension
{
  private readonly EventHandlerDictionary _eventHandlerDictionary;

  public MyAwesomeExtension(EventHandlerDictionary eventHandlerDictionary)
  {
    this._eventHandlerDictionary = eventHandlerDictionary;
  }

  public Task OnStarted()
  {
    // Registering an event is the same as you'd do in a normal resource
    this._eventHandlerDictionary["myAwesomeServerEvent"] += new Action<string>(this.OnMyAwesomeServerEvent);

    return Task.FromResult(0);
  }

  public Task OnStopped()
  {
    return Task.FromResult(0);
  }

  private void OnMyAwesomeServerEvent(string content)
  {
    // Do something with `content`
  }
}