How to execute when someone is wearing specific item

I'm trying to make Thor's hammer and armor, but I need to execute when someone is wearing Thor's armor, because i am trying to do lightning when someone kills 10 entities and i want only with Thor's armor and hammer could "rage" (make lightning).


Solution 1:

Give the armor items a custom item tag so that they're easy to detect and impossible to fake:

give @p iron_chestplate 1 0 {thorArmor:1b,display:{Name:"Thor's Chestplate"},Unbreakable:1b}

Then whenever you want to do something with players who are wearing the armor, run these commands:

scoreboard players tag @a[tag=wearingThorChest] remove wearingThorChest
scoreboard players tag @a add wearingThorChest {Inventory:[{Slot:102b,tag:{thorArmor:1b}}]}
say @a[tag=wearingThorChest] is/are wearing Thor's Chestplate!

102b is the chest armor slot. You can find the other slot numbers on the Wiki: https://minecraft.gamepedia.com/Player.dat_format#Inventory_slot_numbers

You can do something similar with the mainhand item:

scoreboard players tag @a[tag=holdingMjolnir] remove holdingMjolnir
scoreboard players tag @a add holdingMjolnir {SelectedItem:{tag:{thorHammer:1b}}}
say @a[tag=holdingMjolnir] is/are holding Mjolnir!