12

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?

1
  • 1
    Could you just set the spawn point to a certain place, which will land them on a pressure plate that teleports them to a place based on their team, and adds a point to the other team?
    – Sconibulus
    Aug 29 '13 at 18:14
10

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
3
  • after i saw the other - far shorter - answer i figured all that stuff out myself. Still thanks. Good description on how to accomplish it!
    – Shiuyin
    Aug 29 '13 at 22:15
  • @Shiuyin If the other answer was helpful at all, you should give it an upvote. Aug 30 '13 at 0:40
  • @ SevenSidedDie: Done.
    – Shiuyin
    Aug 30 '13 at 14:15
3

I haven't worked much with team scoreboard stuff, but the teleport should just be

/tp @p[score_HEALTH=1] X Y Z

@a is used to find all players matching some criteria; @p only finds one at a time, but let's you use that player's name inside other commands.

0

Or you could just use /setworldspawn unless you're doing a team based game then yea, listen to the other answers.

0

the easyest thing to do is to reset the players spawnpoint using commandblocks as soon as they respawn they will appear in the set location

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.