So I am making a capture the flag game. I have a objective for picking up the flag:

/scoreboard objectives add red_flag stat.mineBlock.minecraft.wool Has the red flag

I want it so that when a player dies, if the have the flag, they drop it where they were standing, (as a block, using setblock). I tried, where h is a health scoreboard:

execute @p[score_h=0] ~ ~ ~ setblock ~ ~1 ~ wool 14

This doesn't work, because the player is dead, and score_h=1 means that if a player has exactly 1/2 heart, then they continuously setblock wool.

Currently, the only solution I can think of is this command, and /kill all players with 1/2 heart. I would like a cleaner solution. Any ideas?

  • Have you tried adding a scoreboard to detect whether he has the flag? Look at gaming.stackexchange.com/questions/192640/…. This time, attempt to /clear the flag. – aytimothy Dec 15 '14 at 17:33
  • I have a solution that's much too complicate for me to put in an answer right now (see here for a hint), and it could use some refinement, but it should do everything you want. – MBraedley Dec 16 '14 at 2:59
  • You could set it so the wool item is dropped and the 'Owner' tag is set to the player who broke the block. Then the player can drop the flag into a hopper at their base, which is disabled when the enemy flag is not captured. – Chemical Comrade Dec 12 '16 at 7:49

Have you tried adding a scoreboard to detect whether he has the flag? Look at how to get and store player name? This time, attempt to /clear the flag.
– aytimothy

I've answered a question looking to identify a player, and perform something at their death.

Long story short, follow the instructions to make the gate and to identify the players, but replace the /clear command in the second step with:

/clear @p[score_playerID=1,score_playerID_min=1] minecraft:Wool 14 0

and the identifier with something else like... Say:

/scoreboard objectives create hasWool dummy hasWool
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasWool 1
/scoreboard players set @p[score_playerID=1,score_playerID_min=1] hasWool 0

in order to identify whether someone has the flag or not. (This only works with /gamerule keepinventory true.)

Next, when the player dies, simply do your command, since you know that they're dead, and they have the wool.


These commands all work, but the problem is: if the player is dead, they can't execute commands. You can't /execute as a player if the player is dead.
– xornob

Let's say we'll use a Creeper to be the placeholder for the /execute command.

Run the conditional flip-flop gates (outlined in that first answer), testing for /testfor @a[score_h=0,hasWool_min=1] (looks for a player who's dead and had the wool.

When a player is dead and has the wool (condition sets to true), run /tp @e[type=Creeper] @p[score_h=0,hasWool_min=1], make that creeper place the block /execute @e[type=Creeper] ~ ~ ~ setblock ~ ~1 ~ wool 14 and teleport away /tp @e[type=Creeper] 0 0 0.
The false condition is up to you; you can either make it teleport the creeper back (since it's already done when the true condition runs anyway)

Just make sure that command is executed before they are respawn (or gets teleported to the respawn point)

Note: You can't directly @a as when you use /clear @a minecraft:Wool 14 0, it'll output true to everyone, even if only one person has it, while @p just gets messy. (You're detecting the closest player)

  • /execute @p[score_h=0,hasWool_min=1] ~ ~ ~ setblock ~ ~1 ~ wool 14 doesn't work, no matter how long before they respawn though. – xornob Dec 15 '14 at 18:08
  • @xornob That was the command you gave me. Have you tried removing the first /? And have you actually read the answer I've linked you to? In case: gaming.stackexchange.com/questions/192640/… – aytimothy Dec 15 '14 at 18:14
  • These commands all work, but the problem is: if the player is dead, they can't execute commands. You can't /execute as a player if the player is dead. – xornob Dec 16 '14 at 5:52
  • Have you tried teleporing [any mob, like an armor stand] to that dead player and then making it do the /execute instead? – aytimothy Dec 16 '14 at 6:10
  • EDIT: Creeper in the example given in the edited answer. – aytimothy Dec 16 '14 at 6:17

@MBraedley pointed out that dead players aren't valid targets for teleportation.

Disclaimer: The following idea should work, but I haven't tested it yet.

This answer requires the red_flag objective to work correctly. That is, it should be 1 for the player that carries the red flag, and 0 for everyone else.

Run these once

/summon ArmorStand 0 0 0 {Invisible:1,Marker:1,NoGravity:1,CustomName:"Marker"}

Then run these on a fast clock

/tp @e[type=ArmorStand,name=Marker] @p[score_red_flag_min=1]

This will make an invisible Armor stand with no hitbox continuously teleport to flag-bearer.

The moment the flag carrier dies, the tp command fails continuously, until a new valid target appears. Grab the output of tp with a comparator and invert the signal using a torch. Note that the comparator signal will be constant, unless something changes, according to the wiki:

SuccessCount: Represents the strength of the analog signal output by redstone comparators attached to this command block. Only updated when the command block is activated with a redstone signal.

This means, that the torch will be continuously on when no one has the flag and turn off when someone picks up the flag, after which it is continuously off. It will turn on exactly the moment the tp command fails, at which point it will power another command block with

/execute @e[type=ArmorStand,name=Marker] setblock ~ ~ ~ minecraft:wool 14 keep

Note that this will also happen when the red_flag objectives drops below 1 for any reason other than death, such as scoring. This can be easily remedied by removing all red wool blocks from the scoring area using

/fill <x1> <y1> <z1> <x2> <y2> <z2> minecraft:air replace minecraft:wool 14
  • +1 Less messy (more compact), but still as efficient as mine. – aytimothy Dec 16 '14 at 22:48
  • This is basically what I came up with last night, although I was actively checking the inventory of players for the wool to set the scoreboard (I think it's less error prone) and teleporting the marker (I used a whither skull) each tick. I did this to ensure that the marker was always where the player was because I didn't think they were a valid target when they were dead. – MBraedley Dec 17 '14 at 2:20
  • @MBraedley that's actually not a bad idea. You could then also make the Armor Stand wear a red banner on their head. This way, the player actually carries a flag with them. – MrLemon Dec 17 '14 at 13:21
  • @MrLemon I did more testing last night, and I couldn't get the marker to tp to a just died player, although come to think of it, I may have been resetting the death score too quickly. – MBraedley Dec 17 '14 at 14:05
  • @MBraedley I admit that I never actually tested this, so it's very well possible that it doesn't work. I'll change the answer to your working version, though I'll rely on the has_flag objective to work correctly. I'll run some tests when I am home. – MrLemon Dec 17 '14 at 14:08

The @a selector is the only selector capable of targeting dead players. You can set the c (maximum targets) parameter to 1 to reduce the number of targets.

You would need to track player deaths with the deathCount objective-type instead of health (which is read-only), as the dead player would otherwise constantly be setting the block:

/scoreboard objectives add deaths deathCount

The following would need to be run in numerical order:

  1. Cause dead players to run a /setblock command.

    /execute @a[score_deaths_min=1,score_red_flag_min=1,c=1] ~ ~ ~ /setblock ~ ~ ~ minecraft:wool 14
  2. Reset the "deaths" score so the previous command does not constantly run.

    /scoreboard players reset @a[score_deaths_min=1,score_red_flag_min=1] deaths

I have an idea no-one proposed so far, also I'm not sure: Are you OK with using mods?

If you are, you can use the OpenBlocks mod, the GraveStone mod or any other mod that generates gravestones upon player death, and then repeatedly run a command replacing all gravestone blocks containing red wool block items with a red wool block.

(Not sure about the GraveStone mod, the OpenBlocks mod however should work cleanly when installed to the server only, at least the Forge version, I know that from LeKoopa's ChaosCraft projects. To those who don't know LeKoopa, it's a german MineCraft youtuber with lots of mod projects - mod reviews, multiplayer mod LP, lucky block minigames and untextured (as in all TNT textures are replaced by white wool textures) Too Many TNT survival quests are just a few examples.)

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.