#Death/Kills counter broken

1 messages · Page 1 of 1 (latest)

icy drum
#

Well the death/kill counter is kinda broken, its counting kills/deaths, but only deaths from being killed from other players, idk why its not working with other ways of deaths? (and its not also giving me any sort of error)
Code:

world.afterEvents.entityHurt.subscribe((data) => {
    let { hurtEntity: entity } = data
    let player = data.damageSource.damagingEntity
    if (player?.typeId !== 'minecraft:player') return;
    if (entity.typeID != "minecraft:player") return;
    /**
     * @type {EntityHealthComponent}
     */
    // @ts-ignore
    const health = entity.getComponent("health");
    if (health.currentValue > 0) return;
    entity.runCommandAsync("function other/death");
    if (player.typeId != "minecraft:player") return;
    player.runCommandAsync("function other/kill");
});
#

(please ping reply)

timid hamletBOT
#
Debug Result

There is an error in this [code](#1143656296185344010 message):

<repl>.js:5:16 - error TS2551: Property 'typeID' does not exist on type 'Entity'. Did you mean 'typeId'?

5     if (entity.typeID != "minecraft:player") return;
                 ~~~~~~

  @minecraft/server.d.ts:4937:22
    4937             readonly typeId: string;
                              ~~~~~~
    'typeId' is declared here.

icy drum
#

oh

#

nope, didnt fix it

dusky dust
#
world.afterEvents.entityHurt.subscribe((data) => {
    let { hurtEntity: entity } = data
    let player = data.damageSource.damagingEntity
    if (player?.typeId !== 'minecraft:player') return;
    if (entity.typeId != "minecraft:player") return;
    /**
     * @type {EntityHealthComponent}
     */
    // @ts-ignore
    const health = entity.getComponent("health");
    if (health.currentValue > 0) return;
    entity.runCommandAsync("function other/death");
    player.runCommandAsync("function other/kill");
});
icy drum
buoyant ether
icy drum
#

oh

#

but dying for example to a mob doesnt run it

buoyant ether
#

Oh that’s a different issue entirely then

#

The issue is likely with the way your functions run code from the entity that died

tame cloak
#

The api has entityDie._.

buoyant ether
#

Since the entity doesn’t exist, technically

buoyant ether