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
Summen the villager like that (He will be in "god mode" and will not move)
/summon Villager ~ ~1 ~ {CustomName:"Eliza",CustomNameVisible:1,Profession:0,Invulnerable:1,NoAI:1}
To teleport the villager to the Player put this cmd into an repeating cmd block
/tp @e[name=Eliza,type=Villager] @p
The problem is, that the villeger is exactly in the player. To soolve this, we'll add a kind of delay.
Create a scoreboard:
/scoreboard objectives add lifeTime dummy
Then a repeating cmd block chain:
/summon ArmorStand ~-2 ~ ~ {CustomName:"Follower",Marker:1b,Invisible:1,Invulnerable:1,NoGravity:1}
/scoreboard players add @e[type=ArmorStand,name=Follower] lifeTime 1
/tp @e[score_lifeTime=1,type=ArmorStand,name=Follower] @p
/execute @p ~ ~ ~ tp @e[name=Eliza,type=Villager] @e[score_lifeTime_min=20,type=ArmorStand,name=Follower,rm=2]
/kill @e[score_lifeTime_min=20,type=ArmorStand]
The player will then follow the player but will not go nearby the player (2 blocks radius)
Generator for summon commands: https://mcstacker.bimbimma.com/
Command selectors: http://minecraft.gamepedia.com/Commands#Target_selectors
Plugin for visible Commands: CommandDescriptor by SimonMeusel: https://www.spigotmc.org/resources/commanddesciptor.23870/
Best Answer
This is actually really easy to do using the caret notation for coordinates. Caret notation does relative translation based on the player's left, up, and forward directions (in that order). So, after tagging your player (which you've indicated you're already doing), your command simply becomes
replacing the 3 with an appropriate distance. Do note however, I believe the forward direction is based on the player's view pitch angle, so using this can allow a player to teleport into the air. This can be solved using an execute command specifying the rotation:
(I'm pretty sure that works, haven't been able to test.)