What i mean by the title is if an item is in slot x (x being any slot) and not selected it gives no effect, but if the item is selected it gives you a certain effect for however long you hold the item.
Type this command in a command block: /testfor @p {Inventory:[{Slot:Xb,id:"minecraft:SAY_WHATEVER_ITEM_SHOULD_BE_IN_'X'_"}]} However this command does only work in the 1.8 snapshots (or release when that comes out) or higher. Hope this helped! P.S. If you want to constantly check, hook up a clock to the command block.
Rollback Post to RevisionRollBack
Whats that? Something about Villagers? You have come to the right person. P.S. I shall expect my payment in emeralds for this valuable information of these mysterious beings with the peculiar long nose. Oops! I have said too much!
Type this command in a command block: /testfor @p {Inventory:[{Slot:Xb,id:"minecraft:SAY_WHATEVER_ITEM_SHOULD_BE_IN_'X'_"}]} However this command does only work in the 1.8 snapshots (or release when that comes out) or higher. Hope this helped! P.S. If you want to constantly check, hook up a clock to the command block.
will entering x instead of 0-8 test every slot if not its going to be a bunch of command blocks and i found dragonz's videos on this earlier and i basically did that which is like 81 command blocks if you want to test for 9 different items. Thank you all who have replied
will entering x instead of 0-8 test every slot if not its going to be a bunch of command blocks and i found dragonz's videos on this earlier and i basically did that which is like 81 command blocks if you want to test for 9 different items. Thank you all who have replied
If they items being checked are custom items, you can apply some extra data to them, reducing the amount of needed command blocks. What you'll do is apply an attribute modifier to the item, which will apply it to the player if they hold/wear the item. For example:
When the player holds it, their maxHealth will increase by 0, which essentially means that it doesn't do anything to the players' attributes. What it will do is add a modifier to the Modifiers list, which we can detect:
/testfor @a {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}
or
/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}
With the second command, you can use that assigned score to target the specific player who are holding the item:
/say @a[score_OBJECTIVE_min=1]
Thus no need to detect every one of the hotbar slots individually.
If they items being checked are custom items, you can apply some extra data to them, reducing the amount of needed command blocks. What you'll do is apply an attribute modifier to the item, which will apply it to the player if they hold/wear the item. For example:
When the player holds it, their maxHealth will increase by 0, which essentially means that it doesn't do anything to the players' attributes. What it will do is add a modifier to the Modifiers list, which we can detect:
/testfor @a {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}
or
/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}
With the second command, you can use that assigned score to target the specific player who are holding the item:
/say @a[score_OBJECTIVE_min=1]
Thus no need to detect every one of the hotbar slots individually
So do you mean that if the item is in any of the hot bar slots and that slot is selected, that the user will get the effect but if the slot is not selected then the effect is not active?
In Skylinerw's way, if you give the player the item using the command he used and then make a clock which will use the command: "/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}" Like he said, then anytime the item will be in the selected slot the player's objective "OBJECTIVE" will be 1... So then you can do stuff like "/effect @a[score_OBJECTIVE_min=1]..." and the effect would be only on the players holding the item. If you want the effect to disappear after he's not holding the item anymore, make the /effect command in a fast clock and every time give the player the effect for only 1 second so when he's not holding the item anymore the effect would disappear... And in the clock with the /scoreboard command, use the command "/scoreboard players set @a OBJECTIVE 0" in the same clock right before the other command...
In Skylinerw's way, if you give the player the item using the command he used and then make a clock which will use the command: "/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:generic.maxHealth,Modifiers:[{Name:"HELD"}]}]}" Like he said, then anytime the item will be in the selected slot the player's objective "OBJECTIVE" will be 1... So then you can do stuff like "/effect @a[score_OBJECTIVE_min=1]..." and the effect would be only on the players holding the item. If you want the effect to disappear after he's not holding the item anymore, make the /effect command in a fast clock and every time give the player the effect for only 1 second so when he's not holding the item anymore the effect would disappear... And in the clock with the /scoreboard command, use the command "/scoreboard players set @a OBJECTIVE 0" in the same clock right before the other command...
nice thats what i was looking for but since I'm new to command block i have to take the time to learn setting up objectives effectively
Will I be able to use the fill clock with the "/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:"HELD"}]}]}" and the objective 0 command? or do i need a slower clock?
I think fill clock is he best for this situation but you basically can use any clock if you know which command comes first.. In a full clock the command that is in the smallest x, y or z is first so you can know that you can first set it to 0...
If you don't know how to do it, to setup the objective you need to use the command: "/scoreboard objectives add OBJECTIVE dummy"
But make sure yo gave the player the item using the command Skylinerw said...
I think fill clock is he best for this situation but you basically can use any clock if you know which command comes first.. In a full clock the command that is in the smallest x, y or z is first so you can know that you can first set it to 0...
If you don't know how to do it, to setup the objective you need to use the command: "/scoreboard objectives add OBJECTIVE dummy"
But make sure yo gave the player the item using the command Skylinerw said...
Okay thank you that will help me a lot, using the first command to give the item how would i alter it so that the item is also renamed?
Thanks to those who comment with help.
Erros
Whats that? Something about Villagers? You have come to the right person. P.S. I shall expect my payment in emeralds for this valuable information of these mysterious beings with the peculiar long nose. Oops! I have said too much!
will entering x instead of 0-8 test every slot if not its going to be a bunch of command blocks and i found dragonz's videos on this earlier and i basically did that which is like 81 command blocks if you want to test for 9 different items. Thank you all who have replied
If they items being checked are custom items, you can apply some extra data to them, reducing the amount of needed command blocks. What you'll do is apply an attribute modifier to the item, which will apply it to the player if they hold/wear the item. For example:
When the player holds it, their maxHealth will increase by 0, which essentially means that it doesn't do anything to the players' attributes. What it will do is add a modifier to the Modifiers list, which we can detect:
With the second command, you can use that assigned score to target the specific player who are holding the item:
Thus no need to detect every one of the hotbar slots individually.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
So do you mean that if the item is in any of the hot bar slots and that slot is selected, that the user will get the effect but if the slot is not selected then the effect is not active?
nice thats what i was looking for but since I'm new to command block i have to take the time to learn setting up objectives effectively
Will I be able to use the fill clock with the "/scoreboard players set @a OBJECTIVE 1 {Attributes:[{Name:"HELD"}]}]}" and the objective 0 command? or do i need a slower clock?
If you don't know how to do it, to setup the objective you need to use the command: "/scoreboard objectives add OBJECTIVE dummy"
But make sure yo gave the player the item using the command Skylinerw said...
Okay thank you that will help me a lot, using the first command to give the item how would i alter it so that the item is also renamed?