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 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 fire_game_event(self, event_name, **kwargs): """Creates and fires an event to this player. :param str event_name: The name of the event to create and fire. :param dict kwargs: The variables to set to the event. """ # Create the event game_event = game_event_manager.create_event(event_name, True) # Set the variables game_event.variables.recursive_copy( KeyValues.from_dict(event_name, kwargs)) # Fire the event self.base_client.fire_game_event(game_event) # Free the event game_event_manager.free_event(game_event)
def _pre_game_event(args): """Call pre-event functions if the event is registered.""" # Get the GameEvent object game_event = make_object(GameEvent, args[1]) # Get the name of the event event_name = game_event.name # If the current event is not in the dictionary, return if event_name not in pre_event_manager: return # Create a variable to know what to do after all pre-events are called event_action = EventAction.CONTINUE # Loop through all callbacks in the pre-event's list for callback in pre_event_manager[event_name]: # Use try/except in case an error occurs during in the callback try: # Call the callback and get its return value current_action = callback(game_event) # Is the return value invalid? if (current_action is not None and not isinstance(current_action, EventAction)): # Raise an error to exit the try raise ValueError( 'Invalid return value for pre-event "{0}".'.format( current_action)) # Was an error encountered? except: # Print the exception to the console except_hooks.print_exception() # Was no error encountered? else: # Does the current action have a higher priority? if current_action is not None and current_action > event_action: # Change the event action event_action = current_action # Does the return value want to set the dontbroadcast value? if event_action is EventAction.STOP_BROADCAST: # Set the dontbroadcast value args[2] = True # Does the return value want to block the event? elif event_action is EventAction.BLOCK: # Free the event game_event_manager.free_event(game_event) # Block the event return False
def _pre_game_event(args): """Call pre-event functions if the event is registered.""" # Crashfix for CS:GO: # https://github.com/Source-Python-Dev-Team/Source.Python/issues/230 game_event_ptr = args[1] if not game_event_ptr: return False # Get the GameEvent object game_event = make_object(GameEvent, game_event_ptr) # Get the name of the event event_name = game_event.name # If the current event is not in the dictionary, return if event_name not in pre_event_manager: return # Create a variable to know what to do after all pre-events are called event_action = EventAction.CONTINUE # Loop through all callbacks in the pre-event's list for callback in pre_event_manager[event_name]: # Use try/except in case an error occurs during in the callback try: # Call the callback and get its return value current_action = callback(game_event) # Is the return value invalid? if (current_action is not None and not isinstance(current_action, EventAction)): # Raise an error to exit the try raise ValueError( 'Invalid return value for pre-event "{0}".'.format( current_action)) # Was an error encountered? except: # Print the exception to the console except_hooks.print_exception() # Was no error encountered? else: # Does the current action have a higher priority? if current_action is not None and current_action > event_action: # Change the event action event_action = current_action # Does the return value want to set the dontbroadcast value? if event_action is EventAction.STOP_BROADCAST: # Set the dontbroadcast value args[2] = True # Does the return value want to block the event? elif event_action is EventAction.BLOCK: # Free the event game_event_manager.free_event(game_event) # Block the event return False