def on_pre_drop_weapon(stack_data): """Remove the dropped weapon after one second.""" # Get the weapon dropped weapon_ptr = stack_data[1] # Continue only for valid weapons if weapon_ptr: # Get a Weapon instance for the dropped weapon weapon = make_object(Weapon, weapon_ptr) # Remove it after one second delay_manager(f'drop_{weapon.index}', 1, weapon_manager.remove_weapon, (weapon.index, ))
def enable_damage_protection(self, time_delay=None): """Enable damage protection and disable it after `time_delay` if `time_delay` is not None.""" # Cancel the damage protection delay for the player delay_manager.cancel(f'protect_{self.userid}') # Enable god mode self.godmode = True # Set protection color self.color = Color(100, 70, 0) # Disable protection after `time_delay` if time_delay is not None: delay_manager( f'protect_{self.userid}', time_delay, PlayerEntity.disable_damage_protection, (self.index, ), call_on_cancel=True )
def load(): """Prepare deathmatch gameplay.""" # Manipulate convar values default_convars.manipulate_values() # Register the Spawn Locations Manager menu as a submenu for the Admin menu admin_menu.register_submenu(menus.spawn_location_manager_menu) # Disable map functions EntityInputDispatcher.perform_action(map_functions, 'Disable') # Remove forbidden entities after 2 seconds delay_manager(f'remove_forbidden_entities', 2, EntityRemover.perform_action, (forbidden_entities, )) # Restart the game after 3 seconds mp_restartgame.set_int(3)
def team_changed(self, team_index): self.team = team_index # Take a note of the team change self.team_changes += 1 # Reset the player's team change count after the team change reset delay if the maximum team change count # has been reached if self.team_changes == cvar_team_changes_per_round.get_int() + 1: penalty_seconds = abs(cvar_team_changes_reset_delay.get_float()) * 60.0 delay_manager( f'reset_team_changes_{self.userid}', penalty_seconds, PlayerEntity.reset_team_changes, (self.userid,) ) penalty_start = datetime.datetime.now() penalty_end = penalty_start + datetime.timedelta(seconds=penalty_seconds) penalty_delta = penalty_end - penalty_start minutes, seconds = str(penalty_delta).split(':')[1:] penalty_map = { 'minutes': int(minutes), 'seconds': int(seconds) } penalty_strings = [f'{penalty_map[key]} {key}' for key in sorted(penalty_map) if penalty_map[key] > 0] # Fix postfix 's' if the respective time value is not higher than 1 penalty_strings = [s if s[0] > '1' else s[:-1] for s in penalty_strings] # Join the strings together penalty_string = ' and '.join(penalty_strings) # Tell the player self.tell( f'{MESSAGE_COLOR_WHITE}You will have to wait {MESSAGE_COLOR_ORANGE}{penalty_string}' f'{MESSAGE_COLOR_WHITE} to join any other team from now on.' ) # Respawn the player after the respawn delay delay_manager( f'respawn_{self.userid}', abs(cvar_respawn_delay.get_float()), PlayerEntity.respawn, (self.index,) )
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 refill_clip(self, weapon_data): """Restore the player's active weapon's clip.""" delay_manager( f'refill_clip_{self.active_weapon.index}', 0.1, self.active_weapon.set_clip, (weapon_data.clip,) )