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);
}
})
#im not sure why this is working i want to use my own
1 messages · Page 1 of 1 (latest)
well, what's that definePlayer?
uhm
here
@brazen cargo
export function definePlayer(player1) {
const player = world.getAllPlayers().find((plr) => plr.name === config.allPlayers[player1]);
return player;
}```
ok
so dead2 is an Entity object and not a string, nor a number for index use
btw, what's config.allPlayers
here
allPlayers: world.getAllPlayers().map((plr) => plr.name),
wym
here, dead2 is already an entity
if its a player, it's a player entity, and theres no need to use definePlayer
just use these two
const dead = data.hitEntity;
const killer = data.entity;
ty
also, to filter that they are players
ty
actually, it's better to use entityDie on this
how so
ah i see
nvm
ty
world.afterEvents.entityDie.subscribe((data) => {
const dead = data.entityDie;```
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'] });
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?
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'] })
ty
export function definePlayer(player1) {
return world.getAllPlayers().find(p => p.name === player1)
}
rt
get allPlayers(){ return world.getAllPlayers().map((plr) => plr.name) },
ty
