Forum

Bots QC Question

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Bots QC Question

Postby Baker » Fri Jan 29, 2010 8:14 pm

I'm starting to understand QuakeC more as time goes on.

FrikBot

I'd like to configure a server so that there are always 7 bots playing MINUS the total human players.

Issues:

1. First, I'd need a way to count the bots.
2. Second, how do you make it on changelevel so there is a "think" 10 seconds into the map to start adding bots.
3. I guess I'd also need to count the bots to keep them from affecting vote counts.

More or less, I'd need to always keep one slot open and limit the bots to maxplayers - realplayers -1.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby ceriux » Fri Jan 29, 2010 8:44 pm

why not just make a global for players and for bots

for example

maybe something like this?

Code: Select all
void() ClientConnect =
{
   bprint (self.netname);
   bprint (" entered the game\n");
        self.playernum = numplayers;
        numplayers = numplayers +1;

   
// a client connecting during an intermission can cause problems
   if (intermission_running)
      ExitIntermission ();
};


Code: Select all
/*
===========
PutClientInServer

called each time a player is spawned
============
*/
void() DecodeLevelParms;
void() PlayerDie;


void() PutClientInServer =
{
   local   entity spot;

   spot = SelectSpawnPoint ();

   self.classname = "player";
   self.health = 100;
   self.takedamage = DAMAGE_AIM;
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_WALK;
   self.show_hostile = 0;
   self.max_health = 100;
   self.flags = FL_CLIENT;
   self.air_finished = time + 12;
   self.dmg = 2;         // initial water damage
   self.super_damage_finished = 0;
   self.radsuit_finished = 0;
   self.invisible_finished = 0;
   self.invincible_finished = 0;
   self.effects = 0;
   self.invincible_time = 0;
        self.playernum = self.playernum;

   DecodeLevelParms ();
   
   W_SetCurrentAmmo ();

   self.attack_finished = time;
   self.th_pain = player_pain;
   self.th_die = PlayerDie;
   
   self.deadflag = DEAD_NO;
// paustime is set by teleporters to keep the player from moving a while
   self.pausetime = 0;
   
//   spot = SelectSpawnPoint ();

//   self.origin = spot.origin + '0 0 1';
   self.origin = self.oldorigin = spot.origin + '0 0 1';   // 1998-07-21 Respawning where player died fix by Robert Field
   self.angles = spot.angles;
   self.fixangle = TRUE;      // turn this way immediately

// oh, this is a hack!
   setmodel (self, "progs/eyes.mdl");
   modelindex_eyes = self.modelindex;

   setmodel (self, "progs/player.mdl");
   modelindex_player = self.modelindex;

   setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
   
   self.view_ofs = '0 0 22';
   
   self.velocity = '0 0 0';   // 1998-07-21 Player moves after respawn fix by Xian

   player_stand1 ();
   
   if (deathmatch || coop)
   {
      makevectors(self.angles);
      spawn_tfog (self.origin + v_forward*20);
   }

   spawn_tdeath (self.origin, self);
};



i *think* something like this should work. at least for counting th players.

basically if i did this right, playernum is the players number it gives him a numeric id. and playernums is a global that keeps track of how many players there are (in clientdisconnect id add numplayers -1) or something. this is probably wrong. but im sure im on track of what should be done to keep track of how many players there are in the server you may not even need to keep track of each players number so all you should need is player global "numplayers" and just have it increase and decrease on player connect and disconnect. for each player thats added call an impulse to remove 1 bot and visa versa. give me the src for frik bot and ill see what i can come up with if you want?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Bots QC Question

Postby Junrall » Sat Jan 30, 2010 3:38 am

Baker wrote:I'm starting to understand QuakeC more as time goes on.

FrikBot

I'd like to configure a server so that there are always 7 bots playing MINUS the total human players.

Issues:

1. First, I'd need a way to count the bots.
2. Second, how do you make it on changelevel so there is a "think" 10 seconds into the map to start adding bots.
3. I guess I'd also need to count the bots to keep them from affecting vote counts.

More or less, I'd need to always keep one slot open and limit the bots to maxplayers - realplayers -1.



I have been slicing away at the Frikbot's innards for a few weeks now... I'm not a Frikbot specialist by no means! However, maybe I can point you in the right directions...

1. First, I'd need a way to count the bots.
First, look in the BotConnect function for self.ishuman = 2; I beleive that you can use this to determine which player is a bot. There are many instances throughout bot.qc that performs this check. Also, nextent is used often to cycle through the player entities for various checks.. such as performing certain tasks only on bots... check out the BotFrame function. So, you could cycle through the player entities with nextent and check each entity with if (self.ishuman == FALSE) to see if it is a bot... now I could be wrong here, but I think the self.ishuman = 2 from the BotConnect function gets changed to self.ishuman = FALSE right after the bot enters the level.

2. Second, how do you make it on changelevel so there is a "think" 10 seconds into the map to start adding bots.
Here is what I did... I'm not sure if this is this the best way... but it does work.
At the top of bot.qc add:
Code: Select all
float botreturntime;

Then goto BotInit and at the top of that add:
Code: Select all
botreturntime = time + 10;

And finally at the bottom of BotFrame... replace:
Code: Select all
if (saved_bots)
      bot_return();

with:
Code: Select all
if (saved_bots && time >= botreturntime)
      bot_return();

The botreturntime = time + 10; is what tells quake to wait for "time + 10" before spawning any bots. In this case 10 was about 30 seconds or so. You'll want to increase this for more time.

3. I guess I'd also need to count the bots to keep them from affecting vote counts.
As far as this one goes... again, you could use nextent and self.ishuman to count the bots.

Hope this helps!
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest