#how detect player kill another player?

1 messages · Page 1 of 1 (latest)

charred gorge
#
world.afterEvents.entityDie.subscribe((event) => {
    const {deadEntity,damageSource} = event
    const {damagingEntity} = damageSource
    if((deadEntity instanceof Player) && (damagingEntity instanceof Player)){
        //Code
        console.warn(`${damagingEntity.name} killed ${deadEntity.name}`);
    }
});
marsh spade
#

Weird i messaged here questions but their gone💀

nova oasis
#

I'm not much of a scripter, so I'm asking for help

charred gorge
nova oasis
#

I don't own the question

#

I just saw your comment and wanted help

charred gorge
nova oasis
#

let me explain

#

I just want when the player kills a player/mob the "/say Hi" command would be executed.

nova oasis
#

It's possible?

shy pond
#

Very possible but you will need many events to pull this off to make sure you test for projectiles owned by a player or other stuff to test if the death of a player or mob is by a certain player and then do your code

nova oasis
#

In my mind it seemed simpler lol

shy pond
#

I mean you could just test if a player kills an entity by hitting them using an event

#

Basically [this](#1204086363733889085 message)

nova oasis
charred gorge
#

@nova oasis

import {world,Player} from "@minecraft/server";

world.afterEvents.entityDie.subscribe((event) => {
    const {damageSource,deadEntity} = event
    const damagingEntity = damageSource.damagingEntity
    if((damagingEntity instanceof Player) && (deadEntity instanceof Player)){
        damagingEntity.runCommandAsync('give @s apple')
    }
});