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.
| Event Hook Mode | Description |
|---|---|
|
Hook callback fired before the event is fired. |
|
Hook callback fired after the event is fired. |
|
Hook callback fired after event is fired, but event data is not copied. |
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.
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.
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 fields are accessed using the dictionary syntax:
evt['field']
evt['field'] = 'value'
Viper parses the mod’s resource/modevents.res file for every field and type for each game event. That allows Viper to return evt['field'] as the correct type for that field. So if in modevents.res there is a “round_start” event with a field “fraglimit” of type “short”, Viper will return a Python int for evt['fraglimit'].
Since Viper knows the fields each game event has, it can provide length:
len(evt) # The number of fields `evt` has
To iterate over the fields of an event, use the get_fields function to retrieve the fields. Then iterate over the dictionary however you please:
fields = evt.get_fields()
for field in fields.iterkeys():
print "%s: %s" % (field, evt[field])
for field,type in fields.iteritems():
print "%s is of type %s" % (field, type)
Read-only. Whether or not this event will be broadcast to players.
Read-only. The name of this game event.
Cancels this created event.
Fires a created event. If dont_broadcast is True, the event is broadcast to the clients.
Retrieves the fields of a game event as seen in modevents.res. They are returned as a dictionary, with the keys being the field names and the values being their type. For example:
>>> evt.get_fields()
{'player': 'byte', 'quality': 'byte', 'item': 'string', 'method': 'byte', 'propername': 'bool'}
Returns whether or not an event field has an empty value.
Note
This only tells if an event field has a value. This means that if you create an event, none of its fields will have values, and this function will return True for all of them.