How do I apply a specific command to a player wearing certain gear? [duplicate]

How do I apply a specific command to a player wearing certain gear? [duplicate] - A Woman Smiling and Holding Tennis Racket

I am trying to create a game where different potion effects are applied to a player depending on what armor the player is wearing (all of the armor is leather, but named and dyed). I know all of the ins and outs of it (test for a player wearing the gear sends out a signal which applies an effect), but how do I apply the affect to that player wearing the gear. Using @p or @a to specify wont work with multiple people as it will specify everyone or anyone.



Best Answer

Use scoreboard to keep track of players wearing the gear.

Setup:

/scoreboard objective set isTarget dummy

Clock:

/scoreboard players set @a isTarget 0
/scoreboard players set @a isTarget 1 {Inventory:[{Slot:<Slot>,id:<Item>}]}
/effect @a[score_isTarget_min=1]

Slot is the slot that you wish to search. Head armor slot is 103 and going in decreasing order to foot 100. Id is the item you want to test for.




Pictures about "How do I apply a specific command to a player wearing certain gear? [duplicate]"

How do I apply a specific command to a player wearing certain gear? [duplicate] - A Woman in White Shirt Holding a Tennis Racket
How do I apply a specific command to a player wearing certain gear? [duplicate] - A Boy Sitting in the Locker Room Wearing Long Sleeve Shirt with Paddings
How do I apply a specific command to a player wearing certain gear? [duplicate] - A Boy Wearing a Hockey Helmet



How do you detect what armor a player is wearing Minecraft?

Yes, it is possible to put colored armor on a person using a command. To equip players with armor or other items, you can use the /replaceitem command. The syntax of /replaceitem for replacing items in an inventory is /replaceitem entity <selector> <slot> <item> [amount] [data] [dataTag] .

How do you put armor on someone with commands?

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.



Minecraft 1.16.5: How to summon a custom mob with armor and weapon




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Artem Podrez, Artem Podrez, Ron Lach, Ron Lach