I am making a map in Minecraft that other people can play. I have a dispenser with an iron, golden and diamond sword in it. I want the player to be able to use this dispenser only once. How would I do this?
Minecraft – Is it possible to invalidate a dispenser after it has been used once
minecraft-java-editionminecraft-redstone
Related Solutions
As of 14w10c, this is possible using scoreboard values.
First, you need to set up a dummy scoreboard variable. I used "sneaky" as my variable, but you can really use whatever you want (as long as you change the commands as appropriate). To set this up, you just need to use the command /scoreboard objectives add sneaky dummy
. You only need to do this once.
I had to set up the command blocks in a very specific pattern for them to work, as shown:
I think this has something to do with how command blocks handle firing off "simultaneously". The comparator in this setup is in subtraction mode, creating a "comparator clock" which pulses very quickly.
The command blocks on the left are your scoreboard related commands. The one on the bottom left sets "sneaky" to 0 for all players:
/scoreboard players set @a sneaky 0
The command block on the top left sets "sneaky" to 1 for all players with the stealth boots equipped:
/scoreboard players set @a sneaky 1 {Inventory:[{Slot:100b,tag:{display:{Name:"Stealth Boots"}}}]}
The command blocks on the right are your effect commands. They give players the invisibility effect, or take it away, as appropriate. The one on the bottom clears the invisibility effect from all players without the stealth boots:
/effect @a[score_sneaky=0] 14 0 0
The top one gives the invisibility effect to all players with the stealth boots:
/effect @a[score_sneaky_min=1] 14 30000
It's very difficult to see whether someone has an object anywhere in their inventory. That would take 36 command blocks, one for each slot! You can, however, take the object, then see if taking the object worked.
The Commands
- Set up a fast clock (but not as fast as a fill clock)
- One command block does
/clear @p iron_ingot 0 1
(clears 1 iron ingot from the nearest player. You can choose which player, but it must be exactly one. Also, you must use the same selector throughout all these commands.) - Run a comparator from that command block to another command block running this command:
/scoreboard players add @p ironIngots 1
(Increases the player'sironIngots
score by 1. Make sure you createironIngots
first!) - Create another command block that does whatever you want. In the case of giving them a diamond, you would do this:
/give @p[score_ironIngots_min=10] diamond
. Note the target selector; it gives the player the diamond only if their ironIngots score is 10 or greater. - The last thing you want to do is take the ironIngots score away so they don't keep getting items. Just run
/scoreboard players remove @p[score_ironIngots_min=10] ironIngots 10
. This removes 10 iron ingots from the player if they have anironIngots
score of 10 or greater. Any player who matches this will have received a diamond in the previous step.
How to Set Them Up
The commands listed above must run in order. It is actually very simple to put them in order. Just open the debug menu and look at the stylish new crosshair. Align the command blocks along either the green or red line so that one of those lines points down the first to the last command block.
Notes
- You don't have to press a button to use this, you just have to be the nearest player. You can change the command to the nearest player within 10 blocks, nearest player on a team, etc.
- The commands will take a short amount of time to finish, but for 10 iron ingots, it will only take half a second. It's one tick (1/20 of a second) per item taken away.
- It will take away iron ingots even if you don't have ten. However, you can submit one, then later submit five, then submit four more later, and it will still give you the diamond. You can also submit 14 at a time and the extra 4 will be saved for later.
Best Answer
Make the switch also activate some water (a current passing glitched water will make it flow normally) to wash away part of the redstone, stopping further current.