def _drop_command(command, index): """Throw melee weapon on 'drop'.""" player = Player(index) class_name = getattr(player.active_weapon, 'classname', None) if class_name not in _melee_weapons: return True if not _available_count[player.userid]: TextMsg(MESSAGE_STRINGS['Empty']).send(index) return _available_count[player.userid] -= 1 TextMsg(MESSAGE_STRINGS['Remaining']).send( index, current=_available_count[player.userid], total=int(total_max), ) start_location = player.eye_location velocity = player.view_coordinates - start_location weapon = Weapon.create(class_name) weapon.spawn() weapon.teleport(origin=start_location, velocity=velocity * 200) _throwers[weapon.index] = player.userid delay = int(remove_delay) weapon.delay(delay, weapon.remove)
def show_damage(self, amount): self._current_damage += amount # Display damage amount TextMsg(strings_module['health'].tokenize( amount=self._current_damage)).send(self.player.index) # Play hit sound if config_manager['hit_sound'] is not None: config_manager['hit_sound'].play(self.player.index) # Show hit marker if config_manager['hit_marker_material'] != "": show_overlay( self.player, config_manager['hit_marker_material'], MARKER_VISIBLE_TIMEOUT ) # Cancel delays if any if (self._reset_text_delay is not None and self._reset_text_delay.running): self._reset_text_delay.cancel() # Relaunch delays self._reset_text_delay = Delay(TEXT_VISIBLE_TIMEOUT, self._reset_text)
def countdown(ticks_left): if (ticks_left > 3 or ticks_left < 1 or config_manager[ 'countdown_{}_material'.format(ticks_left)] == ""): TextMsg(str(ticks_left)).send(*indexes) else: for player in self._players: show_overlay(player, config_manager[ 'countdown_{}_material'.format(ticks_left)], 1) if config_manager['countdown_sound'] is not None: config_manager['countdown_sound'].play(*indexes) self._prepare_countdown = Delay(1.0, countdown, ticks_left - 1)
def warn(self, index, cvar_name, cvar_value, event_name): self.add(index) events = self._events[event_name] events[index] -= 1 if events[index] == 0: cvars = "" kick = False remains = 0 for cvar_warning in self._warnings.values(): if index not in cvar_warning: continue if cvar_warning.kick: warned = cvar_warning.warned remain = cvar_warning.kick - warned[index] if remain == 0: kick = True else: if remains == 0 or remains > remain: remains = remain warned[index] += 1 if cvar_warning.cvar_name not in cvars: cvars += (cvar_warning.cvar_name + " " + str(cvar_warning.cvar_value) + ";") if kick: player = Player(index) message = cvartools_strings["kick"].get_string( player.language, cvars=cvars, ) player.kick(message) return message = cvartools_strings["warning"].tokenized( tag=cvartools_strings["tag"], cvars=cvars, until=cvartools_strings["until"].tokenized( remains=remains) if remains else "", ) SayText2(message).send(index) TextMsg(message, HudDestination.CONSOLE).send(index)
def send_page(self, page_class): if not self._loaded: raise RuntimeError("Cannot send pages to this player: " "not synced with the salt database") session = MOTDSession(self, self._next_session_id, page_class) self._sessions[self._next_session_id] = session self._next_session_id += 1 url = URL_BASE.format( server_addr=SERVER_ADDR, server_id=config['server']['id'], plugin_id=page_class.plugin_id, page_id=page_class.page_id, steamid=self.steamid64, auth_method=AuthMethod.SRCDS, auth_token=self.get_auth_token(page_class.plugin_id, page_class.page_id, session.id), session_id=session.id, ) if cvar_motdplayer_debug.get_bool(): TextMsg(url, destination=HudDestination.CONSOLE).send(self.index) VGUIMenu(name='info', show=True, subkeys={ 'title': 'MOTDPlayer v2 (URL only)', 'type': '0', 'msg': url, }).send(self.index) else: VGUIMenu(name='info', show=True, subkeys={ 'title': 'MOTDPlayer v2', 'type': '2', 'msg': url, }).send(self.index) return session
def _pre_bump_weapon(stack_data): """Damage player or give extra if bump is from thrown weapon.""" weapon = make_object(Entity, stack_data[1]) if weapon.classname not in _melee_weapons: return index = weapon.index if index not in _throwers: return if index in _marked_for_removal: return player = make_object(Player, stack_data[0]) asleep = weapon.physics_object.asleep attacker_userid = _throwers[index] if attacker_userid == player.userid and not asleep: return weapon.delay(0, weapon.remove) _marked_for_removal.add(weapon.index) Delay(0, _marked_for_removal.remove, (weapon.index, )) if not asleep: player.take_damage( damage=int(melee_damage), # TODO: verify damage type damage_type=DamageTypes.SLASH, attacker_index=index_from_userid(attacker_userid), weapon_index=weapon.index, # TODO: determine how to find hitgroup hitgroup=HitGroup.CHEST, ) return if not bool(allow_pickup): return TextMsg(MESSAGE_STRINGS['Gained']).send(player.index) _available_count[player.userid] += 1
def send_message(command_info, message): TextMsg(message, HudDestination.CONSOLE).send(command_info.index)
from .teams import PRISONERS_TEAM, GUARDS_TEAM from .players import broadcast, player_manager, tell strings_module = build_module_strings('team_balancer') config_manager = build_module_config('team_balancer') config_manager.controlled_cvar( bool_handler, "enabled", default=1, description="Enable/Disable team balancing", ) text_msg = { 'denied your_team': TextMsg(strings_module['denied your_team']), 'denied locked': TextMsg(strings_module['denied locked']), 'denied balance': TextMsg(strings_module['denied balance']), 'denied no_license': TextMsg(strings_module['denied no_license']), } cvar_limitteams = cvar.find_var('mp_limitteams') cvar_autoteambalance = cvar.find_var('mp_autoteambalance') def ratio_handler(cvar): try: val = float(cvar.get_string()) except ValueError: raise InvalidValue
from messages import TextMsg from players.entity import Player from settings.player import PlayerSettings # Plugin from .config import LOCATION_OPTIONS, default_location from .info import info from .strings import MESSAGE_STRINGS # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the message instances most_damage_messages = { 1: HintText(MESSAGE_STRINGS[info.verbose_name]), 2: TextMsg(MESSAGE_STRINGS[info.verbose_name], HudDestination.CENTER), 4: KeyHintText(MESSAGE_STRINGS[info.verbose_name]), } # Create the user settings user_settings = PlayerSettings(info.verbose_name, 'md') # Get the human player index iterator _human_players = PlayerIter('human') # ============================================================================= # >> CLASSES # ============================================================================= class _MostDamage(dict): """Stores player damage and kills and sends message on round end."""
LIMIT_FUNCTIONS = { 'percentage': lambda player_class_size, team_size, limit: ( player_class_size == 1 or # Always allow at least 1 player player_class_size / team_size * 100 <= limit), 'absolute': lambda player_class_size, team_size, limit: (player_class_size <= limit) } logger = LogManager(info.name, cvar_logging_level, cvar_logging_areas) limits = None last_loaded_limits_file = None reload_limits_file() msg_not_allowed = TextMsg(common_strings['not_allowed']) msg_you_were_switched = SayText2( insert_chat_tag(common_strings['you_were_switched'])) snd_not_allowed = Sound("common/wpn_denyselect.wav") # ============================================================================= # >> CLASSES # ============================================================================= class BalancedPlayer: def __init__(self, index): self.player = Player(index) def get_player_class(self): return self.player.get_property_uchar("m_PlayerClass.m_iClass")
from controlled_cvars.handlers import sound_nullable_handler, string_handler from ..arcjail import InternalEvent from ..classes.base_player_manager import BasePlayerManager from ..resource.strings import build_module_strings from .overlays import show_overlay from . import build_module_config TEXT_VISIBLE_TIMEOUT = 2 MARKER_VISIBLE_TIMEOUT = 0.2 EMPTY_CENTER_MESSAGE = TextMsg("") strings_module = build_module_strings('show_damage') config_manager = build_module_config('show_damage') config_manager.controlled_cvar( sound_nullable_handler, "hit_sound", default="arcjail/hitsound.wav", description="Path to a hit sound, leave empty to disable", ) config_manager.controlled_cvar( string_handler, "hit_marker_material", default="overlays/arcjail/hitmarker",
# Translations from translations.strings import LangStrings # Script Imports from most_damage.info import info # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the translations most_damage_strings = LangStrings(info.basename) # Get the message instances most_damage_messages = { 1: HintText(most_damage_strings[info.name]), 2: TextMsg(most_damage_strings[info.name], HudDestination.CENTER), 4: KeyHintText(most_damage_strings[info.name]), } # Create the user settings user_settings = PlayerSettings(info.name, 'md') # Get the human player index iterator _human_players = PlayerIter('human') # Store the possible options _options = { int(item.split(':')[1]): value for item, value in most_damage_strings.items() if item.startswith('Option:') }
def send_message(command_info, message, language=None, **tokens): TextMsg(message, HudDestination.CONSOLE).send(command_info.index, **tokens)