I need to detect if a player has died and teleport that one to location XY and give the other team a point.
I can detect if a player has died with testfor @a[score_HEALTH=1]
applied to a redstone pulse, but that just outputs a signal if a player has died, not who has died.
Is there a way to detect which player has died? Is there a way to use the detected player who has died as an argument in the next command block, like /tp @f X Y Z
, where @f
stands for the found player of the last command block?
If nothing of that works, are there workarounds?
Best Answer
Any selector arguments you use in
testfor
can be used intp
. Like so:There are problems with using low health to check for death. Instead, I'd recommend adding a
deaths
scoreboard:This score will get set to 1 when a player dies (automatic, because of the type of objective), your commands can teleport players with a
deaths
score of 1 and then set it back to 0 (so the player isn't repeatedly teleported).The following commands are a full solution, including the team score incrementing, for 1.13+: