Today, I'm not gonna be shy, and I'm not gonna be ambiguous: I got a damn good tutorial for you. In fact, it's probably the third of my greatest hits, behind coffee_move() and the hybrid velocity code.
Your bot will soon learn how to run for cover. I don't care what you've read, no other bot does this. He will actually back up to find a wall or column and hide behind it. This is not a script, and it's not a hack. It works.
On top of that, like most of my best code, it's short and simple. It comes in just one subroutine. We want to put it before the one called bot_strafe(). So, find that now and paste this before it:
// ------------------------------------------------------- void() run_for_cover = // ------------------------------------------------------- { if (!visible(self.enemy) && random() < 0.9) return; if (time > self.attack_finished && self.enemy.health > 0) self.th_missile(); bot_face(); if (self.lefty == 0) if (walkmove (self.angles_y - 180, 20) == TRUE) return; self.lefty = 0; if (walkmove (self.angles_y + self.button1, 20)) return; self.lefty = 1; if (walkmove (self.angles_y, 20) == TRUE) return; };Heehee. I love this stuff. Okay, the first part says this: if I cannot see my enemy, then he cannot see me, so if I feel like it, I'll stay hidden. The second part: if I'm ready to attack and my enemy is still alive, I'll shoot. Next: I'll face my enemy.
// ---------------------- void() bot_strafe = // ---------------------- { // this routine is called every frame during combat, // so he strafes and dodges even while shooting bot_check_ammo();After that, we would add this:
if (self.enemy.weapon == IT_ROCKET_LAUNCHER) { run_for_cover(); return; }Here he would just run for cover and leave the subroutine. A couple notes about run_for_cover(). One, there is a byproduct that I've never been able to change. After the bot hits a corner, if he is still visible, he will run along that wall, toward the enemy. I don't consider this a bug, because it just happens as a result of cornering.
if (!visible(self.enemy)) { movetogoal(20); return; }Here, if he cannot see his enemy, he will try to chase him. For obvious reasons, you could not execute something like this and run_for_cover(), because there, if he is not visible, he tries to stay that way.