Bot Fraglimits

 

      Man is this an overdue lesson.
      I've been meaning to write this one for months now. It is rather fundamental, and important as well. This will allow your bots to "win games." That is, if he reaches the fraglimit set through the console then the Quake will exit to the intermission screen, just like regular servers.
      Lucky for us, this tutorial is butt-simple. In fact, it doesn't even require a new subroutine. All we have to do is call the player routine named CheckRules(), which is found in client.qc. This of course checks the player's frags and the time. Here, it looks like this:


/*
============
CheckRules

Exit deathmatch games upon conditions
============
*/
void() CheckRules =
{
	local	float		timelimit;
	local	float		fraglimit;

	if (gameover)	// someone else quit the game already
		return;

	timelimit = cvar("timelimit") * 60;
	fraglimit = cvar("fraglimit");

	if (timelimit && time >= timelimit)
	{
		NextLevel ();
		return;
	}
	
	if (fraglimit && self.frags >= fraglimit)
	{
		NextLevel ();
		return;
	}	
};

      I believe this is self-explanatory. The cool thing about this routine is that it contains no is player-only code. This allows the bot to use it. Cool.
      CheckRules() is called from the routine PlayerPreThink(), which means that the rules are checked before every frame. I don't think we have to check them this often for bots. After all, he will probably only earn frags during battle. Thus, we will choose for our purposes now to check our rules from the subroutine bot_run(). There you will see this code:

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void() bot_run =
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{

// his fighting thoughts. after a short while, he'll give up 
// on his enemy, but if he can see him, he'll always attack

	if (!(self.flags & FL_ONGROUND))
		return;

	check_for_water();

	if (visible(self.enemy))
		self.search_time = time + 6;

      Add the following after that:

	CheckRules();

      Done. You may elect to call this routine more often. You could even call it from the routine bot_walk(), which means it would be called during every one of the bot's frames. I think this works fine. Oh, and remember to set the variabes "fraglimit" or "timelimit" through the console.
      I think this must be the shortest QuakeC tutorial in history. You might be wondering why it was neccessary for me to even write a one-line lesson; I would respond by saying that it is very important -- and quite fun -- for the bot to be able to win a game. Not all bot's do this now. That's all.

 


What We Learned

1. Some player routines can be called by bots
2. Bot should affect a server or game just like players do
3. Console variables can be nifty

 


Author: Coffee
AI chat on ICQ: 2716002
Return to home