Detect where a specific player died?
So I am making a capture the flag game. I have a objective for picking up the flag:
scoreboard objectives add red_flag stat.mineBlock.minecraft.wool Has the red flag
I want it so that when a player dies, if the have the flag, they drop it where they were standing, (as a block, using setblock). I tried, where h is a health scoreboard:
execute @p[score_h=0] ~ ~ ~ setblock ~ ~1 ~ wool 14
This doesn't work, because the player is dead, and score_h=1 means that if a player has exactly 1/2 heart, then they continuously setblock wool.
Currently, the only solution I can think of is this command, and /kill all players with 1/2 heart. I would like a cleaner solution. Any ideas?
Best Answer
@MBraedley pointed out that dead players aren't valid targets for teleportation.
Disclaimer: The following idea should work, but I haven't tested it yet.
This answer requires the red_flag objective to work correctly. That is, it should be 1 for the player that carries the red flag, and 0 for everyone else.
Run this once
/summon ArmorStand 0 0 0 {Invisible:1,Marker:1,NoGravity:1,CustomName:"Marker"}
Then run this on a fast clock
/tp @e[type=ArmorStand,name=Marker] @p[score_red_flag_min=1]
This will make an invisible Armor stand with no hitbox continuously teleport to flag-bearer.
The moment the flag carrier dies, the tp command fails continuously, until a new valid target appears. Grab the output of tp with a comparator and invert the signal using a torch. Note that the comparator signal will be constant, unless something changes, according to the wiki:
SuccessCount: Represents the strength of the analog signal output by redstone comparators attached to this command block. Only updated when the command block is activated with a redstone signal.
This means, that the torch will be continuously on when no one has the flag and turn off when someone picks up the flag, after which it is continuously off. It will turn on exactly the moment the tp command fails, at which point it will power another command block with
/execute @e[type=ArmorStand,name=Marker] setblock ~ ~ ~ minecraft:wool 14 keep
Note that this will also happen when the red_flag objectives drops below 1 for any reason other than death, such as scoring. This can be easily remedied by removing all red wool blocks from the scoring area using
/fill <x1> <y1> <z1> <x2> <y2> <z2> minecraft:air replace minecraft:wool 14
Pictures about "Detect where a specific player died?"



How do you find where a Minecraft player died?
If the player has their F3 menu open on Java Edition, the coordinates will remain on the screen after the death screen appears. This can allow players to write down their coordinates and backtrack to them if needed.How can I find out where a player is looking?
Create a scoreboard objective that counts player deaths. When it does, decrease it to 0, and execute the commands you want.Player Death Detection - Mapmaking techniques
More answers regarding detect where a specific player died?
Answer 2
The @a selector is the only selector capable of targeting dead players. You can set the c (maximum targets) parameter to 1 to reduce the number of targets.
You would need to track player deaths with the deathCount objective-type instead of health (which is read-only), as the dead player would otherwise constantly be setting the block:
/scoreboard objectives add deaths deathCount
The following would need to be run in numerical order:
Cause dead players to run a
/setblockcommand./execute @a[score_deaths_min=1,score_red_flag_min=1,c=1] ~ ~ ~ /setblock ~ ~ ~ minecraft:wool 14Reset the "deaths" score so the previous command does not constantly run.
/scoreboard players reset @a[score_deaths_min=1,score_red_flag_min=1] deaths
Answer 3
I have an idea no-one proposed so far, also I'm not sure: Are you OK with using mods?
If you are, you can use the OpenBlocks mod, the GraveStone mod or any other mod that generates gravestones upon player death, and then repeatedly run a command replacing all gravestone blocks containing red wool block items with a red wool block.
(Not sure about the GraveStone mod, the OpenBlocks mod however should work cleanly when installed to the server only, at least the Forge version, I know that from LeKoopa's ChaosCraft projects. To those who don't know LeKoopa, it's a german MineCraft youtuber with lots of mod projects - mod reviews, multiplayer mod LP, lucky block minigames and untextured (as in all TNT textures are replaced by white wool textures) Too Many TNT survival quests are just a few examples.)
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ron Lach, Ron Lach, Centre for Ageing Better, RUN 4 FFWPU
