How can I target a player after detecting an item in their inventory

How can I target a player after detecting an item in their inventory - Titrist Golf Ball Near Golf Hole

If I detect a player having a nether star in his inventory, and it detected let's say "XPhotoCrafterX", how can I make it so it automatically effects him with strength 3?

I've tried to search on google but it didn't work.



Best Answer

You will need to assign a label to the player based on their NBT data first and then target based on their label. /testfor will not be useful as it does not label the players that were found.

1.9

No objectives needed.

/scoreboard players tag @a[tag=HasItem] remove HasItem
/scoreboard players tag @a[tag=!HasItem] add HasItem {Inventory:[{id:"minecraft:nether_star"}]}

And then you'd target them with the tag parameter.

/effect @a[tag=HasItem] minecraft:strength 1 3

1.8

Objective required.

/scoreboard objectives add HasItem dummy

Run on a clock in presented order.

/scoreboard players set @a HasItem 0
/scoreboard players set @a HasItem 1 {Inventory:[{id:"minecraft:nether_star"}]}

Players will have their "HasItem" score set to 1 if they have a nether star in their inventory. You can then target them based on their score.

/effect @a[score_HasItem_min=1] minecraft:strength 1 3



Pictures about "How can I target a player after detecting an item in their inventory"

How can I target a player after detecting an item in their inventory - Carefree curling players on ice
How can I target a player after detecting an item in their inventory - Amazed man in sportswear with opened mouth and broom playing curling on ice sheet with circular target area during game in playing area
How can I target a player after detecting an item in their inventory - Sportspeople with curling equipment on ice



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!




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

Images: tyler hendy, SHVETS production, SHVETS production, SHVETS production