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)
It's very difficult to see whether someone has an object anywhere in their inventory. That would take 36 command blocks, one for each slot! You can, however, take the object, then see if taking the object worked.
The Commands
- Set up a fast clock (but not as fast as a fill clock)
- One command block does
/clear @p iron_ingot 0 1
(clears 1 iron ingot from the nearest player. You can choose which player, but it must be exactly one. Also, you must use the same selector throughout all these commands.)
- Run a comparator from that command block to another command block running this command:
/scoreboard players add @p ironIngots 1
(Increases the player's ironIngots
score by 1. Make sure you create ironIngots
first!)
- Create another command block that does whatever you want. In the case of giving them a diamond, you would do this:
/give @p[score_ironIngots_min=10] diamond
. Note the target selector; it gives the player the diamond only if their ironIngots score is 10 or greater.
- The last thing you want to do is take the ironIngots score away so they don't keep getting items. Just run
/scoreboard players remove @p[score_ironIngots_min=10] ironIngots 10
. This removes 10 iron ingots from the player if they have an ironIngots
score of 10 or greater. Any player who matches this will have received a diamond in the previous step.
How to Set Them Up
The commands listed above must run in order. It is actually very simple to put them in order. Just open the debug menu and look at the stylish new crosshair. Align the command blocks along either the green or red line so that one of those lines points down the first to the last command block.
Notes
- You don't have to press a button to use this, you just have to be the nearest player. You can change the command to the nearest player within 10 blocks, nearest player on a team, etc.
- The commands will take a short amount of time to finish, but for 10 iron ingots, it will only take half a second. It's one tick (1/20 of a second) per item taken away.
- It will take away iron ingots even if you don't have ten. However, you can submit one, then later submit five, then submit four more later, and it will still give you the diamond. You can also submit 14 at a time and the extra 4 will be saved for later.
Best Answer
Use target selectors, and use
/execute
to make it happen.This will detect any players within 10 blocks of XYZ (10, 20, 30), and if any are found, it sets a redstone block at a certain position, whether to run more commands, or to open an iron door.
And to detect the name, use the
name
argument.Combine these all together and you get:
Learn more about these commands and mechanics on the Minecraft Wiki:
/execute
Command