Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.61 KB

File metadata and controls

58 lines (40 loc) · 1.61 KB

Events

For custom events see Custom Events.

Event articles

Events can be registered via scripts or dynamically via event delegates. This documentation is registering events via delegates dynamically.

To add for example a player connect event handler dynamically you can just add the delegate that will be called when a player connects.

This is a example using the lambda operator to add a event handler.

Alt.OnPlayerConnect += (player, reason) => {
  Console.WriteLine($"{player.Name} connected.");
};

Its also possible to add a method instead of using a lambda. The method can be private, public, static ect.

Alt.OnPlayerConnect += OnPlayerConnect;
...
public void OnPlayerConnect(IPlayer player, string reason)
{
  Console.WriteLine($"{player.Name} connected.");
}

You should not register event handlers in async code.

Below is a list of all event handlers.

[!code-csharpEvents]

Below is a list of all event handler method signatures.

[!code-csharpEvents]

The player event handler looks like this.

Alt.OnPlayerEvent += (player, name, args) => { 
};

For automated arguments validating you can use Custom Events.