def wcs_amount_select(menu, index, choice): if choice.value == 'spendlevels': userid = userid_from_index(index) amount = int(choice.text) mxlvl = maxlevel.get_int() if bankplayer[userid].levels >= amount: if int(wcs.wcs.wcsplayers[userid].all_races[ wcs.wcs.wcsplayers[userid].currace]['level'] + amount) > int(mxlvl): amount = int(mxlvl) - int(wcs.wcs.wcsplayers[userid].all_races[ wcs.wcs.wcsplayers[userid].currace]['level']) wcs.wcs.wcsplayers[userid].give_level(amount) bankplayer[userid].levels -= amount wcs.wcs.tell( userid_from_index(index), '\x04[WCS] \x05You got \x04%s Levels \x05left in your \x04Bank!' % bankplayer[userid].levels) bankplayer[userid].save() else: wcs.wcs.tell( userid_from_index(index), "\x04[WCS] \x05You don't have enough \x04levels \x05in your \x04bank!" ) menu.send(index) else: userid = choice.value.userid amount = int(choice.text) player = Player(index) bankplayer[userid].levels += amount wcs.wcs.tell( userid, '\x04[WCS] \x05You got \x04%s Bank-Levels \x05from admin \x04%s!' % (amount, player.name)) bankplayer[userid].save()
def wcsadmin_github_items_options_menu_select(menu, client, option): wcsplayer = Player(client) if isinstance(option.value, GithubModuleStatus): wcsplayer.data['_internal_wcsadmin_github_cycle'] = 0 name = wcsplayer.data['_internal_wcsadmin_github_name'] if option.value is GithubModuleStatus.INSTALLING: if len(github_manager['items'][name]['repositories']) > 1: return wcsadmin_github_items_repository_menu else: github_installing_message.send(client, name=name) github_manager.install_module(list(github_manager['items'][name]['repositories'])[0], 'items', name, userid_from_index(client)) elif option.value is GithubModuleStatus.UPDATING: github_updating_message.send(client, name=name) github_manager.update_module('items', name, userid_from_index(client)) else: github_uninstalling_message.send(client, name=name) github_manager.uninstall_module('items', name, userid_from_index(client)) elif isinstance(option.value, SimpleMenu): return option.value return menu
def wcsadmin_github_options_menu_select(menu, client, option): wcsplayer = Player.from_index(client) if option.choice_index == BUTTON_BACK: if wcsplayer.data['_internal_wcsadmin_github_module']: return wcsadmin_github_races_menu else: return wcsadmin_github_items_menu elif isinstance(option.value, GithubStatus): wcsplayer.data['_internal_wcsadmin_github_cycle'] = 0 module = 'races' if wcsplayer.data['_internal_wcsadmin_github_module'] else 'items' name = wcsplayer.data['_internal_wcsadmin_github_name'] if option.value is GithubStatus.INSTALLING: github_installing_message.send(client, name=name) github_manager.install(module, name, userid_from_index(client)) elif option.value is GithubStatus.UPDATING: github_updating_message.send(client, name=name) github_manager.update(module, name, userid_from_index(client)) else: github_uninstalling_message.send(client, name=name) github_manager.uninstall(module, name, userid_from_index(client)) return menu
def __call__(self, command, index=None, team_only=None): command_info.set_args(command) if index is not None: command_info.userid = userid_from_index(index) import es es.addons.callBlock(self.block_name)
def raceinfo_menu_build(menu, index): menu.clear() races = wcs.wcs.racedb.getAll() userid = userid_from_index(index) player_entity = Player(index) allraces = races.keys() for number, race in enumerate(allraces): if race in wcs.wcs.wcsplayers[userid].all_races: level = wcs.wcs.wcsplayers[userid].all_races[race]['level'] else: level = 0 raceinfo = wcs.wcs.racedb.getRace(race) nol = raceinfo['numberoflevels'] nos = int(raceinfo['numberofskills']) if ('|') in nol: nol = nol.split('|') if len(nol) == 1: max_level = int(nol) * nos else: max_level = 0 for x in nol: max_level += int(x) level_buffer = level max_level = int(max_level) if level_buffer > max_level: level_buffer = max_level if level: option = PagedOption('%s - [%s/%s]' % (race, level, max_level), race) else: option = PagedOption('%s' % str(race), race) menu.append(option)
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 __call__(self, command, index=None, team_only=None): command_info.set_args(command) if index is not None: command_info.userid = userid_from_index(index) import es es.addons.callBlock(self.block_name)
def _join_class(command, index): Delay( delay=2, callback=_respawn_player, args=(userid_from_index(index),), cancel_on_level_end=True, )
def _on_spend_skills_select(menu, index, choice): player = players[userid_from_index(index)] skill = choice.value if player.hero.unused_points( player.hero.level) and skill.level < skill.max_level: skill.give_levels(1) return menu
def __init__(self, uniqueid): self._uniqueid = uniqueid self._races = _RaceContainer(self) self._items = _ItemContainer(self) self._userid = None self._index = None self._player = None self._ready = False self._is_bot = uniqueid.startswith('BOT_') self._privileges = privileges['players'].get(uniqueid, {}) self._id = None self._name = None self._current_race = None self._lastconnect = None self.data = {} try: self._index = index_from_uniqueid(uniqueid) except ValueError: name = None else: self._userid = userid_from_index(self._index) Player._cache_userids[self.userid] = self Player._cache_indexes[self.index] = self name = playerinfo_from_index(self.index).name if not _thread.unloading: database_manager.execute('player get', (uniqueid, ), callback=self._query_get_player, name=name)
def shopinfo_menu_subcats_select(menu, index, choice): userid = userid_from_index(index) item = choice.value iteminfo = wcs.wcs.itemdb.getItem(item) desc = iteminfo['desc'] cost = int(iteminfo['cost']) required = int(iteminfo['level']) required_status = int(iteminfo['dab']) if required_status == 1: required_status = '<alive>' if required_status == 0: required_status = '<dead>' if required_status == 2: required_status = '<always>' duration = int(iteminfo['duration']) if duration == 1: duration = '<Until death>' if duration == 0: duration = '<One round>' maximum = int(iteminfo['max']) shopinfo_race_menu = PagedMenu(title='%s' % iteminfo['name'], parent_menu=menu) shopinfo_race_menu.append(Text('o %s' % desc)) shopinfo_race_menu.append(Text('Required level: %s' % required)) shopinfo_race_menu.append(Text('Cost: %s' % cost)) shopinfo_race_menu.append(Text('Buyable when: %s' % required_status)) shopinfo_race_menu.append(Text('Duration: %s' % duration)) shopinfo_race_menu.send(index)
def _jointeam(command, index): """Cancel a player's repeat if they join spectators.""" if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: return # Is the player joining spectators? if command[1] != 1: # If not, just return return CommandReturn.CONTINUE # Get the player's userid userid = userid_from_index(index) # Get the player's DMPlayer instance player = deathmatch_players[userid] # Is the player's repeat active? if player.is_repeat_active(): # Message the player about cancelling their respawn player_dictionary[userid].hint_message('DeathMatch:CancelTeam') # Stop the player's repeat player.stop_repeat() # Return from the command return CommandReturn.CONTINUE
def sp_ban(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: " "$c=(purple)sp_ban $c=(white)<name|#userid|@filter> [minutes: 0] [reason: \"\"]") return CommandReturn.BLOCK targets = target_filter(command[1], source.index) time = command[2] if command.get_arg_count() > 2 else 0 reason = " ".join([command[x] for x in range(3, command.get_arg_count())]) if len(targets) == 0: source.message("c=(white)[c=(purple)SPc=(white)] No Targets found.") else: for target in targets: engine_server.server_command("banid {} {}\n".format(time, userid_from_index(target))) engine_server.server_command("kickid {} {}\n".format(userid_from_index(target), reason)) engine_server.server_command("writeid") source.message("c=(white)[c=(purple)SPc=(white)] Banned " + str(len(targets)) + " players.") return CommandReturn.BLOCK
def rule_menu_callback(_menu, _index, _option): choice = _option.value if choice: userid = userid_from_index(_index) if choice == 'No': queue_command_string('kickid %s You have to accept the rules!' % (userid)) elif choice == 'Yes': SayText2('\x04Thank you for accepting the rules and have fun!').send(_index)
def _on_change_hero_select(menu, index, choice): player = players[userid_from_index(index)] hero = choice.value if not hero.name == player.hero.name and hero.meets_requirements(player): player.client_command('kill', True) player.hero = hero() load_hero_data(player) return
def _show_xp_say_command(command, index, team_only=None): player = players[userid_from_index(index)] show_experience.send(index, hero=player.hero.name, level=player.hero.level, experience=player.hero.experience, needed=player.hero.required_experience( player.hero.level)) return CommandReturn.BLOCK
def wcsadmin_changerace_menu_select(menu, index, choice): player_entity = choice.value global chosen_player chosen_player = player_entity.userid userid = userid_from_index(index) if categories_on.get_int() == 1: doCommand_cats(userid) if categories_on.get_int() == 0: doCommandChangerace(userid)
def wcsadmin_github_races_repository_menu_select(menu, client, option): wcsplayer = Player(client) name = wcsplayer.data['_internal_wcsadmin_github_name'] github_installing_message.send(client, name=name) github_manager.install_module(option.value, 'races', name, userid_from_index(client)) return wcsadmin_github_races_repository_menu.parent_menu
def _joinclass(command, index): """Hook joinclass to start a player's repeat.""" # Get the player's userid userid = userid_from_index(index) # Start the player's repeat deathmatch_players[userid].start_repeat() # Return from the command return CommandReturn.CONTINUE
def take_delayed_damage(self, damage, attacker, skip_hooks=True): # TODO: This method should not have been called if the victim is already dead assert not self.player.dead attacker = userid_from_index(attacker) delay = Delay(0, self._take_delayed_damage, args=(damage, attacker, skip_hooks)) delay.args += (delay, ) _delays[self.userid].add(delay)
def __call__(cls, index, *args, **kwargs): """Instantiates the class. If an instance with the same userid already exists, return it instead of creating a new one. """ instance_dict = _EasyPlayerMeta._classes[cls] userid = userid_from_index(index) if userid not in instance_dict: instance_dict[userid] = super().__call__(index, *args, **kwargs) return instance_dict[userid]
def __call__(cls, index, *args, **kwargs): """Instantiates the class. If an instance with the same userid already exists, return it instead of creating a new one. """ instance_dict = _EasyPlayerMeta._classes[cls] userid = userid_from_index(index) if userid not in instance_dict: instance_dict[userid] = super().__call__(index, *args, **kwargs) return instance_dict[userid]
def _on_spend_skills_build(menu, index): player = players[userid_from_index(index)] menu.clear() menu.description = strings['unused'].get_string( amount=player.hero.unused_points(player.hero.level)) for skill in player.hero.skills: menu.append( PagedOption( strings['skill'].get_string(name=skill.name, level=skill.level, max_level=skill.max_level), skill))
def wcs_bank_admin_command(command, index, team=None): userid = userid_from_index(index) if wcs.admin.is_admin(userid): if wcs.admin.has_flag(userid, 'wcsadmin_bank'): wcsadmin_bank_menu = PagedMenu( title='WCSBank Menu', build_callback=wcsadmin_bank_menu_build, select_callback=wcsadmin_bank_menu_select) wcsadmin_bank_menu.send(index) else: wcs.wcs.tell(userid, '\x04[WCS] \x05You\'re \x04not \x05an WCS-Bank admin')
def sp_slay(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: $c=(purple)sp_slay $c=(white)<name|#userid|@filter>") return CommandReturn.BLOCK targets = target_filter(command[1], source.index) if len(targets) == 0: source.message("c=(white)[c=(purple)SPc=(white)] No Targets found.") else: for target in targets: engine_server.client_command(edict_from_userid(userid_from_index(target)), "kill", True) message_client(target, "You have been slayed.") source.message("c=(white)[c=(purple)SPc=(white)] Slayed " + str(len(targets)) + " players.") return CommandReturn.BLOCK
def shopinfo_menu_subcats_build(menu, index): menu.clear() userid = userid_from_index(index) section = menu.title shopinfo_menu_subcats.parent_menu = shopinfo_menu_cats items_all = wcs.wcs.ini.getItems items_all.walk(gather_subsection) for item in item_names: item_sec = wcs.wcs.itemdb.getSectionFromItem(item) if item_sec == section: iteminfo = wcs.wcs.itemdb.getItem(item) option = PagedOption('%s' % str(iteminfo['name']), item) menu.append(option)
def _joinclass(command, index): """Hook joinclass to start a player's repeat.""" if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: return # Get the player's userid userid = userid_from_index(index) # Start the player's repeat deathmatch_players[userid].start_repeat() # Return from the command return CommandReturn.CONTINUE
def on_say(command, index, team_only): if sayevents_cvar.get_int() <= 0: return CommandReturn.CONTINUE import es # TODO: Fire es_player_chat # TODO: es.regsaycmd() should be handled here and not with SP's # get_say_command() userid = userid_from_index(index) if es.addons.sayFilter(userid, command.arg_string, team_only): return CommandReturn.CONTINUE return CommandReturn.BLOCK
def sp_kick(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: " "$c=(purple)sp_kick $c=(white)<name|#userid|@filter> [reason: \"\"]") return CommandReturn.BLOCK targets = target_filter(command[1], source.index) if len(targets) == 0: source.message("c=(white)[c=(purple)SPc=(white)] No Targets found.") else: for target in targets: reason = " ".join([command[x] for x in range(2, command.get_arg_count())]) engine_server.server_command("kickid {} {}\n".format(userid_from_index(target), reason)) source.message("c=(white)[c=(purple)SPc=(white)] Kicked " + str(len(targets)) + " players.") return CommandReturn.BLOCK
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 _query_save(self, result): # We don't want them to have previous data # This has to be done here, as it'll cause errors if it's done in OnClientDisconnect self.data.clear() try: self._index = index_from_uniqueid(self.uniqueid) except ValueError: OnPlayerDestroy.manager.notify(self) del Player._players[self.uniqueid] self._userid = None self._index = None else: self._userid = userid_from_index(self.index)
def _pre_flashbang_detonate(args): """Store the flashbang's thrower/team to compare against player teams.""" global _flashbang_team, _flashbang_thrower # Get the weapon's instance weapon = make_object(Weapon, args[0]) # Store the weapon's team _flashbang_team = weapon.team # Get the weapon's thrower owner = weapon.current_owner # Store the owner's userid if owner is not None: _flashbang_thrower = userid_from_index(owner.index)
def _on_change_hero_build(menu, index): player = players[userid_from_index(index)] menu.clear() menu.description = strings['change_hero'] for hero in Hero.get_subclasses(): if not hero.meets_requirements(player): menu.append( PagedOption(strings['hero'].get_string( hero=hero.name, requirement=hero.requirement), hero, selectable=False)) else: menu.append( PagedOption(strings['hero'].get_string(hero=hero.name, requirement='Owned'), hero, selectable=True))
def _pre_take_damage(stack_data): """Store the information for later use.""" take_damage_info = make_object(TakeDamageInfo, stack_data[1]) attacker = Entity(take_damage_info.attacker) if attacker.classname != 'player': return victim = make_object(Player, stack_data[0]) if victim.health > take_damage_info.damage: return KILLER_DICTIONARY[victim.userid] = { 'attacker': userid_from_index(attacker.index), 'end': Vector(*take_damage_info.position), 'projectile': attacker.index != take_damage_info.inflictor, 'color': _team_colors[victim.team], }
def _pre_take_damage(stack_data): """Store the information for later use.""" take_damage_info = make_object(TakeDamageInfo, stack_data[1]) attacker = Entity(take_damage_info.attacker) if attacker.classname != 'player': return victim = make_object(Player, stack_data[0]) if victim.health > take_damage_info.damage: return KILLER_DICTIONARY[victim.userid] = { 'attacker': userid_from_index(attacker.index), 'end': Vector(*take_damage_info.position), 'projectile': attacker.index != take_damage_info.inflictor, 'color': _team_colors[victim.team], }
def on_say(command, index, team_only): if sayevents_cvar.get_int() <= 0: return CommandReturn.CONTINUE import es try: userid = userid_from_index(index) except ValueError: userid = 0 fire_es_player_chat(command, userid, team_only) # TODO: es.regsaycmd() should be handled here and not with SP's # get_say_command() if es.addons.sayFilter(userid, command.arg_string, team_only): return CommandReturn.CONTINUE return CommandReturn.BLOCK
def _gold_admin_menu_select(menu, index, choice): userid = userid_from_index(index) if choice.choice_index == 1: if has_flag(userid, 'goldadmin_givegold'): giveGolddoCommand(userid) else: SayText2('\x04[WCS] \x05You do not have \x04access \x05this menu!' ).send(index) gold_admin_menu.send(index) if choice.choice_index == 2: if has_flag(userid, 'goldadmin_removegold'): takeGolddoCommand(userid) else: SayText2('\x04[WCS] \x05You do not have \x04access \x05this menu!' ).send(index) gold_admin_menu.send(index) if choice.choice_index == 9: menu.close(index)
def send_weapons_menu(index): """Send the weapon menu to the player.""" menu = PagedMenu(title=menu_strings['Weapons:Title']) if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: menu.append(menu_strings['Inactive']) else: player = player_dictionary[userid_from_index(index)] for level, instance in weapon_order_manager.active.items(): menu.append( ListOption( choice_index=level, text='{weapon} [{multi_kill}]'.format( weapon=instance.weapon, multi_kill=instance.multi_kill, ), value=level, highlight=level == player.level, selectable=False, ) ) menu.send(index)
def wcs_bank_command(command, index, team=None): userid = userid_from_index(index) if bank_player_loaded[userid] == True: if int(bankplayer[userid].levels) > 0: amount_menu.clear() amount_menu.append( Text('You have %s Levels in your bank' % bankplayer[userid].levels)) amount_menu.append(PagedOption('1', 'spendlevels')) amount_menu.append(PagedOption('5', 'spendlevels')) amount_menu.append(PagedOption('10', 'spendlevels')) amount_menu.append(PagedOption('25', 'spendlevels')) amount_menu.append(PagedOption('100', 'spendlevels')) amount_menu.append(PagedOption('250', 'spendlevels')) amount_menu.append(PagedOption('1000', 'spendlevels')) amount_menu.append(PagedOption('2500', 'spendlevels')) amount_menu.send(index) else: wcs.wcs.tell( userid, '\x04[WCS] \x05You do not have \x04any \x05levels in your \x04Levelbank' )
def popupHandler(menu, index, choice): if choice.choice_index == 8: player = Player(index) player.client_command('wcs', server_side=True) if choice.choice_index < 8: userid = userid_from_index(index) race = wcs.wcs.wcsplayers[userid].currace db = wcs.wcs.racedb.getRace(race) nos = int(db['numberofskills']) nol = db['numberoflevels'] if '|' in nol: nol = nol.split('|') nol = [int(x) for x in nol] else: nos = int(db['numberofskills']) nol_tmp = int(db['numberoflevels']) nol = [] x = 0 while x < nos: nol.append(nol_tmp) x += 1 needed = db['skillneeded'].split('|') if nos >= choice.value: skills = wcs.wcs.wcsplayers[userid].all_races[race][ 'skills'].split('|') if int(skills[choice.value - 1]) < nol[choice.value - 1] and int( needed[choice.value - 1] ) <= wcs.wcs.wcsplayers[userid].all_races[race]['level']: level = wcs.wcs.wcsplayers[userid].add_point(choice.value) if level != None: wcs.wcs.tell( userid, '\x04[WCS] \x05Your skill \x04%s \x05is now on level \x04%s.' % (db['skillnames'].split('|')[choice.value - 1], level)) if wcs.wcs.wcsplayers[userid].all_races[race]['unused']: doCommand(userid)
def _pre_damage_call_events(stack_data): take_damage_info = make_object(TakeDamageInfo, stack_data[1]) if not take_damage_info.attacker: return entity = Entity(take_damage_info.attacker) attacker = players[userid_from_index(entity.index)] if entity.is_player() else None victim = players[userid_from_pointer(stack_data[0])] event_args = { 'attacker': attacker, 'victim': victim, 'take_damage_info': take_damage_info, } if attacker: if victim.team == attacker.team: attacker.hero.call_events('player_pre_teammate_attack', player=attacker, **event_args) victim.hero.call_events('player_pre_teammate_victim', player=victim, **event_args) return attacker.hero.call_events('player_pre_attack', player=attacker, **event_args) victim.hero.call_events('player_pre_victim', player=victim, **event_args)
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 _main_menu_select(menu, index, choice): menu.clear() userid = int(userid_from_index(index)) if choice.choice_index == 1: shopmenu.shopmenu_menu_cats.parent_menu = menu shopmenu.doCommand(userid) menu.close(index) elif choice.choice_index == 2: shopinfo.doCommand(userid) menu.close(index) elif choice.choice_index == 3: showskills.doCommand(userid) menu.close(index) elif choice.choice_index == 4: resetskills.doCommand(userid) menu.close(index) elif choice.choice_index == 5: spendskills.doCommand(userid) menu.close(index) elif choice.choice_index == 6: if config.coredata['categories'] == "1": changerace.changerace_menu_cats.parent_menu = menu else: changerace.changerace_menu.parent_menu = menu changerace.HowChange(userid) menu.close(index) elif choice.choice_index == 7: raceinfo.raceinfo_menu.parent_menu = menu raceinfo.doCommand(userid) menu.close(index) elif choice.choice_index == 8: playerinfo.playerinfo_player_menu.parent_menu = menu playerinfo.doCommand(userid) menu.close(index) elif choice.choice_index == 9: menu.close(index)
def listener_on_client_disconnect(index): user = user_manager.get(userid_from_index(index)) if user is not None: user_manager.delete(user)
def from_index(self, index): """Return the player's instance from their index.""" return self[userid_from_index(index)]
def get_by_index(self, index): userid = userid_from_index(index) return self.get(userid)
def send_level_menu(index): """Send the level menu to the player.""" menu = SimpleMenu() player = player_dictionary[userid_from_index(index)] menu.append( SimpleOption( 1, menu_strings['Level:Title'], selectable=False, ) ) language = player.language if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE: menu.append(menu_strings['Inactive']) elif gg_plugin_manager.is_team_game: if player.team not in team_levels: menu.append(Text(menu_strings['Level:Inactive'])) else: team_level = team_levels[player.team] leader_level = max(team_levels.values()) teams = [ team_names[num] for num, level in team_levels.items() if level == leader_level ] menu.append( menu_strings['Level:Team'].get_string( language=language, level=team_level, ) ) if team_level < leader_level: menu.append( menu_strings['Level:Team:Trailing'].get_string( language=language, levels=leader_level - team_level, ) ) elif len(teams) == 1: second_place = max([ x for x in team_levels.values() if x != leader_level ]) menu.append( menu_strings['Level:Team:Leading'].get_string( language=language, levels=leader_level - second_place ) ) elif len(teams) == len(team_levels): if len(teams) == 2: menu.append(menu_strings['Level:Team:Tied']) else: menu.append(menu_strings['Level:Team:All']) else: message = menu_strings['Level:Team:Multiple'].get_string( language=language, ) message += '\n\t* {teams}'.format( teams=', '.join(teams) ) menu.append(message) elif player.team < 2: menu.append(Text(menu_strings['Level:Inactive'])) else: menu.append( Text( menu_strings['Level:Current'].get_string( language, level=player.level, ) ) ) menu.append( Text( menu_strings['Level:Weapon'].get_string( language, kills=player.level_multi_kill - player.multi_kill, weapon=player.level_weapon, ) ) ) leaders = leader_manager.current_leaders if leaders is None: menu.append(Text(menu_strings['Leader:None'])) elif player.userid not in leaders: menu.append( Text( menu_strings['Level:Trailing'].get_string( language, levels=leader_manager.leader_level - player.level, ) ) ) elif len(leaders) > 1: menu.append(Text(menu_strings['Level:Tied'])) else: menu.append(Text(menu_strings['Level:Leading'])) menu.append( SimpleOption( 2, menu_strings['Level:Wins-Title'], selectable=False, ) ) menu.append( Text( menu_strings['Level:Wins'].get_string( language, wins=player.wins, ) ) ) menu.send(index)
def get_by_index(self, index): return self[userid_from_index(index)]
def is_player(entity): """Return True if the entity is a player.""" return userid_from_index(entity.index, False) != INVALID_PLAYER_USERID