SwiftlyS2
Development

Game Events

Technically, game events are already a deprecated feature in Source 2. Many of the game events are currently not working.

Fire a game event

Example:

Core.GameEvent.Fire<EventShowSurvivalRespawnStatus>(@event => {
  @event.LocToken = "test";
});

This example fires an EventShowSurvivalRespawnStatus event to all players, and sets the LocToken property.

You can also use FireToPlayer to fire an event to a specific player.

The @event param is a temporary object that must not be used outside the configure lambda expression.

Hook a game event

There are two ways to hook a game event:

Core.GameEvent.HookPre<EventShowSurvivalRespawnStatus>(@event => {
  Console.WriteLine("EventShowSurvivalRespawnStatus is fired");
  return HookResult.Continue;
});
[GameEventHandler(HookMode.Pre)]
public HookResult TestGameEventHandler(EventShowSurvivalRespawnStatus @event) {
  Console.WriteLine("EventShowSurvivalRespawnStatus is fired");
  return HookResult.Continue;
}

This example hooks an EventShowSurvivalRespawnStatus event, and prints a message.

You can also use HookPost to hook a game event after it's fired.

The @event param is a temporary object that only exists in the current tick. If you want to use it after the current tick, you need to copy the value to a new object first.

Reference

See GameEventDefinitions for all full list of all game events.

On this page