def wcsx_get_command(command_info, key:str, var:ConVar, userid:valid_userid): if userid is None: var.set_int(-1) return player = getPlayer(userid) if not hasattr(player, key): var.set_int(-1) return value = getattr(player, key) if callable(value): value = value() if hasattr(value, '__iter__'): if hasattr(value[0], '__iter__'): if len(value[0]) == 1: value = value[0][0] else: value = ','.join([str(x) for x in value[0]]) else: value = value[0] var.set_string(str(value))
def wcs_getrandomrace_command(command_info, wcsplayer:convert_userid_to_wcsplayer, var:ConVar): if wcsplayer is None: var.set_int(0) return available_races = list(wcsplayer.available_races) if available_races: var.set_string(choice(available_races)) else: var.set_int(0)
def wcsgroup_get_command(command_info, key:str, var:ConVar, userid:valid_userid_and_team): if userid is None: var.set_int(0) return if isinstance(userid, str): value = team_data[{'T':2, 'CT':3}[userid]].get(key, '0') else: wcsplayer = WCSPlayer.from_userid(userid) value = wcsplayer.data.get(key, '0') var.set_string(str(value))
def wcsgroup_command(command): todo = str(command[1]) if todo == 'get': key = str(command[2]) var = str(command[3]) userid = str(command[4]) if not existsUser(userid): addUser(userid) value = getUser(userid, key) var = ConVar(var) if value is None: var.set_string('0') else: var.set_string(str(value)) elif todo == 'set': key = str(command[2]) userid = str(command[3]) value = str(command[4]) if not existsUser(userid): addUser(userid) setUser(userid, key, value)
def wcs_getinfo_command(command_info, wcsplayer: convert_userid_to_wcsplayer, var: ConVar, attribute: str, key: str): if wcsplayer is None: var.set_int(0) return if key == 'race': if attribute == 'realname': var.set_string(wcsplayer.active_race.name) elif attribute == 'name': var.set_string(wcsplayer.active_race.settings.strings['name']) elif key == 'player': if attribute == 'realcurrace': var.set_string(wcsplayer.active_race.name) elif attribute == 'currace': var.set_string(wcsplayer.active_race.settings.strings['name'])
def wcsx_create_command(command_info, var:ConVar, *args:str): var.set_string(','.join(args))
def wcs_getlanguage_command(command_info, var:ConVar, id_:str, language:str='en'): var.set_string(_languages.get(language, {}).get(id_, 'n/a'))
class _HostnameManager(object): """Class used to set the hostname.""" def __init__(self): """Store the base delay.""" self._convar = ConVar('hostname') self._original_hostname = self._convar.get_string() self.delay = Delay(0.1, self._set_hostname) def reset_hostname(self): """Sets the hostname back to the original value on unload.""" self._convar.set_string(self._original_hostname) def set_hostname(self): """Delay changing the hostname.""" # Is there currently a delay? if self.delay is not None: # Cancel the delay self.delay.cancel() # Delay before setting the hostname self.delay = Delay(0.2, self._set_hostname) def _set_hostname(self): """Set the hostname to show GunGame and Included/Custom Plugins.""" # Set the delay back to None self.delay = None # Set the hostname to the new value self._convar.set_string(self.get_hostname_value()) @staticmethod def get_hostname_value(): """Return the full value of the new hostname.""" # Get the basename value = database['Settings']['base_name'] # Create an empty dictionary plugin_values = dict() # Loop through all plugins in the database for plugin_name, values in database.items(): # Is the plugin loaded? if plugin_name in gg_plugin_manager: if (plugin_name == 'gg_bombing_objective' and not len(EntityIter('func_bomb_target'))): continue if (plugin_name == 'gg_hostage_objective' and not len(EntityIter('func_hostage_rescue'))): continue # Store the plugin's name and priority plugin_values[values['name']] = int(values['priority']) # Are there any plugins that are loaded? if plugin_values: # Add the base_break to the string value += database['Settings']['base_break'] # Sort the loaded plugins by their priority plugins = sorted( plugin_values, key=lambda plugin: plugin_values[plugin], ) # Add all loaded plugins to the string # Separate each with the feature_break value += database['Settings']['feature_break'].join(plugins) return value