client.py
- class sc2.client.Client(ws, save_replay_path=None)
- async chat_send(message, team_only)
Writes a message to the chat
- async debug_all_resources()
Gives 5000 minerals and 5000 vespene to the bot.
- debug_box2_out(pos, half_vertex_length=0.25, color=None)
Draws a box center at a position ‘pos’, with box side lengths (vertices) of two times ‘half_vertex_length’.
- debug_box_out(p_min, p_max, color=None)
Draws a box with p_min and p_max as corners of the box.
- async debug_control_enemy()
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.
- async debug_cooldown()
Disables cooldowns of unit abilities for the bot. Using it a second time disables it again.
- async debug_create_unit(unit_spawn_commands)
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
[Union
[UnitTypeId
,int
,Point2
,Point3
]]])
- async debug_fast_build()
Sets the build time of units and structures and upgrades to zero. Using it a second time disables it again.
- async debug_food()
Should disable food usage (does not seem to work?). Using it a second time disables it again.
- async debug_free()
Units, structures and upgrades are free of mineral and gas cost. Using it a second time disables it again.
- async debug_gas()
Gives 5000 vespene to the bot. This does not seem to be working.
- async debug_god()
Your units and structures no longer take any damage. Using it a second time disables it again.
- async debug_hang(delay_in_seconds)
Freezes the SC2 client. Not recommended to be used.
- debug_line_out(p0, p1, color=None)
Draws a line from p0 to p1.
- async debug_minerals()
Gives 5000 minerals to the bot.
- async debug_set_unit_value(unit_tags, unit_value, value)
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)
- async debug_show_map()
Reveals the whole map for the bot. Using it a second time disables it again.
- debug_sphere_out(p, r, color=None)
Draws a sphere at point p with radius r.
- async debug_tech_tree()
Removes all tech requirements (e.g. can build a factory without having a barracks). Using it a second time disables it again.
- debug_text_screen(text, pos, color=None, size=8)
Draws a text on the screen (monitor / game window) with coordinates 0 <= x, y <= 1.
- debug_text_simple(text)
Draws a text in the top left corner of the screen (up to a max of 6 messages fit there).
- debug_text_world(text, pos, color=None, size=8)
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:
text (
str
)color (
Union
[tuple
,list
,Point3
])size (
int
)
- async debug_upgrade()
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.
- async dump_data(ability_id=True, unit_type_id=True, upgrade_id=True, buff_id=True, effect_id=True)
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()
- async leave()
You can use ‘await self.client.leave()’ to surrender midst game.
- async move_camera(position)
Moves camera to the target position
- async move_camera_spatial(position)
Moves camera to the target position using the spatial aciton interface
- async obs_move_camera(position)
Moves observer camera to the target position. Only works when observing (e.g. watching the replay).
- async query_available_abilities(units, ignore_resource_requirements=False)
Query abilities of multiple units
- Return type:
List
[List
[AbilityId
]]
- async query_available_abilities_with_tag(units, ignore_resource_requirements=False)
Query abilities of multiple units
- Return type:
Dict
[int
,Set
[AbilityId
]]
- async query_building_placement(ability, positions, ignore_resources=True)
This function might be deleted in favor of the function above (_query_building_placement_fast).
- Parameters:
ability (
AbilityData
)ignore_resources (
bool
)
- Return type:
List
[ActionResult
]
- async query_pathing(start, end)
Caution: returns “None” when path not found Try to combine queries with the function below because the pathing query is generally slow.
- async query_pathings(zipped_list)
Usage: await self.query_pathings([[unit1, target2], [unit2, target2]]) -> returns [distance1, distance2] Caution: returns 0 when path not found
- async quick_load()
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()
Saves the current game state to an in-memory bookmark. See: https://github.com/Blizzard/s2client-proto/blob/eeaf5efaea2259d7b70247211dff98da0a2685a2/s2clientprotocol/sc2api.proto#L93
- async step(step_size=None)
EXPERIMENTAL: Change self._client.game_step during the step function to increase or decrease steps per second