| Oak Tutorial | |
Oak Tutorial 1: Spawning |
Lesson Requirements
A C compiler., and the Quake2 Source code
Instructions on using the LCCWin32 Compiler.
Lesson Summary
A quick intro to Spawning a bot in Quake2.
Lesson
Ok I`ve now had a few days to play with the source code and have begun writing my bot. As I get further on with it I`ll be writing these tutorials explaining how it all works. In this one I`ll show you the bot spawn code I currently have, though do remember this will change. Heres the spawn function which is in my src file oak.c. NOTE you can not cut and paste this code from HTML!
/************************************************
*
* Function: SP_Oak
*
* Description: spawns a oak bot
*
* Arguements:
* void
*
* Returns:
* void
*
*************************************************/
void SP_Oak(void)
{
edict_t *newOak;
vec3_t spawn_origin, spawn_angles;
// spawn the bot on a spawn spot
newOak = G_Spawn();
SelectSpawnPoint (spawn_origin, spawn_angles);
VectorCopy (spawn_origin, newOak->s.origin);
newOak->s.origin[2] += 1; // make sure off ground
newOak->classname = "bot";
newOak->takedamage = DAMAGE_AIM;
newOak->movetype = MOVETYPE_STEP;
newOak->mass = 200;
newOak->solid = SOLID_BBOX;
newOak->deadflag = DEAD_NO;
newOak->clipmask = MASK_PLAYERSOLID;
newOak->model = "players/male/tris.md2";
newOak->s.modelindex = 255;
newOak->s.modelindex2 = 255; // custom gun model
newOak->s.frame = 0;
newOak->waterlevel = 0;
newOak->watertype = 0;
newOak->health = 100;
newOak->max_health = 100;
newOak->gib_health = -40;
// think functions
newOak->pain = oak_pain;
newOak->die = oak_die;
VectorSet (newOak->mins, -16, -16, -24);
VectorSet (newOak->maxs, 16, 16, 32);
VectorClear (newOak->velocity);
gi.linkentity (newOak);
gi.bprintf (PRINT_HIGH, "A Oak bot has entered the game\n");
}
This code is fairly self explanatory. The function begins with some variable declarations. The next four lines create a entity, selects a spawn spot, and move the bots origin to the spawn spot. The next block set a number of the entities attirubtes all of which are fairly obvious. I`m going to skip the rest of the code unitl next time. but please note, that you must call the line:
gi.linkentity (newOak);
Otherwise you`ll not have much luck. Next you`ll need to add this code:
void SP_Oak(void);
At the top of the file, beneath the #include statements.
else if (Q_stricmp (cmd, "oak") == 0) SP_Oak(ent);
After line 637 of g_cmds.c (preceeding line is):
else if (Q_stricmp (cmd, "wave") == 0) Cmd_Wave_f (ent);
Ok if you compile that code in with the id code you can then spawn a bot by typing cmd oak in the console. Remember you must run quake with the command line:
quake2 +set game oak
Assuming you put the new gamex86.dll in the dir called oak.
Copyright © 1997, John Crickett.
Legal Information