#Player's Death Information

1 messages · Page 1 of 1 (latest)

pseudo talon
#

Updated Script:
#1250718489853821039 message

Old Script:

import { world } from '@minecraft/server';

function toTitleCase(str) {
    return str.split(" ").map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join(" ");
};

world.afterEvents.entityDie.subscribe(( { deadEntity } ) => {

    const { x, y, z } = deadEntity.location;

        if (deadEntity.typeId === 'minecraft:player') {

            const deathDimension = deadEntity.dimension.id.replace('minecraft:','').replaceAll('_', ' ');
            const formattedDimension = toTitleCase(deathDimension.charAt(0).toUpperCase() + deathDimension.slice(1));

            world.sendMessage(`§6${deadEntity.name}§r has §cdied§r at §b${Math.trunc(x)}§r, §b${Math.trunc(y)}§r, §b${Math.trunc(z)}§r in §a${formattedDimension}§r`);

        };
});

Using this script, you can get information of where the player died. When a player dies, A message will be sent, which displays coordinates and the dimension of the death location of the player.

upper plover
#

this could be use to fork those corpse mod on java. Drop loot boxes on death and such

#

this is interesting nice work

calm falcon
#

Cool

heavy flame
pseudo talon
#

i could also use js if (deadEntity instanceof Player) {}

#

To make my script understandable, and to keep readability, i just used a simple if statement

heavy flame
#

Is the suggested option more difficult to read?

hardy crown
#

typing maybe?

upper plover
upper plover
# heavy flame wdym?

the more you code everyday the more you start to understand what those stuff means even if it's your first time encountering them

pseudo talon
pseudo talon
upper plover
heavy flame
upper plover
#

I don't really because I've never really encountered those cases where it uses filter

upper plover
#

probably it all matters on the knowledge

heavy flame
heavy flame
# upper plover but as a beginner I can read all of the code and I would say this is much cleare...

Is it less clear, in your opinion?

import { world } from '@minecraft/server';

function toTitleCase(str) {
  return str
    .split(' ')
    .map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
    .join(' ');
}

const filter = {
  entityTypes: ['minecraft:player'],
}; // we can just move the filter in a separate variable

world.afterEvents.entityDie.subscribe(({ deadEntity }) => {
  const { x, y, z } = deadEntity.location;
  const deathDimension = deadEntity.dimension.id
    .replace('minecraft:', '')
    .replaceAll('_', ' ');
  const formattedDimension = toTitleCase(
    deathDimension.charAt(0).toUpperCase() + deathDimension.slice(1),
  );

  world.sendMessage(
    `§6${deadEntity.name}§r has §cdied§r at §b${Math.trunc(x)}§r, §b${Math.trunc(y)}§r, §b${Math.trunc(z)}§r in §a${formattedDimension}§r`,
  );
}, filter);
sharp sun
#

add death cause also

pseudo talon
#

but adding too much text would make it messy i think

#

but i'll still do it

pseudo talon
# sharp sun add death cause also

i totally re-made the script, and the new script is much more optimized, i added a death cause too, but I'll share the script tomorrow.

hidden umbra
#

....

normal mason
#

Wait so was the new script ever shared?

pseudo talon
normal mason
#

Alright, take your time!

calm falcon
#

Where i can promote my add-on ;'v

hardy crown
calm falcon
pseudo talon
#

Guys i created a new script

#

I want feedbacks

summer knoll
pseudo talon
#

Updated Script!!

Changes:

  • Optimized the script, and functions.
  • added Death Cause
  • added comments to every line of code.
summer knoll
#

THXXX

normal mason
#

Yipee!

wild summit
pseudo talon
#

can you please explain, i didn't understand

wild summit
# pseudo talon do you mean, the death information will only show, if the player has a specefic ...
    if (entity.hasTag('denied')) {
        entity.sendMessage(`§8You have been sent back to Spawn!§r`);
    }
    else {
        world.sendMessage(`§6${entity.name}§r has §cdied§r at §b${x}§r, §b${y}§r, §b${z}§r in §a${dimensionString}§r\nbecause of: §e${formatCauseName(cause) ?? cause}§r`);
    }

other way around. I figured something out (still trying to learn here) Not sure if this the best way but this is given if "killing the player with keepinventory to send back to spawn" Im still looking around for like a getSpawn instead of killing someone.

wild summit
#

Yeah, what I was messing around with it. It works. Not sure if there's a better way tho

wild summit
#

Ah ok thank you

#

I have noticed when there is a mass amount of mobs killed like with /kill @e[type=!player] that an error will fire in the gui logger with this script even though no players are killed. Continues to work as intended though. Doesn't seem to cause any issues, and doesn't happen every time either. Ill try to get a capture of it.

sinful cove