client.py#

class sc2.client.Client(ws, save_replay_path: str = None) None[source]#
Parameters:

save_replay_path (str)

async chat_send(message: str, team_only: bool) None[source]#

Writes a message to the chat

Parameters:
  • message (str)

  • team_only (bool)

Return type:

None

async debug_all_resources() None[source]#

Gives 5000 minerals and 5000 vespene to the bot.

Return type:

None

debug_box2_out(pos: Unit | Point3, half_vertex_length: float = 0.25, color: tuple | list | Point3 = None) None[source]#

Draws a box center at a position ‘pos’, with box side lengths (vertices) of two times ‘half_vertex_length’.

Parameters:
Return type:

None

debug_box_out(p_min: Unit | Point3, p_max: Unit | Point3, color: tuple | list | Point3 = None) None[source]#

Draws a box with p_min and p_max as corners of the box.

Parameters:
Return type:

None

async debug_control_enemy() None[source]#

Allows control over enemy units and structures similar to team games control - does not allow the bot to spend the opponent’s ressources. Using it a second time disables it again.

Return type:

None

async debug_cooldown() None[source]#

Disables cooldowns of unit abilities for the bot. Using it a second time disables it again.

Return type:

None

async debug_create_unit(unit_spawn_commands: list[list[UnitTypeId | int | Point2 | Point3]]) None[source]#

Usage example (will spawn 5 marines in the center of the map for player ID 1): await self._client.debug_create_unit([[UnitTypeId.MARINE, 5, self._game_info.map_center, 1]])

Parameters:

unit_spawn_commands (list[list[UnitTypeId | int | Point2 | Point3]])

Return type:

None

async debug_fast_build() None[source]#

Sets the build time of units and structures and upgrades to zero. Using it a second time disables it again.

Return type:

None

async debug_food() None[source]#

Should disable food usage (does not seem to work?). Using it a second time disables it again.

Return type:

None

async debug_free() None[source]#

Units, structures and upgrades are free of mineral and gas cost. Using it a second time disables it again.

Return type:

None

async debug_gas() None[source]#

Gives 5000 vespene to the bot. This does not seem to be working.

Return type:

None

async debug_god() None[source]#

Your units and structures no longer take any damage. Using it a second time disables it again.

Return type:

None

async debug_hang(delay_in_seconds: float) None[source]#

Freezes the SC2 client. Not recommended to be used.

Parameters:

delay_in_seconds (float)

Return type:

None

async debug_kill_unit(unit_tags: Unit | Units | list[int] | set[int]) None[source]#
Parameters:

unit_tags (Unit | Units | list[int] | set[int])

Return type:

None

debug_line_out(p0: Unit | Point3, p1: Unit | Point3, color: tuple | list | Point3 = None) None[source]#

Draws a line from p0 to p1.

Parameters:
Return type:

None

async debug_minerals() None[source]#

Gives 5000 minerals to the bot.

Return type:

None

async debug_set_unit_value(unit_tags: Iterable[int] | Units | Unit, unit_value: int, value: float) None[source]#

Sets a “unit value” (Energy, Life or Shields) of the given units to the given value. Can’t set the life of a unit to 0, use “debug_kill_unit” for that. Also can’t set the life above the unit’s maximum. The following example sets the health of all your workers to 1: await self.debug_set_unit_value(self.workers, 2, value=1)

Parameters:
  • unit_tags (Iterable[int] | Units | Unit)

  • unit_value (int)

  • value (float)

Return type:

None

async debug_show_map() None[source]#

Reveals the whole map for the bot. Using it a second time disables it again.

Return type:

None

debug_sphere_out(p: Unit | Point3, r: float, color: tuple | list | Point3 = None) None[source]#

Draws a sphere at point p with radius r.

Parameters:
Return type:

None

async debug_tech_tree() None[source]#

Removes all tech requirements (e.g. can build a factory without having a barracks). Using it a second time disables it again.

Return type:

None

debug_text_screen(text: str, pos: Point2 | Point3 | tuple | list, color: tuple | list | Point3 = None, size: int = 8) None[source]#

Draws a text on the screen (monitor / game window) with coordinates 0 <= x, y <= 1.

Parameters:
  • text (str)

  • pos (Point2 | Point3 | tuple | list)

  • color (tuple | list | Point3)

  • size (int)

Return type:

None

debug_text_simple(text: str) None[source]#

Draws a text in the top left corner of the screen (up to a max of 6 messages fit there).

Parameters:

text (str)

Return type:

None

debug_text_world(text: str, pos: Unit | Point3, color: tuple | list | Point3 = None, size: int = 8) None[source]#

Draws a text at Point3 position in the game world. To grab a unit’s 3d position, use unit.position3d Usually the Z value of a Point3 is between 8 and 14 (except for flying units). Use self.get_terrain_z_height() from bot_ai.py to get the Z value (height) of the terrain at a 2D position.

Parameters:
Return type:

None

async debug_upgrade() None[source]#

Researches all currently available upgrades. E.g. using it once unlocks combat shield, stimpack and 1-1. Using it a second time unlocks 2-2 and all other upgrades stay researched.

Return type:

None

async dump_data(ability_id: bool = True, unit_type_id: bool = True, upgrade_id: bool = True, buff_id: bool = True, effect_id: bool = True) None[source]#

Dump the game data files choose what data to dump in the keywords this function writes to a text file call it one time in on_step with: await self._client.dump_data()

Parameters:
  • ability_id (bool)

  • unit_type_id (bool)

  • upgrade_id (bool)

  • buff_id (bool)

  • effect_id (bool)

Return type:

None

async leave() None[source]#

You can use ‘await self.client.leave()’ to surrender midst game.

Return type:

None

async move_camera(position: Unit | Units | Point2 | Point3) None[source]#

Moves camera to the target position

Parameters:

position (Unit | Units | Point2 | Point3)

Return type:

None

async move_camera_spatial(position: Point2 | Point3) None[source]#

Moves camera to the target position using the spatial aciton interface

Parameters:

position (Point2 | Point3)

Return type:

None

async obs_move_camera(position: Unit | Units | Point2 | Point3) None[source]#

Moves observer camera to the target position. Only works when observing (e.g. watching the replay).

Parameters:

position (Unit | Units | Point2 | Point3)

Return type:

None

async query_available_abilities(units: list[Unit] | Units, ignore_resource_requirements: bool = False) list[list[AbilityId]][source]#

Query abilities of multiple units

Parameters:
  • units (list[Unit] | Units)

  • ignore_resource_requirements (bool)

Return type:

list[list[AbilityId]]

async query_available_abilities_with_tag(units: list[Unit] | Units, ignore_resource_requirements: bool = False) dict[int, set[AbilityId]][source]#

Query abilities of multiple units

Parameters:
  • units (list[Unit] | Units)

  • ignore_resource_requirements (bool)

Return type:

dict[int, set[AbilityId]]

async query_building_placement(ability: AbilityData, positions: list[Point2 | Point3], ignore_resources: bool = True) list[ActionResult][source]#

This function might be deleted in favor of the function above (_query_building_placement_fast).

Parameters:
Return type:

list[ActionResult]

async query_pathing(start: Unit | Point2 | Point3, end: Point2 | Point3) int | float | None[source]#

Caution: returns “None” when path not found Try to combine queries with the function below because the pathing query is generally slow.

Parameters:
Return type:

int | float | None

async query_pathings(zipped_list: list[list[Unit | Point2 | Point3]]) list[float][source]#

Usage: await self.query_pathings([[unit1, target2], [unit2, target2]]) -> returns [distance1, distance2] Caution: returns 0 when path not found

Parameters:

zipped_list (list[list[Unit | Point2 | Point3]])

Return type:

list[float]

async quick_load() None[source]#
Return type:

None

Loads the game state from the previously stored in-memory bookmark. Caution:

  • The SC2 Client will crash if the game wasn’t quicksaved

  • The bot step iteration counter will not reset

  • self.state.game_loop will be set to zero after the quickload, and self.time is dependant on it

async quick_save() None[source]#

Saves the current game state to an in-memory bookmark. See: Blizzard/s2client-proto

Return type:

None

async step(step_size: int = None)[source]#

EXPERIMENTAL: Change self._client.game_step during the step function to increase or decrease steps per second

Parameters:

step_size (int)

async toggle_autocast(units: list[Unit] | Units, ability: AbilityId) None[source]#

Toggle autocast of all specified units

Parameters:
Return type:

None