Detect *where* a specific player died?

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.

Update:

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)


@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 this once

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

Then run this 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

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