entities.entity module

Provides a base class to interact with a specific entity.

class entities._base.Entity(index)[source]

Bases: _entities._entity.BaseEntity

Class used to interact directly with entities.

Beside the standard way of doing stuff via methods and properties this class also provides dynamic attributes that depend on the entity that is being accessed with this class. You can print all dynamic properties by iterating over the following generators:

  1. properties
  2. inputs
  3. outputs
  4. keyvalues
__init__(index)[source]

Initialize the Entity instance.

Parameters:index (int) – The entity index to wrap.
_get_property(name, prop_type)[source]

Verify the type and return the property.

_set_parent(parent)[source]

Set the parent of the entity.

Parameters:parent (Entity) – The parent of the entity. If None, actual parent will be cleared.
_set_property(name, prop_type, value)[source]

Verify the type and set the property.

call_input(name, *args, **kwargs)[source]

Call the input function matching the given name.

Parameters:
  • name (str) – Name of the input function.
  • args – Optional arguments that should be passed to the input function.
  • kwargs – Optional keyword arguments that should be passed to the input function.
Raises:

ValueError – Raised if the input function wasn’t found.

classmethod create(classname)[source]

Create a new networked entity with the given classname.

Parameters:classname (str) – Classname of the entity to create.
Raises:ValueError – Raised if the given classname is not a networked entity.
delay(delay, callback, args=(), kwargs=None, cancel_on_level_end=False)[source]

Execute a callback after the given delay.

Parameters:
  • delay (float) – The delay in seconds.
  • callback – A callable object that should be called after the delay expired.
  • args (tuple) – Arguments that should be passed to the callback.
  • kwargs (dict) – Keyword arguments that should be passed to the callback.
  • cancel_on_level_end (bool) – Whether or not to cancel the delay at the end of the map.
Raises:

ValueError – If the given callback is not callable.

Returns:

The delay instance.

Return type:

Delay

emit_sound(sample, recipients=(), volume=1.0, attenuation=<Attenuation.NONE: 0.0>, channel=_engines._sound.Channel.AUTO, flags=_engines._sound.SoundFlags.NO_FLAGS, pitch=_engines._sound.Pitch.NORMAL, origin=Vector(0.0, 0.0, 0.0), direction=Vector(0.0, 0.0, 0.0), origins=(), update_positions=True, sound_time=0.0, speaker_entity=-1, download=False, stream=False)[source]

Emit a sound from this entity.

Parameters:
  • sample (str) – Sound file relative to the sounds directory.
  • recipients (RecipientFilter) – Recipients to emit the sound to.
  • index (int) – Index of the entity to emit the sound from.
  • volume (float) – Volume of the sound.
  • attenuation (Attenuation) – How far the sound should reaches.
  • channel (int) – Channel to emit the sound with.
  • flags (SoundFlags) – Flags of the sound.
  • pitch (Pitch) – Pitch of the sound.
  • origin (Vector) – Origin of the sound.
  • direction (Vector) – Direction of the sound.
  • origins (tuple) – Origins of the sound.
  • update_positions (bool) – Whether or not the positions should be updated.
  • sound_time (float) – Time to play the sound for.
  • speaker_entity (int) – Index of the speaker entity.
  • download (bool) – Whether or not the sample should be added to the downloadables.
  • stream (bool) – Whether or not the sound should be streamed.
classmethod find(classname)[source]

Try to find an entity with the given classname.

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

Parameters:classname (str) – The classname of the entity.
Returns:Return the found entity.
Return type:Entity
classmethod find_or_create(classname)[source]

Try to find an entity with the given classname.

If no entity has been found, it will be created.

Parameters:classname (str) – The classname of the entity.
Returns:Return the found or created entity.
Return type:Entity
get_color()[source]

Return the entity’s color.

Return type:Color
get_input(name)[source]

Return the input function matching the given name.

Parma str name:Name of the input function.
Return type:InputFunction
Raises:ValueError – Raised if the input function wasn’t found.
get_model()[source]

Return the entity’s model.

Return type:Model
get_parent()[source]

Return the entity’s parent.

Return type:Entity
get_property_bool(name)[source]

Return the boolean property.

Parameters:name (str) – Name of the property to retrieve.
Return type:bool
get_property_char(name)[source]

Return the char property.

Parameters:name (str) – Name of the property to retrieve.
Return type:str
get_property_color(name)[source]

Return the Color property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Color
get_property_edict(name)[source]

Return the Edict property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Edict
get_property_float(name)[source]

Return the float property.

Parameters:name (str) – Name of the property to retrieve.
Return type:float
get_property_int(name)[source]

Return the integer property.

Parameters:name (str) – Name of the property to retrieve.
Return type:int
get_property_interval(name)[source]

Return the Interval property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Interval
get_property_pointer(name)[source]

Return the pointer property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Pointer
get_property_quaternion(name)[source]

Return the Quaternion property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Quaternion
get_property_short(name)[source]

Return the short property.

Parameters:name (str) – Name of the property to retrieve.
Return type:int
get_property_string(name)[source]

Return the string property.

Parameters:name (str) – Name of the property to retrieve.
Return type:str
get_property_string_pointer(name)[source]

Return the string property.

Parameters:name (str) – Name of the property to retrieve.
Return type:str
get_property_uchar(name)[source]

Return the uchar property.

Parameters:name (str) – Name of the property to retrieve.
Return type:int
get_property_uint(name)[source]

Return the uint property.

Parameters:name (str) – Name of the property to retrieve.
Return type:int
get_property_ushort(name)[source]

Return the ushort property.

Parameters:name (str) – Name of the property to retrieve.
Return type:int
get_property_vector(name)[source]

Return the Vector property.

Parameters:name (str) – Name of the property to retrieve.
Return type:Vector
is_in_solid(mask=<ContentMasks.ALL: 4294967295>, generator=<class '_entities.BaseEntityGenerator'>)[source]

Return whether or not the entity is in solid.

Parameters:
  • mask (ContentMasks) – Contents the ray can possibly collide with.
  • generator – A callable that returns an iterable which contains BaseEntity instances that are ignored by the ray.
Return type:

bool

lookup_attachment(name)[source]

Return the attachment index matching the given name.

Parameters:name (str) – The name of the attachment.
Return type:int
set_color(color)[source]

Set the entity’s color.

Parameters:color (Color) – Color to set.
set_model(model)[source]

Set the entity’s model to the given model.

Parameters:model (Model) – The model to set.
set_property_bool(name, value)[source]

Set the boolean property.

Parameters:
  • name (str) – Name of the property to set.
  • value (bool) – The value to set.
set_property_char(name, value)[source]

Set the char property.

Parameters:
  • name (str) – Name of the property to set.
  • value (str) – The value to set.
set_property_color(name, value)[source]

Set the Color property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Color) – The value to set.
set_property_edict(name, value)[source]

Set the Edict property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Edict) – The value to set.
set_property_float(name, value)[source]

Set the float property.

Parameters:
  • name (str) – Name of the property to set.
  • value (float) – The value to set.
set_property_int(name, value)[source]

Set the integer property.

Parameters:
  • name (str) – Name of the property to set.
  • value (int) – The value to set.
set_property_interval(name, value)[source]

Set the Interval property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Interval) – The value to set.
set_property_pointer(name, value)[source]

Set the pointer property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Pointer) – The value to set.
set_property_quaternion(name, value)[source]

Set the Quaternion property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Quaternion) – The value to set.
set_property_short(name, value)[source]

Set the short property.

Parameters:
  • name (str) – Name of the property to set.
  • value (int) – The value to set.
set_property_string(name, value)[source]

Set the string property.

Parameters:
  • name (str) – Name of the property to set.
  • value (str) – The value to set.
set_property_string_pointer(name, value)[source]

Set the string property.

Parameters:
  • name (str) – Name of the property to set.
  • value (str) – The value to set.
set_property_uchar(name, value)[source]

Set the uchar property.

Parameters:
  • name (str) – Name of the property to set.
  • value (int) – The value to set.
set_property_uint(name, value)[source]

Set the uint property.

Parameters:
  • name (str) – Name of the property to set.
  • value (int) – The value to set.
set_property_ushort(name, value)[source]

Set the ushort property.

Parameters:
  • name (str) – Name of the property to set.
  • value (int) – The value to set.
set_property_vector(name, value)[source]

Set the Vector property.

Parameters:
  • name (str) – Name of the property to set.
  • value (Vector) – The value to set.
stop_sound(sample, channel=_engines._sound.Channel.AUTO)[source]

Stop the given sound from being emitted by this entity.

Parameters:
  • sample (str) – Sound file relative to the sounds directory.
  • channel (Channel) – The channel of the sound.
take_damage(damage, damage_type=<DamageTypes.GENERIC: 0>, attacker_index=None, weapon_index=None, hitgroup=<HitGroup.GENERIC: 0>, skip_hooks=False, **kwargs)[source]

Deal damage to the entity.

Parameters:
  • damage (int) – Amount of damage to deal.
  • damage_type (DamageTypes) – Type of the dealed damage.
  • attacker_index (int) – If not None, the index will be used as the attacker.
  • weapon_index (int) – If not None, the index will be used as the weapon. This method also tries to retrieve the attacker from the weapon, if attacker_index wasn’t set.
  • hitgroup (HitGroup) – The hitgroup where the damage should be applied.
  • skip_hooks (bool) – If True, the damage will be dealed directly by skipping any registered hooks.
color

Property to get/set the entity’s color values.

index

Return the entity’s index.

Return type:int
inputs

Iterate over all inputs available for the entity.

keyvalues

Iterate over all entity keyvalues available for the entity.

Note

An entity might also have hardcoded keyvalues that can’t be listed with this property.

model

Property to get/set the entity’s model.

model_header

Return the entity’s model header.

Return type:ModelHeader
outputs

Iterate over all outputs available for the entity.

owner

Return the entity’s owner.

Returns:None if the entity has no owner.
Return type:Entity
parent

Property to get/set the parent of the entity.

properties

Iterate over all descriptors available for the entity.

server_classes

Yield all server classes for the entity.

set_parent

Set the parent of the entity.

Parameters:
  • parent (Pointer) – The parent.
  • attachment (str) – The attachment name/index.
teleport

Change the origin, angle and/or velocity of the entity.

Parameters:
  • origin (Vector) – New location of the entity.
  • angle (QAngle) – New angle of the entity.
  • velocity (Vector) – New velocity of the entity.