In Minecraft, I'm making an adventure map and doing a dungeon style thing. After you die in the "dungeon", I want all mobs in that specific area to die so the player can try again.
I've tried doing a testfor
command but nothing seems to work.
You first have to create a scoreboard like this:
/scoreboard objectives add deaths deathCount
Then you put a repeating, always active command block somewhere out of sight (but still in the loaded area), containing this command:
/execute at @a[scores={deaths=1..}] run kill @e[type=!player,distance=..10]
And in the direction the repeating command block is facing put an always active chain command block (can be conditional if you make it face the same way) containing this command:
/scoreboard players set @e[scores={deaths=1..}] deaths 0
This kills all entities except for players in a radius of 10 around the dead player.
You could use scoreboard
objectives...
/scoreboard objectives add youDied deathCount
The deathCount
will automatically increase when someone dies.
Now you can run a clock to test for it:
/testfor @a[score_youDied_min=1]
(1 = one death, you could as well use a higher number to grant them multiple lives before it resets)
The command to kill the mobs is /kill @e[x,y,z,r,type=!Player]
and don't forget to reset the death count:
/scoreboard players set @a youDied 0
execute
instead of testfor
.
Commented
Nov 3, 2017 at 9:54
/kill @e[x,y,z,r,type=!Player]
work as well?
execute @a[score_deaths_min=1] 12 34 56 <command>
.
Commented
Nov 3, 2017 at 10:57
/testfor
, which no longer exists./testfor
. This question is still a duplicate for a version that did have that command working still, thus people searching for 1.8 that find this question would be lead back to the correct answer.