sourcemod.events — Game Events

The Source Engine defines events that are fired when certain things happen. For example, the event player_shoot is fired when a player fires their weapon in Counter-Strike: Source.

Module Contents

Event Hook Mode Description
sourcemod.events.EventHookMode_Pre
Hook callback fired before the event is fired.
sourcemod.events.EventHookMode_Post
Hook callback fired after the event is fired.
sourcemod.events.EventHookMode_PostNoCopy
Hook callback fired after event is fired, but event data is not copied.
sourcemod.events.create(name[, force=False])

Creates a game event. If force is True, it forces the event to be created even if it’s not being hooked. Note that this will not force the event to be created if the event doesn’t exist at all.

Returns an Event object that represents the game event created, or None if the event does not exist.

sourcemod.events.hook(event, callback[, mode=EventHookMode_Post])

Hooks a game event. This raises a ViperError if the game event does not exist. mode expects an EventHookMode constant.

callback should be a callable that accepts two arguments: an event object, and the event name as a string – in that order.

sourcemod.events.unhook(event, callback[, mode=EventHookMode_Post])
Unhooks the specified callback from a game event. Raises a ViperError if the specified event does not exist or the callback was invalid. mode expects an EventHookMode constant.

Event Objects

Note

There is no way to determine what fields are available in a game event, or the type of a field, which is why this class contains so many inconvenient methods.

Event.dont_broadcast
Read-only. Whether or not this event will be broadcast to players.
Event.name
Read-only. The name of this game event.
Event.cancel()
Cancels this created event.
Event.fire([dont_broadcast=False])
Fires a created event. If dont_broadcast is True, the event is broadcast to the clients.
Event.get_bool(field)
Event.get_float(field)
Event.get_int(field)
Event.get_string(field)

Retrieves a value from a game event.

Note

These will ALWAYS return a value, even if the field does not exist. Use has_field to make sure the field exists.

Event.has_field(field)
Returns whether or not a field exists on a game event.
Event.set_bool(field, value)
Event.set_float(field, value)
Event.set_int(field, value)
Event.set_string(field, value)
Sets a value in a game event.

Table Of Contents

Previous topic

sourcemod.entity — Entity manipulation.

Next topic

sourcemod.forwards — Collections of Callbacks

This Page