How to /testfor at least 10 items? [duplicate]
I used this command:
/testfor @p[score_Room1_min=2,score_Room1=2] {Inventory[{id:minecraft:dye,Damage:1s,tag:{display:{Name:"Body part"}},Count:10b}]}
It all works, but only when I have 10 body parts.
How can I test for at least 10, for example 11 or 12 without needing to make new command blocks?
Best Answer
/testfor also does not have multi-target support. It just tells you there was a match, but not who that match was, and therefore you cannot target that player afterwards.
Even further, if there were multiple players with a "Room1" score of 2 and because you're only targeting the closest one of those, only that player will have their NBT data checked. The selector is processed before the NBT data, so if that player did not match, the command fails (even if the further player could've matched).
Checking NBT data requires you to specify exact values. For a range, you must use CommandStats to store the number of items the player has as a score, which is multi-target friendly. This also has the benefit of not requiring those items to be in the same stack.
Prerequisites
Objective to hold return value from CommandStats.
/scoreboard objectives add ItemCount dummy
Trigger to apply to players. The player will target their own "ItemCount" score when they run a command that returns an "AffectedItems" value (in this case, it'll be /clear). If new players can join at any time, you may need to run this on a clock.
/stats entity @a set AffectedItems @a[c=1] ItemCount
In order for CommandStats to modify its target's score, that target must be tracked on the scoreboard prior. This may also need to run on a clock.
/scoreboard players add @a ItemCount 0
Detection
Now when a player runs /clear, their "ItemCount" score will be set equal to the number of items cleared. If you set the maximum amount to 0, then the return value is the total number of those items in the player's inventory.
/execute @a ~ ~ ~ /clear @a[c=1] minecraft:dye 1 0 {display:{Name:"Body part"}}
And you can then target players based on their "ItemCount" score.
/say @a[score_Room1_min=2,score_Room1=2,score_ItemCount_min=10] has 10+ items.
Pictures about "How to /testfor at least 10 items? [duplicate]"
![How to /testfor at least 10 items? [duplicate] - Bike Chain Forming 1 and 0 How to /testfor at least 10 items? [duplicate] - Bike Chain Forming 1 and 0](/assets/images/how_to_testfor_at_least_10_items_duplicate_1.jpeg)
![How to /testfor at least 10 items? [duplicate] - Number 10 Text How to /testfor at least 10 items? [duplicate] - Number 10 Text](/assets/images/how_to_testfor_at_least_10_items_duplicate_2.jpeg)
![How to /testfor at least 10 items? [duplicate] - 10 and 20 Euro Bill How to /testfor at least 10 items? [duplicate] - 10 and 20 Euro Bill](/assets/images/how_to_testfor_at_least_10_items_duplicate_3.jpeg)
How do you use Testfor items?
You can test whether there is a certain block at a specific location in the game using the /testforblock command in Minecraft....TestForBlock Command in Minecraft Java Edition (PC/Mac)How do you test for a player holding an item?
You can test for a certain target in the game using the /testfor command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /testfor command was removed from the Java Edition version of the game.Minecraft: ITEM DUPLICATION BUG! (1.7 \u0026 14w03b)
More answers regarding how to /testfor at least 10 items? [duplicate]
Answer 2
Ill just get into to it:
First of all do this:
/scoreboard objective add BodyParts dummy
To give the item:
/give @p dye 1 1 {UnCounted:1b,{display:{Name:"Body part"}}
then have a command block doing this: (Repeating Command Block/Command Block on a clock)
/clear @p[score_Room1_min=2,score_Room1=2] dye 1 1 {UnCounted:1b}
then have a command block doing this: (Chain Commmand Block on Conditional/Comperator to another command block)
/scoreboard players add @p[score_Room1_min=2,score_Room1=2] BodyParts 1
then last command block on Chain Conditional again or Comperator to command block again:
/give @p[score_Room1_min=2,score_Room1=2] dye 1 1 {display:{Name:"Body part"}
Now that should add one to the BodyParts scoreboard and quickly replace the item held by the person.
Side Notes:
- This will only work if 1 person has the score Room1 of 2 if you want me to optimize it for multiplayer please comment.
- If in 1.9 all the repeat and chain command blocks must be always active
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Karolina Grabowska, Miguel Á. Padriñán, Magda Ehlers, Markus Spiske
