events.hooks module

Provides event hooking functionality.

class events.hooks._PreEventManager[source]

Bases: dict

Dictionary class used to store pre-events with their callbacks.

register_for_event(event_name, callback)[source]

Register the callback for the given event.

Parameters:
  • event_name (str) – The name of the event to register.
  • callback – The function to be called when the event is fired on the server.
from events.hooks import pre_event_manager

def function(game_event):
    # Code...

pre_event_manager.register_for_event('player_death', function)

See also

Events for a list of supported events per game.

unregister_for_event(event_name, callback)[source]

Unregister the callback for the given event.

Parameters:
  • event_name (str) – The name of the event to unregister.
  • callback – The function to unregister from the event.
from events.hooks import pre_event_manager

def function(game_event):
    # Code...

pre_event_manager.unregister_for_event('player_death', function)
class events.hooks.EventAction[source]

Bases: enum.IntEnum

Enum class used to know what to do with a pre-hooked event.

Attr:CONTINUE: Allow the event to be fired on the server and transmitted to clients.
Attr:STOP_BROADCAST: Allow the event to be fired on the server but not to be transmitted to clients.
Attr:BLOCK: Stop the event from being fired on the server.
@events.hooks.PreEvent(*event_names)[source]

Bases: core.AutoUnload

Fired when any event in event_names is about to be fired on the server.

Parameters:event_names (str) – An event name or any number of event names to register to the decorated function.

The decorated function is passed the following parameters when an event in event_names is going to be fired on the server:

Parameters:game_event (GameEvent) – The fired event object.
Return type:EventAction

Examples:

from events import PreEvent

@PreEvent('player_death')
def pre_player_died(game_event):
    # Code...
@PreEvent('round_start', 'round_freeze_end')
def some_pre_function(game_event):
    # Code...

    # Stop the event from being fired at all on the server
    return EventAction.BLOCK
@PreEvent('player_team')
def pre_player_team(game_event):
    # Code...

    # Stop the event from being transmitted to clients
    return EventAction.STOP_BROADCAST

See also

Events for a list of supported events per game.

events.hooks.pre_event_manager

The singleton object of the _PreEventManager class.