Talk:Server-Side Bots/en

From Valve Developer Community
Jump to: navigation, search

ok so here is sort of a walk though of the BotThink() function and my understanding of whats going on.

ok, so what I see here is in sdk_bot_temp.cpp

note: my line numbers are off as I've been commenting the code as I've gone though it; but the numbers should get you to the general area

note2: cmd is command data (ie fake player data so that the bot can move)

line 434 we have the Bot_Think function

line 437 flags the bot as being a bot line 440 declares user command data (bots need to fake being a user) line 441 initializes the command data to be nothing (ie zero)

now we get into bot logic line 447 checks to see if the bot should generate it's own command data ( its not mimicing a command and its not frozen) line 449 sets the cmd.sidemove to a member variable known as M_flSideMove I'm assuming this tells the bot to maintain its current heading

line 451 check to see if the bot is alive and if its solid? (oook...) line 453 calls the Bot_SetForwardMovement function (defined on line 388) the Bot_SetForwardMovement function takes a pointer to the bot and a reference to command data (its a void function that modifies the command data) Bot_SetForwardMovement function tells the bot to move forward and stop when shot

line 456 talks about the bot only turning it has been hurt. I think this is the case. the bot_updateDirection function (line 255) seems rather simplistic (basically checks to see if it should turn to the right based on bool? I'm honestly just skimming it and its getting pretty mathy. The actual results are underwhelming regardless) the Bot_UpdateStrafing function (line 227) basically randomly sets some strafing variables the Bot_ForceFireWeapon seems to try to handle some shooting but i haven't seen the bots shoot when i spawn them. also line 380 is... confusing if you don't know c++ (im not a c++ guy so i needed to get help with that) basically its an if check on bot_forceattack2.GetBool() and then assigns via a bit-wise operation to cmd.buttons. the function Bot_HandleSendCmd is sort of a mystery to me. it has something to do with ConVars and I'm new to the source sdk and I haven't looked into that yet. Bot_HandleRespawn works correctly from my testing. basically the bot respwans itself by sending a jump command (faking like it's hitting spacebar) every once in a while.

ok here is where it gets interesting the function Bot_FlipOut is unneccessary, you can commnet it out (or not) the bot seems to be getting an integer from a convar and if its not 0 then it attacks randomly and spins around? I'm not sure why that's there.

ok so line 486 has a call to the PostClientMessagesSent function (defined in baseentity.cpp) it basicaly just removes flags from the object (nointerp flags) it looks like a cleanup function.

line 490-2 is setting up some more command data

now regardless of if the bot is frozen or not on line 496 frametime is set and RunPlayerMove is called (passing in the computer made command data)

line 199 defines the RunPlayerMove function this apparently simulates a single frame of movement for the bot. it then uses a fakeclient to rum the command data on the bot as if it were a player. (PlayerRunCommand is defined in the player.cpp function)

That seems to be whats happening in the bot think function. not sure how to detect other bots or players to get them to be more responsive, also I need some help getting some hints out to the bots so they know what they should be doing. Maybe the CS:S bots have some more developed code i can look at (anyone else know of some bot code i can look at maybe? i would really like some bots for this project I'm doing).

oh and here is some stuff about cmd.buttons since that stuff looks funny to me. cmd.buttons explanation

so with cmd.buttons you often see operations like this: cmd.buttons |= IN_JUMP; this means we are adding the jump button to all the buttons being pressed this frame. Hardcore c++ guys already know this; but I'm kinda just screwing around here and I don't do a lot of bitwise operations in my work.

also cmd.buttons = 0; clears all button data... atleast so it seems

TL;DR the code generates fake input data and its a very basic implementation of it.

--Hanusa 23:56, 11 March 2013 (PDT)-Hanusa


Any hints on how this could be used to implement the AI code in the HL2 codebase for multiplayer bots that are smart and shoot back? I'm no C++ guru, but I have figured out quite a bit. I just need a lead on where to start. -- CrazyMonkey

What I would do is edit the BotThink() function. -- Pon

Are there any bot coding communitys that work with this code?

Isn't the bot respawn code now implimented in a more recent SDK update? Certainly it is in my code without me adding it. If so, then it should be removed. -- [ICR]


Upon attempting to use the code in an orangebox hl2mp based mod I found that I had to make some changes to get a bot to actually spawn. The file game\server\hl2mp\hl2mp_bot_temp.cpp in the function *BotPutInServer has a commment that needs to be removed at the front of

//ClientPutInServer( pEdict, botname ); 

I also had to add the following in the same file. ( from sdk_bot_temp.cpp )

pPlayer->ChangeTeam( g_iNextBotTeam ); // to set team model.
pPlayer->RemoveAllItems( true );
pPlayer->Spawn();

best place was just before BotNumber++; --Railgun 21:25, 1 Aug 2008 (PDT)


Sample bot doesn't work or isn't available immediately in the Scratch SDK, although the SDK_bot_temp is in the source files. Having modified it to work by copying HL2MP bot and fixing a few bugs, I still couldn't get it to work completely, for exampe bot_mimic does not work. Does anyone have a working version of the SDK bot that they're willing to post on this article? Seems like a pretty basic thing to have. --Mflux 12:55, 21 Dec 2008 (PST)