How to I give a player a item every time they spawn? 1.13+
Here it is all the commands you'll need:
One time activation:
/scoreboard objectives add death deathCount
/scoreboard objectives add dummydeath dummy
Here it is the chain, connected to a Repeat
command block:
/scoreboard players set @a[scores={death=1}] dummydeath 3
/scoreboard players set @a[scores={death=1}] death 0
/execute as @a[scores={dummydeath=1..},nbt=!{Inventory:[{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"[{\"text\":\"Dash Attack\"}]"},Enchantments:[{id:"binding_curse",lvl:1},{id:"vanishing_curse",lvl:1}]}}]}] run scoreboard players remove @s dummydeath 1
/execute as @a[scores={dummydeath=1..},nbt=!{Inventory:[{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"[{\"text\":\"Dash Attack\"}]"},Enchantments:[{id:"binding_curse",lvl:1},{id:"vanishing_curse",lvl:1}]}}]}] run give @s carrot_on_a_stick{display:{Name:"[{\"text\":\"Dash Attack\"}]"},Enchantments:[{id:"binding_curse",lvl:1},{id:"vanishing_curse",lvl:1}]} 1
/scoreboard players remove @a[scores={dummydeath=1}] dummydeath 1
So, the game works in an interesting way: When you die, you drop your items and, after clicking in the respawn button, the game will clear your inventory;
You can give items to dead players;
We can abuse this the following way:
- When a player dies, give them a score of 3 to
dummydeath
. - If they don't have the Carrot on a stick, remove 1 from their
dummydeath
score. - If they don't have the Carrot on a stick, give it to them.
(At this point, the player will be in the death screen with a carrot on a stick in their hands and with a dummy score of 2; Once they click respawn, they will have their inventory cleared)
- If they don't have the Carrot on a stick, again, remove 1 from their
dummydeath
score. - If they don't have the Carrot on a stick, give it to them.
- Remove 1 score from
dummydeath
from every player that has 1 score ofdummydeath
Interestingly enough, this can work for anything related to respawing players, if there wasn't already a solution to it.