#im not sure why this is working i want to use my own

1 messages · Page 1 of 1 (latest)

tawdry scaffold
#
import { world, EntityHealthComponent  } from "@minecraft/server";
import { getScore } from "./functions";
import { config, definePlayer} from "./config";

world.afterEvents.entityHit.subscribe((data) => {
    const dead2 = data.hitEntity;
    const killer2 = data.entity;
    const killer = definePlayer(killer2);
    const dead = definePlayer(dead2);
    const health = dead.getComponent("minecraft:health")
    console.log(health)
    if (health.currentValue < 0) {
        world.getDimension('overworld').runCommandAsync(`scoreboard players add @s Kills 1`);
        world.getDimension('overworld').runCommandAsync(`scoreboard players add "${dead.name}" Deaths 1`);
        world.getDimension('overworld').runCommandAsync(`scoreboard players add @s ${config.objectives.money} 100`);
        (config.server + config.killMsg);
    }
})
#

@austere cedar

austere cedar
#

isnt working **

#

this is the error it has

austere cedar
#

uhm

#

here

#

@brazen cargo

export function definePlayer(player1) {
  const player = world.getAllPlayers().find((plr) => plr.name === config.allPlayers[player1]);
  return player;
}```
brazen cargo
#

ok

#

so dead2 is an Entity object and not a string, nor a number for index use

#

btw, what's config.allPlayers

austere cedar
#

here

austere cedar
brazen cargo
#

if its a player, it's a player entity, and theres no need to use definePlayer

austere cedar
#

ok

#

idrk how to put that in

#

im a bit slow

brazen cargo
#

just use these two


const dead = data.hitEntity;
const killer = data.entity;
austere cedar
#

ty

brazen cargo
#

also, to filter that they are players

austere cedar
#

ty

brazen cargo
#

actually, it's better to use entityDie on this

austere cedar
#

how so

#

ah i see

#

nvm

#

ty

#
world.afterEvents.entityDie.subscribe((data) => {
    const dead = data.entityDie;```
brazen cargo
#

i do mine like this

world.afterEvents.entityDie.subscribe(({ damageSource: { damagingEntity }, deadEntity }) => {
    deadEntity.scores.deaths++;
    if (damagingEntity?.constructor === deadEntity.constructor) damagingEntity.scores.kills++;
}, { entityTypes: ['minecraft:player'] });
austere cedar
#
world.afterEvents.entityDie.subscribe((data) => {
    const dead = data.entityDie;
    const killer = data.entity;
    const health = dead.getComponent("minecraft:health")
    if (health.currentValue < 0) {
        world.getDimension('overworld').runCommandAsync(`scoreboard players add @s Kills 1`);
        world.getDimension('overworld').runCommandAsync(`scoreboard players add "${dead.name}" Deaths 1`);
        world.getDimension('overworld').runCommandAsync(`scoreboard players add @s ${config.objectives.money} 100`);
        (config.server + config.killMsg);
    }
})
#

should this work?

brazen cargo
# austere cedar allPlayers: world.getAllPlayers().map((plr) => plr.name),
world.afterEvents.entityDie.subscribe((data) => {
    const killer = data.damageSource.damagingEntity;
    if (killer?.typeId === 'minecraft:player') {
        const dead = data.deadEntity;
        killer.runCommandAsync(`scoreboard players add @s Kills 1`);
        killer.runCommandAsync(`scoreboard players add @s ${config.objectives.money} 100`);
        dead.runCommandAsync(`scoreboard players add @s Deaths 1`);
        (config.server + config.killMsg);
    }
}, { entityTypes: ['minecraft:player'] })
austere cedar
#

ty

brazen cargo
austere cedar
#

rt

brazen cargo
austere cedar
#

ty

brazen cargo
#

np

#

use it same as u use before

austere cedar
#

oki

#

also

#

do u know anything abt resource packs