Thief Minigame. Check inventory for specific amount and apply effect
I'm making a Minigame for Minecraft. I want a thief to get gold by standing near a gold block.
Once the player has more then a specific amount(say he has 64 gold) an effect will be applied to the player such as Slowness. i already tried command blocks using some Video's on youtube But that didnt work at all
The game is team based so I only want a specific team to be able to get the gold.
Here is a solution, it uses a scoreboard and commandstats. It will use 3 command blocks in a repeating chain:
First you need to manually create a scoreboard objective:
/scoreboard objectives add Amount dummy
I also recommend disabling command block output to prevent chat spam with command:
/gamerule commandBlockOutput false
The first block clears the item of your choosing with an amount of 0. It clears no items from the inventory, but it still affects the specified item. The second block stores how many items were affected in the objective Amount
. This objective now has total number of the item specified in the first command block that is in the players inventory. The third block applies the effect
First block is Repeat Unconditional Always Active with command:
clear @a minecraft:gold_ingot 0 0
Second block is Chain Conditional Always Active with command:
stats block ~1 ~ ~ set AffectedItems @a Amount
Third block is Chain Conditional Always Active with command:
effect @a[score_Amount_min=100] minecraft:slowness 1 2
This will apply level 2 slowness effect to any player with 100 or more gold ingots.
Note: The coordinates in the second command block should be the coordinates for the first command block. It could be X or Z +/- 1.
Here is a method of making the gold block give the player gold ingots. Set a gold block where ever you want it to be. Jump on top of it and use the command:
/summon armor_stand ~ ~-1 ~ {Tags:["TheftBlock"],Invulnerable:1,Invisible:1,NoGravity:1}
Set another Repeat Unconditional Always Active command block and give it command:
execute @e[tag=TheftBlock] ~ ~ ~ give @a[r=1] gold_ingot 1
This will give any player a gold ingot every tick they are standing near the gold block. Once they get more then 100, the above command blocks would apply a slowness effect.
You mentioned only a specific team being able to 'steal' the gold. In that case, just change the last command block command to:
execute @e[tag=TheftBlock] ~ ~ ~ give @a[r=1,team=TEAMNAME] gold_ingot 1
Change TEAMNAME
to the team name of the thief team.
If you ever decide to destroy the entire contraption, you will need to destroy the invisible armor stand. Use the command:
/kill @e[tag=TheftBlock]