Have you ever wondered what it's like to be a bot? No? Why not? I think about that a few times a day. Anyway, today we will find out what life is like as a bot. Well, specifically, we will be able to see what a bot sees.
This lesson is a bot camera. You will be able to type an impulse and see what your bot sees. This can be helpful if you need to observe his navigation. Ot it can be just plain cool to look at.
All our work takes place in weapons.qc, so open that. Scroll down to the routine ImpulseCommands(). Before it, paste this:
void() player_stand1; // ------------------------ void() make_bot_cam = // ------------------------ { self.goalentity = find(self.goalentity, classname, "bot"); if (self.goalentity.classname != "bot" || self.goalentity.health <= 0) { msg_entity = self; WriteByte (MSG_ONE, 5); WriteEntity (MSG_ONE, self); WriteByte (MSG_ONE, 10); WriteAngle(MSG_ONE, self.angles_x); WriteAngle(MSG_ONE, self.angles_y); WriteAngle(MSG_ONE, self.angles_z); bprint("Back into your body.\n"); W_SetCurrentAmmo (); player_stand1 (); return; } self.weaponmodel = ""; self.think = bot_cam_think; self.nextthink = time + 0.01; bprint("Looking through "); bprint(self.goalentity.netname); bprint("'s eyes.\n"); };There's a little technical crap in this, but you don't need to know it. The rest is easy. We look for a bot and mark it as the player's self.goalentity. If he already has a bot as a goal entity, it skips to the next bot in the entity list. In other words, we can scroll through all the bots in the game.
// ------------------------ void() bot_cam_think = // ------------------------ { msg_entity = self; WriteByte (MSG_ONE, 5); WriteEntity (MSG_ONE, self.goalentity); WriteByte (MSG_ONE, 10); WriteAngle(MSG_ONE, self.goalentity.angles_x); WriteAngle(MSG_ONE, self.goalentity.angles_y); WriteAngle(MSG_ONE, self.goalentity.angles_z); self.angles = self.goalentity.angles; self.fixangle = TRUE; self.think = bot_cam_think; self.nextthink = time + 0.01; };Yeah, yeah, more dull technical stuff. We're just writing bytes into Quake so the player's viewport will show what the bot sees. Remember, self.goalentity is the current bot.
if (self.impulse == 103) make_bot_cam();Now when you type impulse 103 into the console (or bind it to a key and press it), the bot eye camera will turn on. Easy.