events.hooks module

Provides event hooking functionality.

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.