def index_from_steamid(steamid): """Return an index from the given SteamID.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's SteamID the same as the one given? if playerinfo.get_networkid_string() == steamid: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching SteamID, raise an error raise ValueError('Invalid SteamID "{0}"'.format(steamid))
def index_from_name(name): """Return an index from the given player name.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's name the same as the one given? if playerinfo.get_name() == name: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching name, raise an error raise ValueError('Invalid name "{0}"'.format(name))
def index_from_uniqueid(uniqueid): """Return an index from the given UniqueID.""" # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's UniqueID the same as the one given? if uniqueid_from_playerinfo(playerinfo) == uniqueid: # Return the index of the current player return index_from_playerinfo(playerinfo) # If no player found with a matching UniqueID, raise an error raise ValueError('Invalid UniqueID "{0}"'.format(uniqueid))
def index_from_steamid(steamid): """Return an index from the given SteamID. :param str steamid: The SteamID to get the index of. :rtype: int """ # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's SteamID the same as the one given? if playerinfo.steamid == steamid: # Return the index of the current player return index_from_playerinfo(playerinfo) raise ValueError( 'Conversion from "SteamID" ({}) to "Index" failed.'.format(steamid))
def index_from_name(name): """Return an index from the given player name. :param str name: The player name to get the index of. :rtype: int """ # Loop through all players on the server for edict in PlayerGenerator(): # Get the PlayerInfo instance of the player... playerinfo = playerinfo_from_edict(edict) # Is the current player's name the same as the one given? if playerinfo.name == name: # Return the index of the current player return index_from_playerinfo(playerinfo) raise ValueError( 'Conversion from "Name" ({}) to "Index" failed.'.format(name))