I'm making Capture the Flag minigame and I want players to drop only banners from their inventory on death (if they had one).
I've been looking for this for quite a while (1.14.4 related) and couldn't find anything which would work, most threads were older game versions related.
Is it possible to achieve with only command blocks?
I think I kinda figured it out, I'll post it here if someone has the same problem as I had.
First of all you need to create death count scoreboard through text chat.
/scoreboard objectives add Deaths deathCount
Then place 3 command blocks (Repeating, Unconditional, Always Active) and paste that 3 commands:
execute as @a[nbt={Inventory:[{id:"minecraft:blue_banner"}]}] run execute if entity @p[scores={Deaths=1..}] run replaceitem entity @p[scores={Deaths=0..}] hotbar.8 minecraft:blue_banner 1
execute as @a[nbt={Inventory:[{id:"minecraft:blue_banner"}]}] run execute if entity @p[scores={Deaths=1..}] run clear @p[scores={Deaths=1..}] minecraft:blue_banner
execute as @a[scores={Deaths=1..}] run execute as @a[nbt={Inventory:[{Slot:8b,id:"minecraft:blue_banner"}]}] run scoreboard players reset @a Deaths
If you want other item just simply change blue_banner. Also, it only works with gamerule keepInvrentory true. Hope this helps anybody
I'm making Capture the Flag minigame and I want players to drop only banners from their inventory on death (if they had one).
I've been looking for this for quite a while (1.14.4 related) and couldn't find anything which would work, most threads were older game versions related.
Is it possible to achieve with only command blocks?
I think I kinda figured it out, I'll post it here if someone has the same problem as I had.
First of all you need to create death count scoreboard through text chat.
/scoreboard objectives add Deaths deathCount
Then place 3 command blocks (Repeating, Unconditional, Always Active) and paste that 3 commands:
execute as @a[nbt={Inventory:[{id:"minecraft:blue_banner"}]}] run execute if entity @p[scores={Deaths=1..}] run replaceitem entity @p[scores={Deaths=0..}] hotbar.8 minecraft:blue_banner 1
execute as @a[nbt={Inventory:[{id:"minecraft:blue_banner"}]}] run execute if entity @p[scores={Deaths=1..}] run clear @p[scores={Deaths=1..}] minecraft:blue_banner
execute as @a[scores={Deaths=1..}] run execute as @a[nbt={Inventory:[{Slot:8b,id:"minecraft:blue_banner"}]}] run scoreboard players reset @a Deaths
If you want other item just simply change blue_banner. Also, it only works with gamerule keepInvrentory true. Hope this helps anybody