Use tags to target only players who are holding the gun.
Repeat block:
/scoreboard players tag @a remove HoldingGun
Chain blocks, in order:
/scoreboard players tag @a add HoldingGun {SelectedItem:{display:{Name:"Medigun"}}}
/execute @a[tag=HoldingGun] ~ ~ ~ /effect @e[r=4] minecraft:regeneration 10 2
Of course, I'm just assuming the Medigun item has a display name of Medigun; if it has other special tags, you should change those in the first command accordingly. (And I highly recommend including the item id inside the SelectedItem tag as well, so that people can't just rename other items to Medigun and get the effect.)
You can create a loot table that contains all the different items you want the item dropper to drop.
Go to minecraft.tools/en/loots.php to create a loot table with all of the items you want in it. Because loot tables are random (you don’t get the same exact drops and amounts of those drops when you kill mobs), loot tables can be used to generate random drops, but can be controlled enough to decide probabilities and amounts if you so desire.
If you don’t know how to create loot tables, there are plenty of examples on the internet that explain how.
Once you create your loot table, copy it to your clipboard and go to your world saves folder (the world saves folder’s name is default to “world” on servers) and then navigate to the folder called data
. Create a folder called loot_tables
inside of it if it doesn’t already exist. Inside of that folder, create a folder called custom_drops
. Inside of the custom_drops folder, create a folder called entities
. Then in that folder create a text file called item_dropper.json
with your loot table pasted inside of it.
In your minecraft world, use this command to summon the armor stand:
/summon armor_stand -1181 32 -131 {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoGravity:1b,CustomName:"item_dropper",CustomNameVisible:0b,DeathLootTable:”custom_drops:entities/item_dropper”}
Then kill the armor stand with the command /kill @e[type=armor_stand,name=item_dropper]
right after you summon it (with chain command blocks you could do this on the same tick).
This will summon an armor stand with the loot table created, and then kill it to make it drop the items in the loot table.
Keep in mind that the mob loot gamerule must be on for this to work. Use /gamerule doMobLoot true
to toggle mob loot to true.
Best Answer
/clone
can't take relative coordinates of two entities. You'll have to clone it first to a fixed location (maybe 0 0 0, just make sure it's definitely loaded) and then to the target location. Then you can delete it at 0 0 0 or just leave it there if that doesn't interfere with anything.