def send_win_message(message='', recipients=None): """Creates and sends the 'cs_win_panel_round' event. Args: message (str): Message to send, supports some HTML tags. recipients: List/tuple of player indexes that should receive the message. """ event = game_event_manager.create_event('cs_win_panel_round') event.set_string('funfact_token', message) # Should the message be sent to everyone on the server? if recipients is None: game_event_manager.fire_event(event) # Or have the recipients been specified? else: for index in recipients: try: # Try to get a Player instance. Player(index).base_client.fire_game_event(event) except ValueError: continue # When firing events to players/clients directly, we need to free it # once we're done with it. game_event_manager.free_event(event)
def on_client_command(command, index): try: userid = userid_from_index(index) except ValueError: # Not sure when this happens... But if it happens, we don't want to # continue. See also: # https://forums.sourcepython.com/viewtopic.php?p=12943#p12943 return CommandReturn.CONTINUE import es if not es.addons.clientCommand(userid): return CommandReturn.BLOCK command_name = command[0] fire_client_command = command_name[0] in cmdprefix_cvar.get_string() if fire_client_command or command_name == 'menuselect': event = game_event_manager.create_event('es_client_command', True) if event is not None: event.set_int('userid', userid) event.set_string('command', command_name) event.set_string('commandstring', command.arg_string) try: game_event_manager.fire_event(event) except RuntimeError: # TODO: # I have no idea why that happens, but the event gets fired... pass else: es.dbgmsg(0, 'es_client_command not fired! =(') return CommandReturn.CONTINUE
def _fake_death(attacker, dominated, headshot, revenge, userid, weapon): event = game_event_manager.create_event('player_death', True) event.set_int('attacker', attacker) event.set_int('dominated', dominated) event.set_bool('headshot', headshot) event.set_int('revenge', revenge) event.set_int('userid', userid) event.set_string('weapon', weapon) game_event_manager.fire_event(event)
def _fake_death(attacker, dominated, headshot, revenge, userid, weapon): event = game_event_manager.create_event('player_death', True) event.set_int('attacker', attacker) event.set_int('dominated', dominated) event.set_bool('headshot', headshot) event.set_int('revenge', revenge) event.set_int('userid', userid) event.set_string('weapon', weapon) game_event_manager.fire_event(event)
def on_client_settings_changed(index): event = game_event_manager.create_event('es_player_setting') if event is None: return client = server.get_client(index - 1) if client is None: return event.set_int('userid', client.userid) game_event_manager.fire_event(event)
def fire(self): """Fire the event with the stored variable values.""" # Get the event's instance event = game_event_manager.create_event(self.name, True) # Loop through the event's variables for variable in self._odict: # Set the event variable values getattr(event, "set_" + self._odict[variable]._method)(variable, getattr(self, "_" + variable)) # Fire the event game_event_manager.fire_event(event)
def fire(self): """Fire the event with the stored variable values.""" # Get the event's instance event = game_event_manager.create_event(self.name, True) # Loop through the event's variables for variable in self._odict: # Set the event variable values getattr(event, 'set_{0}'.format(self._odict[variable].method))( variable, getattr(self, '_' + variable)) # Fire the event game_event_manager.fire_event(event)
def eventscripts_unregister(command): if len(command) < 2: _print_all_registered_cfg_scripts() return import es scriptpack = command[1] event = game_event_manager.create_event('es_scriptpack_unregister', True) event.set_string('scriptpack', scriptpack) game_event_manager.fire_event(event) cfg_scripts[scriptpack] = 0 es.dbgmsg(0, '[EventScripts] Unregistered script pack: {}'.format( command.arg_string))
def on_query_cvar_value_finished(cookie, index, status, cvar_name, cvar_value): event = game_event_manager.create_event('es_player_variable') if event is None: return try: userid = userid_from_index(index) except ValueError: userid = 0 event.set_int('userid', userid) event.set_string('status', QUERY_STATUS.get(status, '')) event.set_string('variable', cvar_name) event.set_string('value', cvar_value) game_event_manager.fire_event(event)
def send_win_message(message='', recipients=None): event = game_event_manager.create_event('cs_win_panel_round') event.set_string('funfact_token', message) if recipients is None: game_event_manager.fire_event(event) else: for index in recipients: try: # Try to get a Player instance. Player(index).base_client.fire_game_event(event) except ValueError: continue game_event_manager.free_event(event)
def eventscripts_register(command): if len(command) < 2: _print_all_registered_cfg_scripts() return import es scriptpack = command[1] cfg_scripts[scriptpack] = 1 es.setinfo('{}_dir'.format(scriptpack), '"{}/{}/"'.format( scriptdir_cvar.get_string(), scriptpack)) es.dbgmsg(0, '[EventScripts] Registered script pack: {}'.format(command.arg_string)) event = game_event_manager.create_event('es_scriptpack_register', True) event.set_string('scriptpack', scriptpack) game_event_manager.fire_event(event)
def on_level_init(map_name): currentmap_cvar.set_string(map_name) if defaultevents_cvar.get_int() != 0: default_event_registration() event = game_event_manager.create_event('es_map_start') if event is not None: event.set_string('mapname', map_name) game_event_manager.fire_event(event) import es es.dbgmsg(3, 'es_map_start fired.') if autorefreshvars_cvar.get_int() > 0: es.refreshpublicvars() muparser.clear_vars() es.dbgmsg(6, ' Reset variables for muParser.')
def fire_es_player_chat(command, userid, team_only): if len(command) <= 1: return event = game_event_manager.create_event('es_player_chat') if event is None: return event.set_int('userid', userid) event.set_bool('teamonly', team_only) full_text = command.arg_string if (userid > 0 and full_text[0] == '"' and full_text[-1] == '"' and full_text.count('"') <= 2): event.set_string('text', full_text[1:-1]) else: event.set_string('text', full_text) game_event_manager.fire_event(event)
def on_client_command(command, index): import es userid = userid_from_index(index) if not es.addons.clientCommand(userid): return CommandReturn.BLOCK command_name = command[0] fire_client_command = command_name[0] in cmdprefix_cvar.get_string() if fire_client_command or command_name == 'menuselect': event = game_event_manager.create_event('es_client_command', True) if event is not None: event.set_int('userid', userid) event.set_string('command', command_name) event.set_string('commandstring', command.arg_string) try: game_event_manager.fire_event(event) except RuntimeError: # TODO: # I have no idea why that happens, but the event gets fired... pass else: es.dbgmsg(0, 'es_client_command not fired! =(') return CommandReturn.CONTINUE
def on_client_command(command, index): import es userid = userid_from_index(index) if not es.addons.clientCommand(userid): return CommandReturn.BLOCK command_name = command[0] fire_client_command = command_name[0] in cmdprefix_cvar.get_string() if fire_client_command or command_name == 'menuselect': event = game_event_manager.create_event('es_client_command', True) if event is not None: event.set_int('userid', userid) event.set_string('command', command_name) event.set_string('commandstring', command.arg_string) try: game_event_manager.fire_event(event) except RuntimeError: # TODO: # I have no idea why that happens, but the event gets fired... pass else: es.dbgmsg(0, 'es_client_command not fired! =(') return CommandReturn.CONTINUE
def on_network_id_validated(name, networkid): event = game_event_manager.create_event('es_player_validated') if event is not None: event.set_string('name', name) event.set_string('networkid', networkid) game_event_manager.fire_event(event)