Tutorial Create Bot AI for Zombies

NightwalkerLots

Well-Known Member
Messages
8
Reaction score
0
Points
201
Resources

//Needed for most of the function calls done on the bot
#include scripts\shared\bots\_bot;
#include scripts\shared\laststand_shared;

//GSC source for in-game bot code to reference how certain functions can be used
Please, Log in or Register to view URLs content!


//Video showcasing some bot behavior at work. To see what all is possible, or at least what I've done with bot ai so far.


Behavior
First of all,
Code:
add_bot() {
   bot = AddTestClient();
}

I won't reveal all I've made. But the simplest thing to get the bot to do is have them revive players because it's an in-game function.
Here's just an example,


Code:
Foreach( player in level.players ) {
if ( player laststand::player_is_in_laststand() ) { in_need = player; } else { in_need = undefined; }
if( player IsTestClient() ) { bot = player; }
if( isdefined( in_need ) ) { bot bot::revive_player(in_need); bot.is_reviving_player = true; }
}

Obviously, you can make more complex AI to prioritize reviving over other behaviors as I have. But something like this is actually what I started out with.
To fix bots going down, and being defined as both, I usually just have the bots in godmode to not have bugs with multiple of them running around.

This is a function I created to have a bot follow a player. The Canpath & BotSetGoal are built-in functions. Just don't forget the include I put at the top.
The Distance var is how close the bot needs to be to you for the bot to think he's reached his goal already. You could combine this with a looping function that makes the bot follow you but pauses if there is a downed player that needs to be revived. As the bot gets confused when trying to do both.

Code:
ice_MoveBot_toPOS(bot, player, distance = 200) {
    posb = bot.origin;
    posp = player.origin;
    if(!isDefined(bot)) return;
    if(bot CanPath(posb, posp)) {
        bot BotSetGoal(posp, distance);
        player iPrintLnBold(bot.name + " is pathing to you...");
    } else {
        player iPrintLnBold("Bot Could Not find Path");
    }
}

Getting the bot to path to a power-up is also pretty simple, as it is similar to using the function above except instead we're looking for the origin of the power-up.
This is a function I made to allow the bot to path to the closest power-up to them if one exists on the map.

Code:
ice_bot_pathto_powerup(bot) {   
    if(bot.is_reviving_player == true) return;
    if( level.active_powerups.size >= 1 && isDefined(level.active_powerups)) {
        p_target = ArrayGetClosest(bot.origin, level.active_powerups);
        wait 0.1;
        ice_MoveBot_toPOS(bot, p_target, 0);
        self iPrintLnBold("Bot is pathing to power up");
    } else { self iPrintLnBold("No Current Powerups"); }
}

Just a few examples. Never seen people use this in a mod menu, and rarely on custom maps. But if you get really creative with it, you could essentially give the bots a real AI.
Another idea I've done to make the bots more useful is that all the points they earn go to each player in the game. Because while play testing a friend of mine was annoyed as the bot was pretty much robbing all the points.
 

Attachments

  • 65GkfTA3M.png
    65GkfTA3M.png
    58.1 KB · Views: 63

JayCoder

Veteran
Staff member
Messages
369
Reaction score
148
Points
903
nice, simple ai, looks like u got the pathing down and stuff...
 
Top