Left 4 Dead 2/Scripting/Script Functions/CommandABot

From Valve Developer Community
Jump to: navigation, search
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

Function Description

bool CommandABot(table commandTable)

Issues commands to bots based on a table configuration.

Survivor bots, special infected and common infected can be commanded. The bot's normal AI is disable while it is commanded, and it will blindly follow the command until a new command is issued.

Parameters

Type Name Description
table commandTable Table for passing configuration paramters for the bot command.

Returns

bool - Whether the command was valid. If the command failed, an error message will also be printed to console.

Note.pngNote:Bots may still refuse the command even if it was valid, depending on their programming.

Example

Here is an example of how to create a table that commands all bots to run to position 0,0,0:

commands <-
{
	cmd = DirectorScript.BOT_CMD_MOVE
	pos = Vector( 0,0,0 )
}
----
CommandABot( commands )

// Alternatively, you could send the data inline, like so:

 CommandABot( { cmd = DirectorScript.BOT_CMD_MOVE, pos = Vector( 0,0,0 ) } )

Input Parameters

Passed to the commandTable to set up the command.

Type Name Description
CTerrorPlayer or Infected bot The bot to command. When set to null or not set, all bots are given the command.
int cmd The command enumeation. Required.
Vector pos Where to move in a BOT_CMD_MOVE command.
CBaseEntity target The entity to attack in BOT_CMD_ATTACK or retreat from in BOT_CMD_RETREAT.

Commands

Note.pngNote: The enumerations are only available in the Director scope, to access them outside of Director or mutation scripts, prefix the enumearion with DirectorScript. fore example DirectorScript.BOT_CMD_ATTACK
Enumeration Value Description
BOT_CMD_ATTACK 0 Force the bot to attack a specific target, even bypassingCTerrorPlayer::SetSenseFlags(DirectorScript.BOT_CANT_SEE). Only works on forcing Survivor Bots to attack player-controllable Special Infected, and vice versa.
BOT_CMD_MOVE 1 Force the bot to move to a specific location, which then they will do it unconditionally without performing any other AI behaviors controlled by themselves. This means that Survivor Bots and most player-controllable Special Infected won't attack anything when commanded, but Common Infected still automatically attack enemies if they close in enough.
BOT_CMD_RETREAT 2 Force the bot to retreat from a target entity. Only work when used on Survivor Bots, and if target is a Tank.
BOT_CMD_RESET 3 Removes the active bot command and lets the AI resume controlling the bot.