players._base module

Provides a class used to interact with a specific player.

class players._base.Player(index)[source]

Bases: entities._base.Entity

Class used to interact directly with players.

__init__(index)[source]

Initialize the object.

Parameters:index (int) – A valid player index.
Raises:ValueError – Raised if the index is invalid.
ban(duration=0, kick=True, write_ban=True)[source]

Ban a player from the server.

Parameters:
  • duration (int) – Duration of the ban in minutes. Use 0 for permament.
  • kick (bool) – If True, the player will be kicked as well.
  • write_ban (bool) – If True, the ban will be written to cfg/banned_users.cfg.
client_command(command, server_side=False)[source]

Execute a command on the client.

Parameters:
  • command (str) – The command to execute.
  • server_side (bool) – If True the command will be emulated by the server.
classmethod from_userid(userid)[source]

Create an instance from a userid.

Parameters:userid (int) – The userid.
Return type:Player
get_active_weapon()[source]

Return the player’s active weapon.

Returns:None if the player does not have an active weapon.
Return type:Weapon
get_eye_location()[source]

Return the player’s eye location.

Return type:Vector
get_flashlight()[source]

Return whether or not the flashlight of the player is turned on.

Return type:bool
get_frozen()[source]

Return whether frozen mode is enabled.

Return type:bool
get_godmode()[source]

Return whether god mode is enabled.

Return type:bool

Todo

Add m_takedamage to the data files. Which name do we want to use? We can’t use take_damage.

get_jetpack()[source]

Return whether jetpack mode is enabled.

Return type:bool
get_name()[source]

Return the player’s name.

Return type:str
get_noblock()[source]

Return whether noblock mode is enabled.

Return type:bool
get_noclip()[source]

Return whether noclip mode is enabled.

Return type:bool
get_projectile_ammo(projectile)[source]

Return the player’s ammo value of the given projectile.

Parameters:projectile (str) – The name of the projectile to get the ammo of.
Return type:int
get_stuck()[source]

Return whether stuck mode is enabled.

Return type:bool
get_team()[source]

Return the player’s team.

Return type:int
get_trace_ray(mask=<ContentMasks.ALL: 4294967295>, trace_filter=None)[source]

Return the player’s current trace data.

Parameters:
Return type:

GameTrace

get_view_angle()[source]

Return the player’s view angle.

Return type:QAngle
get_view_coordinates()[source]

Return the coordinates the player is currently looking at.

Return None if the player is not looking at anything.

Return type:Vector
get_view_entity()[source]

Return the entity that the player is looking at.

Return None if the player is not looking at an entity.

Return type:Entity
get_view_player()[source]

Return the player that the player is looking at.

Return None if the player is not looking at a player.

Return type:Player
get_weapon(classname=None, is_filters=None, not_filters=None)[source]

Return the first found weapon for the given arguments.

Return type:Weapon
has_c4()[source]

Raise an error because this method is game specific.

is_bot()[source]

Return whether the player is a bot.

Return type:bool
is_connected()[source]

Return whether the player is connected.

Return type:bool
is_fake_client()[source]

Return whether the player is a fake client.

Return type:bool
is_hltv()[source]

Return whether the player is HLTV.

Return type:bool
is_in_a_vehicle()[source]

Return whether the player is in a vehicle.

Return type:bool
is_muted(receivers=None)[source]

Return True if the player is currently muted.

See players.voice.mute_manager.is_muted for more information.

is_observer()[source]

Return whether the player is an observer.

Return type:bool
is_weapon_restricted(weapon)[source]

Return whether the player is restricted from the given weapon. :param str weapon: The name of the weapon to check against restriction. :rtype: bool

kick(message='')[source]

Kick the player from the server.

Parameters:message (str) – A message the kicked player will receive.
mute(receivers=None)[source]

Mute the player.

See players.voice.mute_manager.mute_player for more information.

play_sound(sample, 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]

Play a sound to the player.

Parameters:
  • sample (str) – Sound file relative to the “sounds” directory.
  • 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.
projectile_indexes(projectile)[source]

Yield all indexes of the given projectile for the player.

Parameters:projectile (str) – The name of the projectile to find indexes of.
push(horiz_mul, vert_mul, vert_override=False)[source]

Push the player along his view vector.

Parameters:
  • horiz_mul (float) – Horizontal multiplier.
  • vert_mul (float) – Vertical multiplier.
  • vert_override (bool) – If True vert_mul will be used as a static value and not as a multiplier.
restrict_weapons(*weapons)[source]

Restrict the weapon for the player. :param str weapons: A weapon or any number of weapons to add

as restricted for the player.
say(message)[source]

Force the player to say something in the global chat.

Parameters:message (str) – The text the player should say.
say_team(message)[source]

Force the player to say something in the team chat.

Parameters:message (str) – The text the player should say.
send_convar_value(cvar_name, value)[source]

Send a convar value.

Parameters:
  • cvar_name (str) – Name of the convar.
  • value (str) – Value to send.
set_active_weapon(weapon)[source]

Set the player’s active weapon.

Parameters:weapon (Weapon) – The weapon to set as active.
set_eye_location(eye_location)[source]

Set the player’s eye location.

set_flashlight(enable)[source]

Turn on/off the flashlight of the player.

Parameters:enable (bool) – True to turn on, False to turn off.
set_frozen(enable)[source]

Enable/disable frozen mode.

Frozen mode makes the player unable to move, look and shoot.

Parameters:enable (bool) – If True frozen mode will be enabled.
set_godmode(enable)[source]

Enable/disable god mode.

Godmode makes the player invulnerable.

Parameters:enable (bool) – If True god mode will be enabled.

Todo

Add m_takedamage to the data files. Which name do we want to use? We can’t use take_damage.

set_jetpack(enable)[source]

Enable/disable jetpack mode.

Jetpack mode gives the player the ability to use a jetpack.

Parameters:enable (bool) – If True jetpack mode will be enabled.
set_name(name)[source]

Set the player’s name.

set_noblock(enable)[source]

Enable/disable noblock mode.

Noblock mode assigns a new collision group to the player that doesn’t block other players. That means players can run through each other.

Parameters:enable (bool) – If True noblock mode will be enabled.
set_noclip(enable)[source]

Enable/disable noclip mode.

Noclip mode gives the player the ability to fly through the map.

Parameters:enable (bool) – If True noclip mode will be enabled.
set_projectile_ammo(projectile, value)[source]

Set the player’s ammo value for the given projectile.

Parameters:
  • projectile (str) – The name of the projectile to set the ammo of.
  • value (int) – The value to set the projectile’s ammo to.
set_stuck(enable)[source]

Enable/disable stuck mode.

Stuck mode forces the player to stay exactly at his current position even if he is currently in the air. He’s still able to look and shoot.

Parameters:enable (bool) – If True stuck mode will be enabled.
set_team(value)[source]

Set the players team.

set_view_angle(angle)[source]

Set the player’s view angle.

set_view_coordinates(coords)[source]

Force the player to look at the given coordinates.

Parameters:coords (Vector) – The coordinates the player should look at.
set_view_entity(entity)[source]

Force the player to look at the origin of the given entity.

Parameters:entity (Entity) – The entity the player should look at.
set_view_player(player)[source]

Force the player to look at the other player’s eye location.

Parameters:player (Player) – The other player.
slay()[source]

Slay the player.

spawn(force=False)[source]

Spawn the player.

Parameters:force (bool) – Whether or not the spawn should be forced.
unmute(receivers=None)[source]

Unmute the player.

See players.voice.mute_manager.unmute_player for more information.

unrestrict_weapons(*weapons)[source]

Restrict the weapon for the player. :param str weapons: A weapon or any number of weapons to remove

as restricted for the player.
weapon_indexes(classname=None, is_filters=None, not_filters=None)[source]

Iterate over the player’s weapon indexes for the given arguments.

Returns:A generator of indexes
Return type:generator
weapons(classname=None, is_filters=None, not_filters=None)[source]

Iterate over the player’s weapons for the given arguments.

Returns:A generator of weapons.entity.Weapon objects
Return type:generator
active_weapon

Return the player’s active weapon.

Returns:None if the player does not have an active weapon.
Return type:Weapon
address

Return the player’s IP address and port.

If the player is a bot, an empty string will be returned.

Returns:The IP address. E.g. ‘127.0.0.1:27015’
Return type:str
base_client

Return the player’s players.BaseClient object.

client

Return the player’s players.Client object.

drop_weapon

Drop a weapon.

Parameters:
  • weapon (Pointer) – Weapon to drop.
  • target (Vector) – Target location to drop the weapon at.
  • velocity (Vector) – Velocity to use to drop the weapon.
eye_location

Return the player’s eye location.

Return type:Vector
flashlight

Return whether or not the flashlight of the player is turned on.

Return type:bool
frozen

Return whether frozen mode is enabled.

Return type:bool
godmode

Return whether god mode is enabled.

Return type:bool

Todo

Add m_takedamage to the data files. Which name do we want to use? We can’t use take_damage.

jetpack

Return whether jetpack mode is enabled.

Return type:bool
language

Return the player’s language.

If the player is a bot, an empty string will be returned.

Return type:str
name

Return the player’s name.

Return type:str
noblock

Return whether noblock mode is enabled.

Return type:bool
noclip

Return whether noclip mode is enabled.

Return type:bool
permissions

Return the player’s auth.manager.PlayerPermissions object.

playerinfo

Return the player’s PlayerInfo object.

primary

Return the player’s primary weapon.

Return type:Weapon
secondary

Return the player’s secondary weapon.

Return type:Weapon
spectators

Return all players observing this player. :return: The generator yields players.entity.Player objects. :rtype: generator

steamid

Return the player’s SteamID.

Return type:str
stuck

Return whether stuck mode is enabled.

Return type:bool
team

Return the player’s team.

Return type:int
uniqueid

Return the player’s uniqueid.

userid

Return the player’s userid.

Return type:int
view_angle

Return the player’s view angle.

Return type:QAngle
view_coordinates

Return the coordinates the player is currently looking at.

Return None if the player is not looking at anything.

Return type:Vector
view_entity

Return the entity that the player is looking at.

Return None if the player is not looking at an entity.

Return type:Entity
view_player

Return the player that the player is looking at.

Return None if the player is not looking at a player.

Return type:Player
view_vector

Return the view vector of the player. :rtype: Vector

players._base._find_weapon_prop_length(table)[source]

Loop through a prop table to find the myweapons property length.