The usual way to test for dead players is to set up a scoreboard objective. Check out the linked wiki page for general information, as well as the command reference for using scoreboards.
First, you have to set up an objective, I'll call it hasDied
using
/scoreboard objectives add hasDied deathCount
Using the deathCount
criterion means that it is automatically updated when someone dies. Now you can check whether a player has died using
/testfor @a[score_hasDied_min=1]
On a clock. The output of this command block will turn on once at least one player, somewhere, has a death score of at least 1. As part of this output (or the game start routine) you should reset the scoreboard objective for everyone using
/scoreboard players set @a hasDied 0
For an unknown number of players detecting the last man standing can be tricky, but it's doable. You can easily track people that have not died (using @a[score_hasDied=0]
), and detect when the comparator outputs at signal strength 1.
First, you should set up a scoreboard objective of type stat.leaveGame
:
/scoreboard objectives add JustLeft stat.leaveGame
When a player leaves the world, their JustLeft score will increase by 1 because of its type.
On a clock somewhere, you should then have:
/scoreboard players set @a[score_JustLeft_min=1] Death 1
To set the death score of players who have just relogged to 1. Followed by:
/scoreboard players set @a[score_Death_min=1] JustLeft 0
So that their JustLeft score is reset after their Death score is set, preventing them being continually killed.
@a
only selects online players, so they should only have their Death score set and then reset when they rejoin the world, even though their JustLeft stat will increase to 1 straight away.
Best Answer
This is actually not too difficult to implement by using scoreboard magic.
First, set up some scoreboard commands
Next, run the following commands on a fast clock (I suggest using a fill clock), in this order.
The first two will set
airborne
to 1 for every player who is not standing on something, i.e. the block beneath him isair
. The third command will reset thefallen
score to 0 for everyone who is notairborne
, the fourth increments the score 20 times a second instead. This means thatfallen
is 0 as long as you were standing on something since your last fall.Now you can select the falling players for teleportation using
@a[score_fallen_min=XYZ]
. ReplaceXYZ
with however many seconds a player has to be above air to be considered "falling", multiplied by 20.There is an issue with this however: Standing on the edge of a block will make you be considered falling, and I can't think of an elegant solution to this, short of chaining
execute detect
commands to check a 3×3 area below the player for blocks.