I am trying to make a pvp minecraft bot using mineflayer in javascript. This is my function for if the bot is requested to pvp:
bot.loadPlugin(pvp)
bot.on('chat', (username, message) =>{
if (message === 'fight me') {
const player = bot.players[username]
if (!player) {
bot.chat("I can't see you.")
return
}
bot.chat("Get ready to PvP in 10 seconds!")
const sword = bot.inventory.items().find(item => item.name.includes('sword'))
if (sword) bot.equip(sword, 'hand')
const shield = bot.inventory.items().find(item => item.name.includes('shield'))
if (shield) bot.equip(shield, 'off-hand')
sleep(1500).then(() => {
beeingAlive()
bot.chat(`/tp notbreadbutter ${username}`)
bot.pvp.attack(player.entity)})
}
if (message === 'stop') {
bot.pvp.stop()
}})
I want the bot to know when the player gets killed. I also want the bot to know if the bot itself gets killed. How should i modify my code?