How to I give a player a item every time they spawn? 1.13+
So far I have this...
/scoreboard objectives add CrimDeath deathCount
/scoreboard objectives add CrimRespawn dummy
/give CrimsonCreates carrot_on_a_stick{display:{Name:"[{\"text\":\"Dash Attack\"}]"},Enchantments:[{id:"binding_curse",lvl:1},{id:"vanishing_curse",lvl:1}]} 1
/execute as @e[name=CrimsonCreates,scores={CrimRespawn=1..}] run replaceitem entity CrimsonCreates weapon.offhand carrot_on_a_stick{display:{Name:"[{\"text\":\"Dash Attack\"}]"},Enchantments:[{id:"binding_curse",lvl:1},{id:"vanishing_curse",lvl:1}]} 1
/execute as @e[name=CrimsonCreates,scores={CrimDeath=1..}] run scoreboard players add CrimsonCreates CrimRespawn
/scoreboard players reset @a[scores={CrimDeath=2..}] CrimDeath
/scoreboard players reset @a[scores={CrimRespawn=1..}] CrimRespawnI tried it and it doesn't work, I'm pretty sure it has to do with the scoreboard reset commands. If possible, can somebody explain what I am doing wrong or tell me a better way to do it?
21 Answer
Here it is all the commands you'll need:
One time activation:
/scoreboard objectives add death deathCount /scoreboard objectives add dummydeath dummyHere 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 1So, 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
dummydeathscore. - 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
dummydeathscore. - If they don't have the Carrot on a stick, give it to them.
- Remove 1 score from
dummydeathfrom 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.