Any selector arguments you use in testfor
can be used in tp
. Like so:
1.7 to 1.12: /tp @a[score_HEALTH=1] X Y Z
1.13+: /tp @a[scores={HEALTH=..1}] X Y Z
There are problems with using low health to check for death. Instead, I'd recommend adding a deaths
scoreboard:
/scoreboard objectives add deaths deathCount
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+:
tp @a[scores={deaths=1..}] 73 10 31
execute as @a[scores={deaths=1..},team=red] run scoreboard players add blue points 1
execute as @a[scores={deaths=1..},team=blue] run scoreboard players add red points 1
scoreboard players set @a deaths 0
For this problem, you don't actually need to modify the players score when they are offline (which is possible, but finicky), you should be able to change their score as soon as they log back in.
First, create a scoreboard objective of type stat.leaveGame
:
scoreboard objectives add quits stat.leaveGame
You should then have two command blocks on some kind of clock, one activated after another. In the block that is activated first, put this command:
scoreboard players set @a[score_quits_min=1] timer -1
Then, in the one that is activated second:
scoreboard players set @a[score_quits_min=1] quits 0
The quits
score increments when the player leaves. So, when they log back on, it will be at 1 and their timer score will be set to -1. Their quits
score then has to be set back to 0, so that it can be used for the next logout and also so that timer isn't repeatedly set to -1,
Best Answer
Your real problem is that the players can wait arbitrarily long until they click "respawn", so no fixed delay would help you. What you can instead do is detecting when they have respawned. This can for example be done by checking if they are at a location (because dead players are nowhere*):
This
distance=0..
might seem useless, because you're testing for a distance of 0 or more from the command block, but what it does is only activating if you have an alive player in the same dimension. You could also do the same for Nether and End, but since you want to detect respawning, that's not necessary. Dead players have no location, so their distance from the command block isn't 0 or more, it's nothing.*This got a bit more complicated in 1.15, because the player is still registered as being at their death location for about a second after dying. That could be very helpful in some cases, I think it even used it in an answer here already, but it complicates this case. Now you need to check if they are not at any location first and then at a location again:
The first command is the real magic: Every player who died gets tagged, but only once no player who died can be found at any location anymore. This still fails if another player is currently in its death animation, I don't think this can be avoided.
Then you just run whatever command you want at a player that used to be at no location, but is at some location now. Finally, you reset the scoreboard (implied in my 1.14 solution) and the tag.