Difference between revisions of "CS:GO Bot Behavior Trees"

From Valve Developer Community
Jump to: navigation, search
m (Removed construction notice (existed for too long) and cleaned up the page a bit.)
(Added back button. Section 'Assigning BTs to Bots'. Section 'Related ConCommands'. ExpandBoxed long code.)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
{{lang|CS:GO Bot Behavior Trees}}
 
{{stub}}
 
{{stub}}
 
{{update}}
 
{{update}}
In {{game name|csgo|name=Counter-Strike: Global Offensive}}, [[bot|bots]] can be given a behavior tree to follow. A behavior tree dictates how the bot senses things (vision, hearing, damage sensing), moves, attacks, and does other actions. They can be customized for the [[Creating a Co-op Strike Map|Co-op gamemode]] (with {{ent|info_enemy_terrorist_spawn}}) and the [[Creating a Guardian Scenario Map|Guardian gamemode]], and are also used internally for [[CS:GO Gamemodes: Deathmatch|Deathmatch]].
+
{{back|Counter-Strike: Global Offensive Level Creation}}
 +
In {{game name|csgo|name=Counter-Strike: Global Offensive}}, [[bot]]s can be given a '''Behavior Tree''' to follow. A behavior tree dictates how the bot senses things (vision, hearing, damage sensing), moves, attacks, and does other actions.
  
Behavior trees were first [https://blog.counter-strike.net/index.php/2019/09/25510/ added to the game] on September 16, 2019. Since September 1, 2020, [https://blog.counter-strike.net/index.php/2020/09/31532/ behavior trees can be packed into BSP files]
+
They use [[Valve|Valve's]] proprietary [[Dota 2 Workshop Tools/KeyValues3|KeyValues3]] format (<code>.kv3</code>), which is a text-based format with somewhat strict syntax. They typically use the <code>bt_</code> prefix, to signify that file is a ''Behavior Tree''. They are stored in <code>csgo/scripts/ai</code>. One can create and use his own behavior trees, see below.
  
They use [[Valve|Valve's]] proprietary [[Dota 2 Workshop Tools/KeyValues3|KeyValues3]] format (<code>.kv3</code>), which is a text-based format with somewhat strict syntax. They typically use the <code>bt_</code> prefix, to signify that file is a ''Behavior Tree''. They are stored in <code>csgo/scripts/ai</code>.
+
Officially, behavior trees are used for the game modes [[File:Csgo icon coopstrike.png|16px|link=]] [[Creating a Co-op Strike Map|Co-op Strike]], [[File:Csgo icon guardian.png|16px|link=]] [[Creating a Guardian Scenario Map|Guardian]] and [[File:Csgo icon deathmatch.png|16px|link=]] [[CS:GO Gamemodes: Deathmatch|Deathmatch]].
  
= Format =
+
Behavior trees were first [https://blog.counter-strike.net/index.php/2019/09/25510/ added to the game] on September 16, 2019. Since September 1, 2020, [https://blog.counter-strike.net/index.php/2020/09/31532/ behavior trees can be packed into BSP files].
 +
 
 +
== Using a Behavior Tree ==
 +
The [[ConVar]] <code>'''mp_bot_ai_bt'''</code> can assign a behavior tree to all bots on the server. Its value is a string representing the path to a .kv3 file, starting from <code>csgo/</code>. For example, the following line is used for official Deathmatch and can be found in <code>csgo/cfg/gamemode_deathmatch.cfg</code>:
 +
<pre>mp_bot_ai_bt "scripts/ai/deathmatch/bt_default.kv3"</pre>
 +
 
 +
For the Co-op game mode, {{ent|info_enemy_terrorist_spawn}} entities have the KeyValue <code>behavior_tree_file</code> that can be used to specify a behavior tree only for bots spawning at this entity.
 +
 
 +
== Related Console Commands ==
 +
{| class=standard-table
 +
! ConVar !! Default Value !! Description
 +
|-
 +
| <code>cv_bot_ai_bt_debug_target</code>
 +
| -1
 +
| Draw the behavior tree of the given bot.
 +
|-
 +
| <code>cv_bot_ai_bt_hiding_spot_show</code>
 +
| 0
 +
| Draw hiding spots.
 +
|-
 +
| <code>cv_bot_ai_bt_moveto_show_next_hiding_spot</code>
 +
| 0
 +
| Draw the hiding spot the bot will check next.
 +
|-
 +
| <code>mp_bot_ai_bt</code>
 +
| ""
 +
| Use the specified behavior tree file to drive the bot behavior.
 +
|-
 +
| <code>mp_bot_ai_bt_clear_cache</code>
 +
| ''ConCommand''
 +
| Clears the cache for behavior tree files.
 +
|}
 +
 
 +
== Format ==
 
The first line of a <code>.kv3</code> file is always a header specifying the KV3 version. For CS:GO, use this header:
 
The first line of a <code>.kv3</code> file is always a header specifying the KV3 version. For CS:GO, use this header:
 
<source lang="javascript">
 
<source lang="javascript">
Line 14: Line 49:
  
  
== Subtrees ==
+
=== Subtrees ===
  
= Commands =
+
== Commands ==
== Control Flow ==
+
=== Control Flow ===
== Movement ==
+
=== Movement ===
== Items ==
+
=== Items ===
== Sensing ==
+
=== Sensing ===
== Other ==
+
=== Other ===
= Examples =
+
== Examples ==
== Default Deathmatch Behavior Tree ==
+
=== Default Deathmatch Behavior Tree ===
Found in <code>csgo/scripts/ai/bt_default.kv3</code>
+
Found in <code>csgo/scripts/ai/bt_default.kv3</code>.
 +
{{ExpandBox|
 
<source lang="javascript"><!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
 
<source lang="javascript"><!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
 
{
 
{
Line 203: Line 239:
 
}
 
}
 
</source>
 
</source>
 +
}}

Latest revision as of 15:05, 29 September 2021

English
Counter-Strike: Global Offensive Level Creation

In Counter-Strike: Global Offensive Counter-Strike: Global Offensive , bots can be given a Behavior Tree to follow. A behavior tree dictates how the bot senses things (vision, hearing, damage sensing), moves, attacks, and does other actions.

They use Valve's proprietary KeyValues3 format (.kv3), which is a text-based format with somewhat strict syntax. They typically use the bt_ prefix, to signify that file is a Behavior Tree. They are stored in csgo/scripts/ai. One can create and use his own behavior trees, see below.

Officially, behavior trees are used for the game modes Csgo icon coopstrike.png Co-op Strike, Csgo icon guardian.png Guardian and Csgo icon deathmatch.png Deathmatch.

Behavior trees were first added to the game on September 16, 2019. Since September 1, 2020, behavior trees can be packed into BSP files.

Using a Behavior Tree

The ConVar mp_bot_ai_bt can assign a behavior tree to all bots on the server. Its value is a string representing the path to a .kv3 file, starting from csgo/. For example, the following line is used for official Deathmatch and can be found in csgo/cfg/gamemode_deathmatch.cfg:

mp_bot_ai_bt "scripts/ai/deathmatch/bt_default.kv3"

For the Co-op game mode, info_enemy_terrorist_spawn entities have the KeyValue behavior_tree_file that can be used to specify a behavior tree only for bots spawning at this entity.

Related Console Commands

ConVar Default Value Description
cv_bot_ai_bt_debug_target -1 Draw the behavior tree of the given bot.
cv_bot_ai_bt_hiding_spot_show 0 Draw hiding spots.
cv_bot_ai_bt_moveto_show_next_hiding_spot 0 Draw the hiding spot the bot will check next.
mp_bot_ai_bt "" Use the specified behavior tree file to drive the bot behavior.
mp_bot_ai_bt_clear_cache ConCommand Clears the cache for behavior tree files.

Format

The first line of a .kv3 file is always a header specifying the KV3 version. For CS:GO, use this header:

<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->


Subtrees

Commands

Control Flow

Movement

Items

Sensing

Other

Examples

Default Deathmatch Behavior Tree

Found in csgo/scripts/ai/bt_default.kv3.