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. Can anyone help me please?

  • 1
    I guess I'm more strict in that sense. I've make an edit request. – Fabian Röling Nov 3 '17 at 12:31
  • How about just when they respawn, there's a pressure plate or command block to check if player's nearby, then kill all mobs? – MCMastery Nov 3 '17 at 15:08

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[score={deaths=1..}] deaths 0

This kills all entities except for players in a radius of 10 around the dead player.

  • Would that be in the area they would respawn or in the area where the mobs were? – Comyak Nov 3 '17 at 10:00
  • It's at the death location. The player location is set to the respawn location as soon as they click "respawn", but since this runs 0,05s after the death, the player probably didn't click that yet, especially because the buttons need a bit of time to become clickable. – Fabian Röling Nov 3 '17 at 10:37
  • Did you already publish the map and link to this question? I'm getting an unusual amount of upvotes. It's my second most upvoted answer on this site (5th most upvoted post overall) and that in just 5 hours. – Fabian Röling Nov 3 '17 at 15:27
  • 2
    @Fabian this question got into Hot Network Questions (HNQ) bar which is shown on the right side on all SE sites. It means more exposure and more upvotes (due to association bonus rep). – antimo Nov 3 '17 at 18:26
  • 2
    That's not a point of consistency, it's a point of actually working. @a selects all players, @e selects all entities. It's intended how it is. – Fabian Röling Nov 3 '17 at 22:08

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

  • He wants to kill all entities in an area, so you have to use execute instead of testfor. – Fabian Röling Nov 3 '17 at 9:54
  • @Fabian yep I forgot about the kill radius, but wouldn't /kill @e[x,y,z,r,type=!Player]work as well? – dly Nov 3 '17 at 10:09
  • Only if you knew the coordinates of the player before writing that command. – Fabian Röling Nov 3 '17 at 10:35
  • probably in the dungeon, which is known :P (radius can be applied as well) – dly Nov 3 '17 at 10:53
  • Ok, but it's still more effort and one command block more. If you want fixed coordinates, you can just use execute @a[score_deaths_min=1] 12 34 56 <command>. – Fabian Röling Nov 3 '17 at 10:57

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.