AI Tutorial
Predator Deathmatch Mode

 

     I'm excited.
     I'm excited because these tutorials are getting really cool. This time we're going to add a new deathmatch mode to the Tutor Bot, which I call Predator Mode. You can rename it, if you like
     In this mode, everyone is invisible. Well, more specifically, you and the bots play as eyeballs, which are quite hard to see and more than a little spooky.
     You really have to creep around slowly, keeping your, eh, eyes open, making sure those bots don't prey on you before you prey on them. That's Predator Mode.
     This lesson is very simple. All we'll be doing is setting everyone's model to the eyes, and then making the bot's aiming a little worse, since he won't see you as well.
     First, scroll down to respawn_bot() until you see this:


// making him normal again
	setmodel(self, "progs/player.mdl");

     Then, replace that little bit with this:

// making him normal again
	if (cvar("deathmatch") == 3)
		setmodel(self, "progs/eyes.mdl");
		else setmodel(self, "progs/player.mdl");

     Next, go down a bit further to create_bot(), where this will appear:

// defining his animation
	setmodel(bot, "progs/player.mdl");

     Just like before, we'll replace that bit with this:

// defining his animation
	if (cvar("deathmatch") == 3)
		setmodel(bot, "progs/eyes.mdl");
		else setmodel(bot, "progs/player.mdl");

     Okay, very simple stuff. Now, if you bring the Quake console down, type "deathmatch 3" and then restart, the bot will appear as those cute and creepy eyeballs.
     Since you'll have a harder time hitting him, we'll make it harder for him to hit you. Scroll up to bot_aim_at_enemy() and replace it with this:

// -------------------------------------
vector() bot_aim_at_enemy =
// -------------------------------------
{
local float chance;

	if (cvar("deathmatch") == 3)
		chance = floor(random() * 10);
		else chance = floor(random() * 4);

	if (chance < 2)
		return normalize(self.enemy.origin - self.origin);
	else if (chance == 2)
		return normalize((self.enemy.origin - '50 0 0') - self.origin);
	else if (chance == 9)
		return normalize((self.enemy.origin - '75 0 0') - self.origin);
	else
		return normalize((self.enemy.origin + '50 0 0') - self.origin);
};

     Now, in Predator Mode, he only has a two in ten chance of aiming perfectly, and sometime he will shoot *way off* to your side.
     You can save that now. We're done with tutor.qc. We have two more changes to make, both in client.qc, where the player is spawned.
     Scroll down to the subroutine PutClientInServer(). Look for the line that says "setmodel (self, "progs/player.mdl");" As you can guess, you'll replace that line with these:

	if (cvar("deathmatch") == 3)
		setmodel(self, "progs/eyes.mdl");
		else setmodel(self, "progs/player.mdl");

     Good work. We only have one change left. Find the subroutine called PlayerPostThink(). At the very end of that, we'll paste this in:

	if (time < 5 && cvar("deathmatch") == 3)
		centerprint(self, "Now playing Predator Mode\n");

     Basically, this is similar to a "message of the day." If you have deathmatch set to three, this message will be printed on your screen for the first five seconds of the game. Kewl, huh?
     Can you guess what time it is? Yup, it's "save-and-compile time." Now you have a new deathmatch mode. Damn, that was easy.
     Keep your eyes peeled.

 


What We Learned

1. Deathmatch is cool; custom rules are better
2. The bot can be adapted to new styles of play
3. A few lines of code can make a whole new game
 


     Author: Coffee
     Questions: coffee@planetquake.com
     AI chat on ICQ: 2716002