Exemplo n.º 1
0
def _set_team_level(game_event):
    for class_name in team_managers:
        for entity in EntityIter(class_name):
            if entity.team_index != game_event['team']:
                continue
            entity.score = game_event['new_level']
            return
Exemplo n.º 2
0
    def __init__(self, factory=Entity, iterator=EntityIter(), *args, **kwargs):
        """Initializes the dictionary.

        :param callable factory:
            Factory class or function.

            Factory signature: index, *args, **kwargs
        :param iterable iterator:
            Iterator used to generates instances on initialization and resync.
        :param tuple args:
            Arguments passed to the factory class or function.
        :param dict kwargs:
            Keyword arguments passed to the factory class or function.

        :raise ValueError:
            If the factory is set to None.
        """
        if factory is None:
            raise ValueError('Factory cannot be None for synced dictionaries.')

        # Initialize the dictionary
        super().__init__(factory, *args, **kwargs)

        # Store the given iterator and resync the dictionary
        self._iterator = iterator
        self.resync()

        # Register our networked entity creation listener
        on_networked_entity_created_listener_manager.register_listener(
            self._on_networked_entity_created)
Exemplo n.º 3
0
def cmd_on_drop(command, index):
    if not config_manager['drop_hot_weapons']:
        return

    player = player_manager[index]
    if not (player.team == GUARDS_TEAM or is_rebel(player)):
        return True

    weapons = []
    for entity in EntityIter():
        if not entity.classname.startswith('weapon_'):
            continue

        if entity.owner_handle == player.inthandle:
            weapons.append(entity)

    def confirm_weapon_drop():
        for entity in weapons:
            if entity.owner_handle == player.inthandle:
                continue

            mark_weapon_hot(entity)

    Delay(0, confirm_weapon_drop)

    return True
Exemplo n.º 4
0
def find_template_blocks(block_type):
    results = []
    for entity in EntityIter(BLOCK_ENTITY):
        if entity.target_name == f"block_{block_type}":
            results.append(entity)

    return results
Exemplo n.º 5
0
    def __call__(self, callback):
        """Store the callback and try initializing the hook.

        :param callable callback:
            The callback to store.
        :return:
            The passed callback.
        :rtype: callable
        """
        # Validate the given callback...
        if not callable(callback):
            raise TypeError('Given callback is not callable.')

        self.callback = callback

        # Try initializing the hook...
        for entity in EntityIter():
            if self.initialize(entity):
                # Yay! The entity was the one we were looking for
                return self.callback

        # Initialization failed. There is currently no entity with the given
        # class name. So, we need to wait until such an entity has been
        # created.
        _waiting_entity_hooks.append(self)

        # Return the callback
        return self.callback
Exemplo n.º 6
0
    def __init__(self, team):
        self._team = team
        self._score = 0

        for entity in EntityIter('cs_team_manager'):
            if entity.get_property_string('m_szTeamname') == team:
                self.manager = entity
                break
Exemplo n.º 7
0
def _grenade_bounce(game_event):
    coords = Vector(*[game_event[x] for x in 'xyz'])
    for entity in EntityIter('hegrenade_projectile'):
        if entity.origin == coords:
            if entity.get_key_value_string('targetname') == "cluster":
                detonate(entity)
                break
    else:
        return
Exemplo n.º 8
0
    def get_hostname_value():
        """Return the full value of the new hostname."""
        # Get the basename
        value = database['Settings']['base_name']

        # Create an empty dictionary
        plugin_values = dict()

        # Loop through all plugins in the database
        for plugin_name, values in database.items():

            # Is the plugin loaded?
            if plugin_name in gg_plugin_manager:

                if (plugin_name == 'gg_bombing_objective'
                        and not len(EntityIter('func_bomb_target'))):
                    continue

                if (plugin_name == 'gg_hostage_objective'
                        and not len(EntityIter('func_hostage_rescue'))):
                    continue

                # Store the plugin's name and priority
                plugin_values[values['name']] = int(values['priority'])

        # Are there any plugins that are loaded?
        if plugin_values:

            # Add the base_break to the string
            value += database['Settings']['base_break']

            # Sort the loaded plugins by their priority
            plugins = sorted(
                plugin_values,
                key=lambda plugin: plugin_values[plugin],
            )

            # Add all loaded plugins to the string
            # Separate each with the feature_break
            value += database['Settings']['feature_break'].join(plugins)

        return value
Exemplo n.º 9
0
    def projectile_indexes(self, projectile):
        """Yield all indexes of the given projectile for the player.

        :param str projectile: The name of the projectile to find indexes of.
        """
        if projectile in weapon_manager.projectiles:
            for entity in EntityIter(projectile):
                if entity.owner == self:
                    yield entity.index
        else:
            yield from self.weapon_indexes(weapon_manager[projectile].name)
Exemplo n.º 10
0
def _round_start(game_event):
    if GunGameStatus.MATCH is not GunGameMatchStatus.ACTIVE:
        return

    if not gg_plugin_manager.is_team_game:
        return
    for class_name in team_managers:
        for entity in EntityIter(class_name):
            if entity.team_index not in team_levels:
                continue
            entity.score = team_levels[entity.team_index]
Exemplo n.º 11
0
    def has_c4(self):
        """Return whether or not the player is carrying C4."""
        # Loop through all c4 entities on the server
        for weapon in EntityIter('weapon_c4'):

            # Is the entity's "owner" the player?
            if weapon.owner_handle == self.inthandle:

                # Return True
                return True

        # If no c4 is owned by the player, return False
        return False
Exemplo n.º 12
0
    def find(classname):
        """Try to find an entity with the given classname.

        If not entity has been found, None will be returned.

        :param str classname: The classname of the entity.
        :return: Return the found entity.
        :rtype: Entity
        """
        # Import this here to fix a circular import
        from filters.entities import EntityIter

        for entity in EntityIter(classname):
            return entity

        return None
Exemplo n.º 13
0
def find_trains(cp_names):
    for train_watcher in EntityIter('team_train_watcher'):
        for cp_index in range(8):
            key = "linked_cp_{}".format(cp_index + 1)
            cp_name = get_key_value_string_t(train_watcher, key)
            if cp_name in cp_names:
                break
        else:
            continue

        team = train_watcher.get_key_value_int('TeamNum')
        if team == 0:
            train_watchers_by_team[ATTACKING_TEAM] = train_watcher.inthandle
            train_watchers_by_team[DEFENDING_TEAM] = train_watcher.inthandle
        elif team in (ATTACKING_TEAM, DEFENDING_TEAM):
            train_watchers_by_team[team] = train_watcher.inthandle
Exemplo n.º 14
0
    def __call__(self, callback):
        """Store the callback and try initializing the hook."""
        self.callback = callback

        # Try initializing the hook...
        for entity in EntityIter():
            if self.initialize(entity):
                # Yay! The entity was the one we were looking for
                return self

        # Initialization failed. There is currently no entity with the given
        # class name. So, we need to wait until such an entity has been
        # created.
        _waiting_entity_hooks.append(self)

        # Return the callback
        return self.callback
Exemplo n.º 15
0
def on_item_pickup(game_event):
    def does_weapon_trigger_rebel(player, weapon_class, entity):
        should_rebel = weapon_class[7:] in config_manager['forbidden_weapons']

        if IGNORE_MAP_REBELWEAPONS:
            return should_rebel
        # ArcJail allows mapmakers to decide if a picked weapon:
        # 1 - should always make its owner a rebel
        # 0 - should never make its owner a rebel
        # -1 - doesn't have any particular restrictions (server default)
        try:
            # TODO: Extract 'rebelsweapon' keyvalue from entity
            mapmaker_opinion = -1
        except:
            mapmaker_opinion = -1

        return (mapmaker_opinion == -1 and should_rebel
                or mapmaker_opinion == 1)

    player = player_manager.get_by_userid(game_event['userid'])
    if player.dead or not _can_rebel(player):
        return

    # TODO: Use weapon_manager to get the proper "weapon_" prefix
    weapon_class = 'weapon_{}'.format(game_event['item'])
    for entity in EntityIter(weapon_class):
        if entity.owner_handle == player.inthandle:
            break

    else:
        return

    if does_weapon_trigger_rebel(player, weapon_class, entity):
        if entity.index in _hot_weapons:
            player.drop_weapon(entity.pointer, NULL_VECTOR, NULL_VECTOR)
            mark_weapon_hot(entity)
        else:
            _set_rebel(player)
            broadcast(strings_module['by_pickup'].tokenize(rebel=player.name))
Exemplo n.º 16
0
def get_bomb_entity():
    """Return the bomb's BaseEntity instance."""
    for entity in EntityIter('planted_c4', return_types='entity'):
        return entity
Exemplo n.º 17
0
 def perform_action(entities):
     """Remove all entities specified from the server."""
     for classname in entities:
         for entity in EntityIter(classname):
             entity.remove()
Exemplo n.º 18
0
def get_predicted_view_model(player):
    'Retrieves the current view model predictor representative of the player.'
    for entity in EntityIter('predicted_viewmodel'):
        if entity.get_property_int('m_hOwner') != player.inthandle:
            continue
        return entity
Exemplo n.º 19
0
 def perform_action(entities, input_name):
     """Dispatch the specified input on all entities."""
     for classname in entities:
         for entity in EntityIter(classname):
             entity.call_input(input_name)