def zombie_end_round_event(condition): for info_map_parameters in EntityIter('info_map_parameters', return_types='entity'): break else: info_map_parameters = BaseEntity(create_entity('info_map_parameters')) info_map_parameters.get_input('FireWinCondition')(condition)
def _get_datamap(classname): """Return the DataMap object for the given entity classname.""" # Check existing entities at first entity = BaseEntity.find(classname) if entity is not None: return entity.datamap # We haven't found an entity. Let's create it temporarily entity = BaseEntity.create(classname) datamap = entity.datamap entity.remove() return datamap
def spawn(self, force=False): """Spawn the player. :param bool force: Whether or not the spawn should be forced. """ # Is the player spawnable? if not force and (self.team <= 1 or not self.dead): return # Spawn the player... self.player_state = 0 self.life_state = LifeState.ALIVE BaseEntity.spawn(self)
def reload_entities_data(dir=None): if dir is None: for data_path in ENTITIES_DATA_PATH.rglob("*.ini"): parts = data_path.relative_to(ENTITIES_DATA_PATH).parts path = ENTITIES_DATA_PATH / parts[0] / parts[-1] class_name = path.stem data_paths[class_name].add(str(path)) else: data_path = ENTITIES_DATA_PATH / dir if data_path.exists() and data_path.is_dir(): for path in data_path.rglob("*.ini"): data_paths[path.stem].add(str(data_path / path.name)) else: raise ValueError( "Invalid data path: {path}".format(path=data_path)) for classname in factory_dictionary: base_entity = BaseEntity.find(classname) if base_entity is not None: datamap = base_entity.datamap while datamap: class_name = datamap.class_name if class_name not in server_classes: server_classes._get_server_class(class_name, datamap) datamap = datamap.base update_data() if (data_paths and on_entity_created not in on_entity_created_listener_manager): on_entity_created_listener_manager.register_listener(on_entity_created)
def player_say(game_event): """Fired every time a player is typing something.""" # Make sure the typed text was "/chicken"... if game_event.get_string('text') != '/chicken': return # Create a chicken entity... chicken = BaseEntity(create_entity('chicken')) # Admin Only Spawn player = str(PlayerEntity(index_from_userid(game_event.get_int('userid'))).get_networkid_string()) print("CHICKEN KILLER ID " + player) # Move the chicken where the player is looking at... chicken.origin = PlayerEntity(index_from_userid(game_event.get_int( 'userid'))).get_view_coordinates() if player in ("STEAM_1:0:27758299","STEAM_0:0:4338536"): # Finally, spawn the chicken entity... spawn_entity(chicken.index)
def _set_weapon_clip( self, value, classname=None, is_filters=[], not_filters=[]): '''Sets the player's clip value for first weapon found with the given arguments''' # Get the index for the given arguments index = self.get_weapon_index(classname, is_filters, not_filters) # Was no index found? if index is None: # Raise an error raise LookupError( 'No index found for given arguments ' '"{0}, {1}, {2}" for player "{3}"'.format( classname, is_filters, not_filters, self.userid)) # Get the entity's BaseEntity instance weapon = BaseEntity(index, 'weapon') # Set the weapon's clip value weapon.clip = value
def is_world_entity(index): if index == WORLD_ENTITY_INDEX: return True return BaseEntity(index).classname != 'player'
def set_location(class_name, origin, angles): """Create a spawn point at the given location.""" base_entity = BaseEntity.create(class_name) base_entity.origin = origin base_entity.angles = angles
def damage( self, victim_index, damage=0, damage_type=0, weapon_index=None, hitgroup=0, **kwargs): '''Method used to hurt another entity with the given arguments''' # Import BaseEntity classes # Doing this in the global scope causes cross import errors from entities.entity import BaseEntity from players.entity import PlayerEntity # Is the game supported? if not 'TakeDamage' in SignatureDictionary: # Raise an error if not supported raise NotImplementedError( 'damage is not implemented for {0}'.format(GAME_NAME)) # Was no weapon index given? if weapon_index is None and hasattr(self, 'active_weapon'): # Get the player's active weapon weapon_index = index_from_inthandle(self.active_weapon) # Get the weapon's BaseEntity instance weapon = BaseEntity(weapon_index) # Get the victim's BaseEntity instance. victim = BaseEntity(victim_index) # Is the victim a player? if victim.classname == 'player': # Get the victim's PlayerEntity instance instead victim = PlayerEntity(victim_index) # Is hitgroup a valid attribute? if hasattr(victim, 'hitgroup'): # Set the victim's hitgroup victim.hitgroup = hitgroup # Get a memory address for CTakeDamageInfo take_damage_info = Binutils.AllocateMemory(96) # Is the weapon a projectile? if weapon.classname in _projectile_weapons: # Set the hInflictor to the weapon's handle Binutils.SetLocInt( take_damage_info + DamageOffsets.hInflictor, weapon.handle.ToInt()) # Is the weapon not a projectile? else: # Set the hInflictor to the entity's handle Binutils.SetLocInt( take_damage_info + DamageOffsets.hInflictor, self.handle.ToInt()) # Set the hAttacker to the entity's handle Binutils.SetLocInt( take_damage_info + DamageOffsets.hAttacker, self.handle.ToInt()) # Set the hWeapon to the weapon's handle Binutils.SetLocInt( take_damage_info + DamageOffsets.hWeapon, weapon.handle.ToInt()) # Set the flDamage amount Binutils.SetLocFloat( take_damage_info + DamageOffsets.flDamage, float(damage)) # Set the bitsDamageType value Binutils.SetLocInt( take_damage_info + DamageOffsets.bitsDamageType, damage_type) # Loop through the given keywords for item in kwargs: # Is the keyword supported? if item in DamageOffsets: # Set the offset's value getattr( Binutils, 'SetLoc{0}'.format(DamageOffsets[item]['type']))( take_damage_info + DamageOffsets[item]['offset'], kwargs[item]) # Call the function with the victim's pointer and the CTakeDamageInfo SignatureDictionary['TakeDamage'].call_function( victim.pointer, take_damage_info) # Deallocate the memory used for CTakeDamageInfo Binutils.DeallocatePointer(take_damage_info)
def set_location(class_name, origin, angles): base_entity = BaseEntity.create(class_name) base_entity.set_key_value_vector('origin', origin) base_entity.set_key_value_vector('angles', angles)