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)
This answer was written prior to the release of 1.13 and "The Flattening" that came with it. An updated answer can be found here.
You're actually pretty close, and definitely on the right track. Instead of {Inventory:[{id:<block ID>,data:<data value>}]}
, use {Inventory:[{id:<block ID>,Damage:<data value>s}]}
. The s
after the data value is important since it's stored as a short, not as an int. (As an aside, if it were stored as a byte, you would append a b
instead.)
Best Answer
I figured out how to do this. I use the
stat.damageDealt
scoreboard objective. First I run the following command once:Then on the 20Hz clock I do the following:
First command block:
/tellraw @a[score_hit_min=1] "Nice Hit!"
Second command block:
/scoreboard players reset @a[score_hit_min=1] hit
How this works is that points is added to the
stat.damageDealt
objective each time they hit/attack/hurt an entity or player. Then it runs the command on every player that has hurt another entity or player. When that command is done, the objective gets reset.How I found this is that on the statistics menu from the pause menu, there is a statistic called Damage Dealt.
EDIT:
In Minecraft 1.9, use the repeating command block instead of a 20Hz clock.