get the player's position #3415
Answered
by
greenik228
mncrftfrcnm
asked this question in
Q&A
Replies: 1 comment 1 reply
-
const mineflayer = require('mineflayer')
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
function createBot () {
const bot = mineflayer.createBot({
username: 'YOUR_NICKNAME',
host: 'YOUR_IP',
port: 25565
})
mainFunc(bot)
}
createBot()
function mainFunc(bot) {
bot.on('message', (jsonMsg) => {
console.log(jsonMsg.toAnsi())
})
bot.on('end', () => {
createBot()
rl.removeAllListeners('line')
})
rl.on('line', (input) => {
if (input.match(/^\$/)) {
switch (input) {
case '$pos':
for (const entity of Object.values(bot.entities))
if (entity.name === 'player') {
const x = Math.round(entity.position.x * 10) / 10
const y = Math.round(entity.position.y * 10) / 10
const z = Math.round(entity.position.z * 10) / 10
console.log(entity.username,
'x:', x,
'y:', y,
'z:', z)
}
return
}
} else bot.chat(input)
})
}by typing $pos in the cmd, the bot displays the coordinates of nearby players |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mncrftfrcnm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Could someone please tell me how to get the position of other players on the server, including non-bot players?
Beta Was this translation helpful? Give feedback.
All reactions