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?