games are incredibly nuanced, and like a human, your bot will have to make critical decisions if you want it to play. yolkbot provides a variety of tools to make this possible, but if you want a bot to be like a player, you'll need to write most of the logic yourself. this is a good thing, because it means you can make your bot play however you want, but it also means that there's a lot to learn if you want to make a bot that plays well.
the client data syncs to the server every 100 milliseconds, but the actual game loop runs every 33 milliseconds (1/3 of that). to play a game, you'll want to listen to the clientTick event:
bot.on('clientTick', () => {
// game logic here
});
even if you don't WANT to do something every tick, this is more reliable than trying to do things in response to other events, because this will make your bot truly reactive.
every tick, you'll want to create some algorithm to decide what your bot should do (fire, reload, move, melee, do nothing, etc).
an example of a very simple algorithm that
const shotsPer = 3;
let lastAction = 0;
bot.on('clientTick', () => {
if (!bot.game.isReady() || !bot.me.playing) return;
const target = bot.game.getBestTarget(true);
if (target) {
bot.emit('lookAt', target.player.id);
bot.emit('fire', shotsPer);
lastAction = Date.now();
} else {
if (
bot.me.weapons[0] &&
bot.me.weapons[0].ammo &&
bot.me.weapons[0].ammo.rounds <= shotsPer &&
(Date.now() - lastAction) > 5000
) bot.emit('reload');
}
});
bot.on('playerDamage', (player) => player.id === bot.me.id && (lastAction = Date.now()));
this algorithm is pretty simple and demonstrates a system that will shoot targets that are in the line of sight (getBestTarget - true is the LoS check) and then reload if it determines it's "safe" (bot hasn't been damaged in 5 seconds).
this probably works best with an eggk, due to the large mag size and lack of distance checks. obviously, depending on which algorithm you implement, you'll want to implement a vastly different system that does more checks based on distance.
this algorithm also doesn't make use of any movement or pathfinding, which is readily available. pathfinding is still being worked on internally to add more options like going down stairs, traversing ramps, jumping, and falling. however, the basics (walking, ladders, going up stairs, etc) are all available. people who are interested in pathfinding should join the community and let me know about your use case.