I'm making mineflayer bot he follow me and try to kill me so when I go far from him he stop from following me, And he has other problems like while he bridge he fall as stupid so how I can make him sprint while he follow me My code :
const { versions } = require('minecraft-data')
const MinecraftData = require('minecraft-data')
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
const GoalFollow = goals.GoalFollow
const pvp = require('mineflayer-pvp').plugin
const armorM = require('mineflayer-armor-manager')
const bot = mineflayer.createBot({
host: 'EventWG.aternos.me',
username: 'bot'
})
//Follow the player
function followPlayer() {
bot.on('chat', (namee, msgg)=>{
const player = bot.players[namee]
if (msgg == "attack") {
bot.chat("ok " + namee)
bot.chat("/effect give @p minecraft:resistance 111111 255")
if (!player || !player.entity){
bot.chat("I can't see you " + namee)
return
}
const data = require('minecraft-data')(bot.version)
const movements = new Movements(bot, data)
bot.pathfinder.setMovements(movements)
const goal = new GoalFollow(player.entity, 2)
bot.pathfinder.setGoal(goal, true)
setInterval(() => {
const playerFilter = p => p.type === "player"
const playerr = bot.nearestEntity(playerFilter)
bot.pvp.attack(player.entity)
const sword = bot.inventory.items().find(item => item.name.includes('sword'))
if(sword) bot.equip(sword, "hand")
}, 2000);
}
})
}
bot.on('spawn', lookAtPlayer)
bot.on('spawn', followPlayer)
You can simple just use bot.setControlState just like
bot.setControlState('sprint', true);