Closed SonicandTailsCD closed 1 year ago
The error was /Users/adm/Desktop/Bot/node_modules/minecraft-protocol/src/transforms/framing.js:69 throw e ^
TypeError: Cannot read properties of undefined (reading 'setMovements')
at EventEmitter.
Node.js v17.9.1
You didn't load the pathfinder
plugin.
Add the code below under mineflayer.createBot()
:
bot.loadPlugin(pathfinder)
btw, you should just move bot.on('chat')
inside onSpawn
and remove bot.on('spawn', onSpawnMessage)
and onSpawnMessage
btw, you should just move bot.on('chat') inside onSpawn and remove bot.on('spawn', onSpawnMessage) and onSpawnMessage
The thing is that a server plugin sends the spawn message to the client when its skin is loaded. That causes the bot to loop sending a command.
You didn't load the pathfinder plugin.
I'm gonna try to load the server now with the correction...
Also, wanna join the server? We try to fix it in real time? It isn't an issue if you don't agree.
LOL it said "I can't see you, SkinsRestorer". How do I fix this?
Also, wanna join the server? We try to fix it in real time?
yeah sure
Alright. You know the IP and port?
yup
// Here I tell node.js mineflayer and a few other plugins are required to load 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
// Here, we set up the server connection (in this case, my skin plugin server) const bot = mineflayer.createBot({ host: 'SonicJavaBots.aternos.me', port: '37867', username: "SonicandTailsCDb", version: '1.18.2' })
// Loading! bot.loadPlugin(pathfinder)
// And now, we work on the AI here! // Here's all of the functions: // One note tho: All functions are placeholders. function onPhysicsTick () {}
function onSpawn () { bot.chat("Hey! I'm working properly :D") bot.chat("/skin set SonicandTailsCDb robot1_stevetest") }
function onSpawnMessage () { bot.on('chat', (daname, msgg)=>{ const player = bot.players[daname] if (msgg == "follow me") { bot.chat("Okay " + daname) } if (!player || !player.entity){ bot.chat("I can't see you, " + daname) 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)
})
}
// I need to set physicsTick because I want the AI to target me. bot.on('physicsTick', onPhysicsTick)
// Next, I'm gonna set spawn actions. bot.once('spawn', onSpawn) bot.on('space', onSpawnMessage)
// Here I tell node.js mineflayer and a few other plugins are required to load
const { versions } = require('minecraft-data')
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
const GoalFollow = goals.GoalFollow
const pvp = require('mineflayer-pvp').plugin
// Here, we set up the server connection (in this case, my skin plugin server)
const bot = mineflayer.createBot({
host: 'SonicJavaBots.aternos.me',
port: '37867',
username: "aaaa",
version: '1.18.2'
})
const mcData = require('minecraft-data')(bot.version)
// Setup pathfinder
bot.loadPlugin(pathfinder)
bot.pathfinder.setMovements( new Movements(bot, mcData))
// And now, we work on the AI here!
// Here's all of the functions:
// One note tho: All functions are placeholders.
function onPhysicsTick () {}
function onSpawn () {
bot.chat("Hey! I'm working properly :D")
bot.chat("/skin set SonicandTailsCDb robot1_stevetest")
bot.on('chat', (daname, msg)=>{
const player = bot.players[daname]
if (msg == "follow me") {
if (!player?.entity){
bot.chat("I can't see you, " + daname)
return
}
bot.chat("Okay " + daname)
const goal = new GoalFollow(player.entity, 2)
bot.pathfinder.setGoal(goal, true)
return
}
})
}
// I need to set physicsTick because I want the AI to target me.
bot.on('physicsTick', onPhysicsTick)
// Next, I'm gonna set spawn actions.
bot.once('spawn', onSpawn)
I'm ready! :D
This issue is complete, I don't have that specific issue anymore. Thanks to @678435021 for his help :)
Versions
Detailed description of a problem
A clear and concise description of what the problem is, with as much context as possible. Weird error that doesn't allow me to create a bot. That's all I know. What are you building? A pathfinding bot that follows me when I say "follow me" What problem are you trying to solve?
What did you try yet?
Did you try any method from the API? I don't know how to. Did you try any example? Yes Any error from those? No
Your current code
Expected behavior
A clear and concise description of what you expected to happen. I expected the bot to join and follow me when I say "follow me"
Additional context
Add any other context about the problem here. NO. Thanks :)