![]() |
bot coding in CS?
Hi Everyone. I would really appreciate some help here;)
Ok, the thing is that I am currently studying C++ and already know quite a bit. But I really want to understand what the code in HL does. you know what I mean. I know C++, but i dont know HL;). What would your tips be for a guy like me wanting to create a bot? Please give me some links if you must;) How did you manage to learn the HL SDK? Its like when I look at a piece of code I know what it does, but I dont know what the variables and stuff are and why and when I must use them i.e pEdict what is that? Its that kind of thing I need to know:) Please help me;) BTW what are some good internet sites to learn C++, I would like some just to have some backup resources for studying:) Thanks in advance MusicMan |
Re: bot coding in CS?
botman recommended http://www.cplusplus.com/
|
Re: bot coding in CS?
I learned the HL BOT code by just looking at it for hours and hours.
Browsing through the code and flowing functions in the code looking up variable names. writing down what they mean or stand for (as i thought as it was), then again looking at it for hours and hours. and browsing more through the code. again absorbing variable and funtion names (etc etc.) After weeks (months) i tried to change one little thingy. Eureka it worked. By then the story repeated it self. Trying to understand the code (what variables mean and where they come from in the code.) Valve VERC botmans forums various other C and C++ sites and now .::Bots United::. Where most helpfull, they all helped me in understanding wtf i was doing. The SDK or Bot code has some comments in them that help also. Reading Botmans "readme" was/is the BEST ever that got me started. Thanks again botman ( I think every body should read that file once before starting to code bots.) I don't think there are tuts about how to code bots. Hence that why we are all here. It is C code rest is just made up variables and funtions by a VALVE coder or botman. Only the comments or the coder him self can explain it. It's all about figuring it out. ???:( ???:( |
Re: bot coding in CS?
Exactly what Cpl. Shrike said !
One thing that may help you first: you must learn to separate the bot variables and the HL engine variables. Everywhere you see an "edict_t" variable, it points to a HL ENTITY. Everywhere you see pEdict->v.somestuff, it points to the variable "somestuff" that belongs to the entity pEdict that is located among the other entities of the game within the HL engine. It means that you can't CHANGE these variable names, but you can read (and sometimes write) into them. Everything in Half-Life is an entity. The map is one big entity (entity number 0), and players, doors, crates and stuff are other small entities that are just spawned on top of the map. Every entity has a set of parameters : a model mesh (the 3D polygons), a bounding box (that is, an invisible box around that entity mostly used for collision checking), although some entities use different parameters than the others, and for some, different means of storing things. For example, the players' mesh models are overriden by their client infobuffer (you'll read about that stuff later, for now, just take the word for it). And the entity #0 (the map) is not linkable to an edict_t pointer. Now in order to keep track of which entity is one of our bots, and since we need additional storage space for putting our own variables for each bot, botman had the idea to "embed" this edict_t pointer into a wider structure : the bot_t structure. Since there can be at max 32 players in a HL game, the bots are an array of 32 bot_t structures. Some of which are filled, some of them are free. bot_t bots[32]; // max of 32 bots in game And their edict_t pointer (pointing to the HL ENTITY that describes this bot) is also stored in this bot_t structure. For example, the HL entity for the 3rd bot in our list is: bots[2].pEdict For convenience, botman uses bot_t pointers instead of indexing the bots array each time : bot_t *pBot = &bots[i]; and so, later on in his functions, you see things like : pBot->pEdict->v.v_angle.x = 0; // reset the pitch view angle of the bot (using the engine variables for the bot entity) because pBot actually is &bots[i]. It is the same as doing : bots[i].pEdict->v.v_angle.x = 0; And if one wants to bind a variable in the bot_t structure (which is located in our bot DLL), one level up of the edict_t structure (which one is located within the engine) : if (bots[bot_number].pBotEnemy != NULL) // does this bot have an enemy ? or you can also do if (pBot->pBotEnemy != NULL) // does this bot have an enemy ? if you're in a function which takes "bot_t *pBot" as a parameter. Somebody feel free to move this to the wiki if needed and comment/correct/fix over it :) |
Re: bot coding in CS?
This headache kills me...
Quote:
If pBot is a pointer to[i] &bots.pEdict then why is it pBot->pEdict->v.v_angle.x = 0; ? |
Re: bot coding in CS?
Pierre meant bot_t *pBot = &bots[i];
:) |
Re: bot coding in CS?
I have only played around a bit with some bot stuff but the line...
Code:
bot_t bots[32]; // max of 32 bots in game that way you can access the bot's data with just a call to ENTINDEX whenever needed. Setting the array size to 32 will allocate space for players 1-31 since 0 is worldspawn it makes it useless. Having it 33 ensures you can index from 1 to 32 with 0 remaining unused. Though thats just from looking at that one line, let me know if I'm wrong about that. |
Re: bot coding in CS?
Uhm no....in botmans template the ENTINDEX != as the bot index. When a bot is created it will just search from 0 to 31 for a free bot slot. That way there is alway enough space
|
Re: bot coding in CS?
Lazy is right, it is best to have the bots array sorted the same way the players are allocated their entities. In my bot I have ENTINDEX (pBotEdict) - 1 == pBot->pEdict (well, I don't use "pBot->pEdict" anymore but you see the idea)
And yeah thanks Rick for fixing my mistake, I meant bot_t *pBot = &bots[i]; rather than &bots[i].pEdict. Go back to school PMB :D |
Re: bot coding in CS?
Quote:
@memed: The PhpHighlight plugin has an error: I needed to put an extra space before all ] signs in the code otherwise they weren't displayed... |
All times are GMT +2. The time now is 00:34. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.