def on_select_primary_weapon(menu, player_index, option): """Add the primary weapon to the player's inventory.""" player = PlayerEntity(player_index) player.choose_weapon(option.value) # Send the secondary menu to the player secondary_menu.send(player.index)
def unload(): """Reset deathmatch gameplay.""" # Enable map functions EntityInputDispatcher.perform_action(map_functions, 'Enable') # Clear player data PlayerEntity.clear_data() # Restart the game after 1 second mp_restartgame.set_int(1)
def on_spawn_location_manager_menu_select(menu, player_index, option): """Handle the selected option.""" # Get a PlayerEntity instance for the player player = PlayerEntity(player_index) # Call the callback function from `option` on `player` option.value(player)
def on_close_admin_menu(menu, player_index): """Enable default gameplay for the admin player who just closed the Admin menu.""" player = PlayerEntity(player_index) # Remove the player from the Admin menu users storage admin_menu.users.remove(player.userid) # Equip the player with their inventory & a High Explosive grenade player.equip_inventory() player.give_weapon('weapon_hegrenade') # Give a random melee weapon player.give_weapon('weapon_knife') # Disable damage protection PlayerEntity.disable_damage_protection(player_index)
def on_player_disconnect(game_event): """Cancel all pending delays for the disconnecting player.""" player = PlayerEntity.from_userid(game_event['userid']) delay_manager.cancel(f'respawn_{player.userid}') delay_manager.cancel(f'protect_{player.userid}') player.clear_data(keep_inventories=True)
def on_spawn_location_list_menu_select(menu, player_index, option): """Spawn the player at the selected location.""" # Get a PlayerEntity instance for the player player = PlayerEntity(player_index) # Move player to the chosen spawn location option.value.move_player(player) # Send the Spawn Location Manager menu to the player spawn_location_manager_menu.send(player.index)
def on_weapon_fire_on_empty(game_event): """Refill the player's ammo, if the player's active weapon's clip is about to be empty.""" if cvar_enable_infinite_ammo.get_int() > 0: player = PlayerEntity.from_userid(game_event['userid']) # Refill only valid weapons if weapon_manager.by_name( player.active_weapon.weapon_name) is not None: # Refill only if this is the last round if player.active_weapon.clip == 1: player.refill_ammo(1)
def on_player_death(game_event): """Handle attacker rewards & respawn the victim.""" # Get the attacker's userid userid_attacker = game_event['attacker'] # Handle attacker rewards, if the attacker's userid is valid if userid_attacker: attacker = PlayerEntity.from_userid(userid_attacker) # Handle headshot reward if cvar_refill_clip_on_headshot.get_int( ) > 0 and game_event['headshot']: # Get the weapon's data weapon_data = weapon_manager.by_name( attacker.active_weapon.weapon_name) # Refill the weapon's clip attacker.refill_clip(weapon_data) # Restore the weapon's ammo attacker.active_weapon.ammo = weapon_data.maxammo # Give a High Explosive grenade, if it was a HE grenade kill if cvar_equip_hegrenade.get_int( ) == 2 and game_event['weapon'] == 'hegrenade': attacker.give_weapon('weapon_hegrenade') # Restore the attacker's health if it was a knife kill if cvar_restore_health_on_knife_kill.get_int( ) > 0 and game_event['weapon'].startswith('knife'): attacker.health = 100 # Get a PlayerEntity instance for the victim victim = PlayerEntity.from_userid(game_event['userid']) # Respawn the victim after the configured respawn delay delay_manager(f'respawn_{victim.userid}', abs(cvar_respawn_delay.get_float()), PlayerEntity.respawn, (victim.index, ))
def on_player_run_command(player, user_cmd): """Store the silencer option when the player attaches or detaches the silencer.""" # Ignore dead players if player.dead: return # Ignore bots if player.is_bot(): return # Only respect secondary attack if not user_cmd.buttons & PlayerButtons.ATTACK2: return # Get the player's active weapon weapon = player.active_weapon # Ignore weapon errors if weapon is None: return # Only respect weapons with silencers if weapon.classname not in ('weapon_m4a1', 'weapon_hkp2000' if GAME_NAME == 'csgo' else 'weapon_usp'): return # Set the silencer option for the player's inventory item inventory_item = PlayerEntity(player.index).inventory_item_by_weapon_name( weapon.weapon_name) if inventory_item is not None: inventory_item.silencer_option = weapon.get_property_bool( 'm_bSilencerOn') if GAME_NAME == 'csgo': inventory_item.silencer_option = not inventory_item.silencer_option
def client_command_filter(command, index): """Handle buy anywhere & spawning in the middle of the round.""" # Get a PlayerEntity instance for the player player = PlayerEntity(index) # Get the client command client_command = command[0] # Handle client command `buy` if client_command == 'buy': player.choose_weapon(command[1]) # Block any further command handling return False # Handle the client command `drop` if client_command == 'drop': player.weapon_dropped() # Block any further command handling return False # Allow any client command besides `jointeam` if client_command != 'jointeam': return True # Get the team the player wants to join team_index = int(command[1]) # Allow spectators if team_index < 2: return True # Allow the team change, if the player hasn't yet exceeded the maximum team change count if player.team_changes < cvar_team_changes_per_round.get_int() + 1: player.team_changed(team_index) # Allow the client command return True # Block any further command handling return False
def on_saycommand_admin(command_info): """Send the Admin menu to the player.""" # Get a PlayerEntity instance for the player player = PlayerEntity(command_info.index) # Protect the player indefinitely player.enable_damage_protection() # Strip the player off their weapons player.strip(not_filters=None) # Send the Admin menu to the player admin_menu.users.append(player.userid) admin_menu.send(command_info.index) # Block the text from appearing in the chat window return False
def on_close_secondary_menu(menu, player_index): """Equip random weapons if the player's inventory is empty.""" player = PlayerEntity(player_index) if not player.inventory: player.equip_random_weapons()
def on_pre_round_freeze_end(game_event): """Enable damage protection for all players.""" delay_time = abs(cvar_spawn_protection_delay.get_float()) for player in PlayerEntity.alive(): player.enable_damage_protection(delay_time)
def on_saycommand_guns(command_info, *args): """Allow the player to edit & equip one of their inventories.""" # Get a PlayerEntity instance for the player who entered the chat command player = PlayerEntity(command_info.index) # Get the selection for the inventory the player wants to equip or edit selection = args[0] if args else None # If no selection was made, send the Primary Weapons menu if selection is None: primary_menu.send(player.index) # Tell the player player.tell( f'Editing inventory {MESSAGE_COLOR_WHITE}{player.inventory_selection + 1}' ) # Stop here and block the message from appearing in the chat window return False # Ignore invalid input when evaluating the inventory selection try: selection = int(selection) except ValueError: return False # Stop if the selection isn't valid if selection <= 0: return False # Make the player's choice their inventory selection player.inventory_selection = selection - 1 # Send the Primary Weapons menu if the player is allowed to edit their inventory if player.carries_inventory: primary_menu.send(player.index) # Tell the player player.tell( f'Editing inventory {MESSAGE_COLOR_WHITE}{player.inventory_selection + 1}' ) # Else equip the selected inventory else: player.equip_inventory() # Tell the player player.tell( f'Equipping inventory {MESSAGE_COLOR_WHITE}{player.inventory_selection + 1}' ) # Block the message from appearing in the chat window return False
def on_level_end(): """Clear personal player dictionaries.""" PlayerEntity.clear_data(keep_inventories=True) # Cancel all delays delay_manager.clear()
def on_weapon_reload(game_event): """Refill the player's ammo.""" if cvar_enable_infinite_ammo.get_int() > 0: player = PlayerEntity.from_userid(game_event['userid']) player.refill_ammo()
def on_hegrenade_detonate(game_event): """Equip the player with another High Explosive grenade if configured that way.""" if cvar_equip_hegrenade.get_int() == 3: player = PlayerEntity.from_userid(game_event['userid']) player.give_weapon('weapon_hegrenade')
def on_player_spawn(game_event): """Prepare the player for battle if they are alive and on a team.""" player = PlayerEntity.from_userid(game_event['userid']) if not player.dead and player.team > 1: prepare_player(player)