#How to detect an entity being attacked/killed?

1 messages · Page 1 of 1 (latest)

mellow peak
#

The code in question

import { world } from "@minecraft/server"

world.afterEvents.entityHurt.subscribe(async evd => {
    var player1 = evd.damageSource.damagingEntity
    var player2 = evd.hurtEntity
    if (player2.typeId == 'minecraft:player') {
        await player1.runCommandAsync(`function player/hit`)
        if (player2.getComponent('health').current <= 0) {
            await player1.runCommandAsync(`function player/kill`)
        }
    }
})
#

the error im getting is constantly that it cannot read the properties from "entityHurt"

inner plover
#

we have die event

mellow peak
#

Oh cool, what about the hitting though?

inner plover
#

show error

mellow peak
#

Wait I did something but now its just spamming the logs with this

mellow peak
# gilded harness show manifest version
        {
            "type": "script",
            "language": "javascript",
            "uuid": "8e1d169a-3aae-41f2-9c92-e37af79d7a9f",
            "version": [
                1,
                0,
                0
            ],
            "entry": "scripts/index.js"
        }
    ],
    "dependencies": [
        {
            "version": "1.5.0",
            "module_name": "@minecraft/server"
        }
    ]
}

Here's the manifest, it doesen't look wrong to me at least.

#

(well part of the manifest anyways)