Birds Bot Manager - Tutorial
Sample Code
Note: These are NOT fully functional HalfLife Bots! None of the bots given here have any
intelligence whatsoever. This section is meant only as a starting point for a programmer who wants
to know the fundamentals of writing bot code under BBM.
You will find sample code to a number of simple bots in the bbm/sample_bots
directory. I will briefly describe each of these bots here, and leave it to you to compile and
play with them.
Before compiling any of the sample bots you have to compile the common library
of bot code that they all use. This is in the sample_bots/common directory -
just go there and do a "make" before trying to compile any of the bots. The
result should be a file called common.lib in the common directory.
Instructions for Compiling and loading bots
Each bot directory has its own Makefile - you should be able to just give the
"make" command in each bots directory for it to compile and install under the
HalfLife/bbm directory.
To load a bot into CS after compiling and installing it, create a LAN game of CS, bring down
the console and give the command "loadbot CLASSNAME" (where CLASSNAME
is joinbot, printbot, etc).
Then you can add a bot of that class with the addbot console command.
joinbot
The best way to start off is to write a very simple bot. About the simplest
that you can create is one that knows how to join a game, and then just
stands there oblivious to all else.
This bot looks through its message queue for VGUIMenu messages and knows
how to interpret them (under CounterStrike) as "Join Team" and "Model Select"
messages. For each one, the bot uses the Command() method to send a menuselect
console command to select an option.
printbot
Writing a Bot requires that you know the types of messages that are being sent in the Bots message queue.
To help find out, printbot will helpfully print out all the messages that it receives to the
debug file.
In all other ways this bot is the same as joinbot.
jumpbot
This bot knows how to run around randomly, changing direction whenever it detects that its motion
is blocked, or every few seconds.
It continually scans the area in front of it using TraceLines() to see if there is a low obstacle
that it can try to jump onto/over.
It is otherwise pretty stupid.
ShootBot
This bot tracks the VisibilityChange messages so that it knows what entities are in its field of view.
When it spots an entity that is a "player" on the other team it will fire 3 bullets to let you know. It
makes no attempt to aim at the target, so you should be pretty safe :-)
MenuBot
This bot waits a few seconds and then opens a popup menu on the display of the listenserver with
ShowMenu(). When the player makes a selection, it acknowledges it.
ShowMenu() will fail if there is already a menu open on the listenserver.
Bots as Debugging tools
Apart from just loading & playing with these bots, they can also be used to glean useful
information. For example, to find out exactly what happens when a FlashBang goes off in
the FOV of a bot, you'd load a "shootbot" (because it prints out everything in its FOV
while looking for enemies) and then you throw a grenade so that it lands in front of the
bot and watch the messages to see what happens :-)
When I tried this, I found the following messages:
985434501: Entity 73 team= (weapon_flashbang) () (364.07,2220.37,36.03) is no longer visible
985434504: Entity 75 team= (grenade) () (344.12,2141.32,44.51) is visible
985434506: Entity 73 team= (spark_shower) () (483.93,1864.75,54.97) is visible
985434506: Entity 75 team= (grenade) () (0.00,0.00,0.00) is no longer visible
985434507: Entity 73 team= (spark_shower) () (0.00,0.00,0.00) is no longer visible
You can clearly see when the grenade became visible, and the shower of sparks when
it exploded. It is easy to see how your bot could behave "properly" (i.e. be blinded)
for a few seconds.