1

I am attempting to make a shop in which you can trade a number of items for coins (ender stars).

I'm using the /testfor command to see if they're on the right team and /clear to remove the items, however, when someone presses the button with only one item their one item is removed and they get the coin even though the shop requires you to pay 5 items.

How do I make it so it tests to see if they have the minimum amount of items in their inventory before it clears the item and gives them the coin?

  • 1
    Try a dummy scoreboard objective for (if there is one) stat.pickup.### – Reflexive Jan 30 '17 at 3:38
0

You can use CommandStats to accomplish this:

Prerequisites:
Objective to track player inventories of items.

/scoreboard objectives add ITEMS dummy

Detection Commands:
Run the following commands first, whenever you're testing for the items in the players inventory:

/stats entity @a set AffectedItems @a[c=1] ITEMS
/scoreboard players add @a ITEMS 0

Then run this command to write the amount of items into the players "AffectedItems" score (change to whatever item you want to test for):

/execute @a ~ ~ ~ clear @a[c=1] minecraft:iron_ingot 0 0

Summary:

The above setup will set the players' "ITEMS" score to the number of iron ingots in their inventory, without removing any items. You will then be able to detect players using that score. For example, detecting if a player has at least 5 iron ingots:

/testfor @a[score_ITEMS_min=5]

taken and adapted from http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2164463-test-for-multiple-items-in-someones-inventory#c7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.