How to make a player drop an item when hit
I am making a game on Minecraft when someone starts holding one item. If they get hit by someone they lose the item, and it goes on until a timer finishes. How can I do this? I am still new to command blocks, so any help will be appreciated.
Best Answer
You could have them via command blocks equip a piece of armour with half a hitpoint on it, so when they get hit the armour breaks, this could trigger the "clear" command to remove the item, and then spawn @players feet the item in question
Pictures about "How to make a player drop an item when hit"



What is the command to drop items in Minecraft?
This is a simple command where you just type /drop and you drop all your items. You can also use /Drop @(entity) to target an entity or /Drop @(entity) Minecraft: (item) to make an entity drop a certain item.How do you make a player not drop an item in Minecraft?
Using /gamerule keepInventory false we can prevent players from dropping items on their death, however, players are still able to drop items in general.How to Make Tools Drop on Death in Roblox Studio
More answers regarding how to make a player drop an item when hit
Answer 2
You can delete the item there holding if they get it, and you can make them drop the item if you know what item there holding. To do this you need a scoreboard objective testing for when they get hit,
/scoreboard objectives add damage stat.damageTaken
Then in command block do,
/testfor @a[score_damage_min=1]
Then a comparator coming out of that into a command block do,
/replaceitem entity @a slot.weapon.mainhand air
Then with a repeater coming out of that into a command block,
/scoreboard players reset @a damage
Though if you know what item there holding add before the scoreboard reset do,
/execute @a[score_damage_min=1] ~ ~ ~ /summon Item ~ ~ ~ {PickupDelay:60s,Item:{id:"minecraft:grass"},Motion:[0.2,0.5,0.2]}
And replace "grass" in minecraft:grass with the item you want dropped.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: RF._.studio, Alexander Suhorucov, Pixabay, Kelly
