Oak Tutorial

Back to Tutorials

Next Lesson

 

Oak Tutorial 5: Picking up items

Lesson Requirements
A C compiler, and the Quake2 Source code

Instructions on using the LCCWin32 Compiler.

Example source code

Lesson Summary

This tutorial covers adding a client field to your bot and allowing it to pickup items. Ok this tutorial is based on how I`ve been writing my bot, you may choose to do it differently, this is only a guideline :) Please remember that this is a ongoing tutorial series, and if something is not explained or done in this one then its probably going to be in the next one.

 Lesson

Ok firstly its worth noting what is not in my code release:

  1. Proper death animations - I consider this a minor aspect which is less important than good roaming AI.
  2. Ability to fire weapons.
  3. Any sort of roaming AI at all.
  4. Decent chase AI.
  5. Bots on scoreboard.

I`ll be adding code to cover most of this in the coming months.

Ok firstly we want to create a cliet field for the bot. We`ll do that by adding this code into the SP_Oak function:

	newOak->client = gi.TagMalloc(sizeof(gclient_t), TAG_GAME);
	if (newOak->client)
	{
		InitClientPersistant(newOak->client);
		InitClientResp(newOak->client);
		strcpy(newOak->client->pers.netname, "Oak");
		strcpy(newOak->client->pers.sounddir, "player/male");
	}
	else
	{
		G_FreeEdict(newOak);
		gi.bprintf (PRINT_HIGH, "Oak Spawn Error, TagMalloc failed\n");		
		return;
	}

So whats this do? Firsly we allcoate some moemory for the client structure using:

newOak->client = gi.TagMalloc(sizeof(gclient_t), TAG_GAME);

 The code then tests to see if the memory was successfully allocated, if so the bot is created, otherwise it is removed. Next change this in g_items.c:

void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
	// Oak changed to allow bots to pickup stuff
	if (strcmp(other->classname, "player"))
		return;

 to:

void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
	// Oak changed to allow bots to pickup stuff
	if ((strcmp(other->classname, "player")) && (strcmp(other->classname, "bot")))
		return;

And there you have it the bot can now pickup items, the next tutorial will show you how to make it look for them.

 Ok if you compile the 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 +set deathmatch 1

Assuming you put the new gamex86.dll in the dir called oak.

 

Back to Tutorials

Next Lesson


Copyright © 1998, John Crickett.
Legal Information