首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当他跟着我的时候,我该如何让我的雷飞冲刺?

当他跟着我的时候,我该如何让我的雷飞冲刺?
EN

Stack Overflow用户
提问于 2022-08-14 15:13:28
回答 1查看 93关注 0票数 0

我在制作雷人机器人,他跟着我,想杀了我,所以当我远离他的时候,他就停止跟踪我,他还有其他的问题,比如当他架桥的时候,他摔倒的时候很蠢,所以我怎么能让他在他遵循我的代码的时候让他冲刺:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2022-09-14 02:57:21

您可以简单地使用bot.setControlState,就像

代码语言:javascript
复制
bot.setControlState('sprint', true);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73352764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档