Is it possible to mark or modify a player with a specific item in their inventory
I'm building a CTF map of sorts, using command blocks in vanilla 1.8. I've discovered two commands for detecting if an item is in a players inventory:
/clear @a[team=Red] banner 4 0
/testfor @a[team=Red] {Inventory:[{id:"minecraft:banner"}]}
Those work fine, unless you want to perform a command ON the player carrying that item. For example: I want to cause the player who picks up a banner of the opposite team, to automatically equip that banner in their head slot with a command similar to this:
/replaceitem entity @a[???????] slot.armor.head banner 1 4
Can this be done? If not, is there a way to mark a specific player carrying an item using scoreboards?
Best Answer
As of 1.13, doing this no longer needs a scoreboard and can be done in one command block:
/execute as @a[nbt={Inventory:[{id:"blue_banner"}]}] run ...
Pictures about "Is it possible to mark or modify a player with a specific item in their inventory"



How do you mark a player in Minecraft?
The command could be: /mark <add/remove> <player> <mark>. That means, /mark, if you want to add or remove a mark, who you want to add or remove it from, and then the actual name of the mark you want to add or remove.Check Player Inventories for 'Named' Items *Kind Of* / Buff Players Who Have Certain Items!
More answers regarding is it possible to mark or modify a player with a specific item in their inventory
Answer 2
First, you need to set up a dummy scoreboard objective:
scoreboard objectives add hasFlag dummy
Now, create a 20 Hz. clock, such as a fill clock or use minecraft 1.9's repeat and chain command blocks to run the following commands in order:
scoreboard players set @a hasFlag 0
scoreboard players set @a hasFlag 1 {Inventory:[{id:"minecraft:banner",Damage:4s}]}
This ensures that the flag-bearer (i.e. the player with a blue banner) has a hasFlag score of 1, and it's 0 for everyone else. Note that you can modify the data tag in the second command to your liking, using any of the NBT tags available for players.
Now, we can do whatever we want with that scoreboard, by using the score_hasFlag_min=1 target selector argument to target only flag-bearers, or score_hasFlag=0 to target everyone else. These commands have to be run on the same clock, after the above commands. For example:
replaceitem entity @a[score_hasFlag_min=1] slot.armor.head minecraft:banner 1 4
replaceitem entity @a[score_hasFlag=0] slot.armor.head minecraft:air 1
Note: In 1.9, you can opt for using scoreboard tags instead of a dummy objective.
Answer 3
The command to put it on a players head is:
/replaceitem entity slot.armor.head minecraft:banner [amount] [datatag]
and that would place the banner in the helmet position, but the banner will be sticking out of the back of the head which doesn't look all that good but it still works and you can always try using wool if you prefer that. Also the datatag is that color of the flag whichever number in place of that will determine the color of the banner and you have to remember that you have to have an amount if you have a datatag.
Datatags:
Black = 0
Red = 1
Green = 2
Brown = 3
Blue = 4
Purple = 5
Cyan = 6
Light Grey = 7
Grey = 8
Pink = 9
Lime = 10
Yellow = 11
Light Blue = 12
Magenta = 13
Orange = 14
White = 15
Answer 4
Use a dummy scoreboard to keep track of what players are valid. For example the dummy scoreboard is isCarryingFlag
/scoreboard players isCarryingFlag 1 @a[team=Red] {Inventory:[{id:"minecraft:banner"}]}
/excecute @a[isCarryingFlag=1]
/scoreboard players isCarryingFlag 0 @a
Run these commands in order.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ketut Subiyanto, Ollie Craig, cottonbro, Ellie Burgin
