Hi, I have a minecraft modded server and I need to detect when someone gets a dragon egg. I need his name to write in the chat. It would be even better if it regularly wrote his coordinates in the chat until he lost the egg. Would anyone please advise me. Well thank you.
tellraw @a [{"text":"\n\nThe egg is with ","bold":true},{"selector":"@p[tag=hasegg]","color":"light_purple"},{"text":" at ","color":"white"},{"score":{"name":"x","objective":"Coords"},"color":"light_purple"},{"text":", ","color":"white"},{"score":{"name":"y","objective":"Coords"},"color":"light_purple"},{"text":", ","color":"white"},{"score":{"name":"z","objective":"Coords"},"color":"light_purple"},{"text":".\n\n","color":"white"}]
//Edited command, look underneath, look at bottom
You can change whatever you want.
A warning: Because the chain command blocks are conditional, if you put the sad sound first the nice sound won't play unless there are other people around. The other way around (nice then sad) isn't a problem, because the commands won't be activates unless someone get the egg.
EDIT
Found a simpeler command, credit to Megacrafter107
execute as @p[tag=hasegg] run tellraw @a [{"text":"\n\nThe egg is with ","bold":true},{"selector":"@p[tag=hasegg]","color":"light_purple"},{"text":" at ","color":"white"},{"entity":"@s","nbt":"Pos[0]","color:"light_purple"},{"text":", ","color":"white"},{"entity":"@s","nbt":"Pos[1]","color:"light_purple"}{"text":", ","color":"white"},{"entity":"@s","nbt":"Pos[2]","color:"light_purple"},{"text":".\n\n","color":"white"}]
Hi, I have a minecraft modded server and I need to detect when someone gets a dragon egg. I need his name to write in the chat. It would be even better if it regularly wrote his coordinates in the chat until he lost the egg. Would anyone please advise me. Well thank you.
To start with:
/scoreboard objectives add Coords dummy
//Not necessary, look at bottom
if you want to test it:
/scoreboard objectives setdisplay sidebar Coords
//Not necessary, look at bottom
Repeating command blocks:
//execute store result score x Coords run data get entity @p[tag=hasegg] Pos[0]
//execute store result score y Coords run data get entity @p[tag=hasegg] Pos[1]
//execute store result score z Coords run data get entity @p[tag=hasegg] Pos[2]
// store coordinates of person w/ eggs Not neccecary, look at bottom.
execute as @a unless entity @s[nbt={Inventory:[{id:"minecraft:dragon_egg"}]}] run tag @s remove hasegg
// remove tag if you lose the egg
Repeating command block with line of conditional chain command blocks:
execute as @a[nbt={Inventory:[{id:"minecraft:dragon_egg"}]}] unless entity @s[tag=hasegg] run tag @s add hasegg
// give tag if you have the egg, repeating command block
tellraw @a [{"selector":"@a[tag=hasegg]","color":"light_purple"},{"text":" has the egg!"}]
// tell everyone who has the egg
playsound minecraft:block.respawn_anchor.charge master @a[tag=hasegg] ~ ~ ~
// play nice sound to the new owner
playsound minecraft:block.respawn_anchor.deplete master @a[tag=!hasegg] ~ ~ ~
// play sad sound to everyone else
Every 5 minutes or so (what you want):
tellraw @a [{"text":"\n\nThe egg is with ","bold":true},{"selector":"@p[tag=hasegg]","color":"light_purple"},{"text":" at ","color":"white"},{"score":{"name":"x","objective":"Coords"},"color":"light_purple"},{"text":", ","color":"white"},{"score":{"name":"y","objective":"Coords"},"color":"light_purple"},{"text":", ","color":"white"},{"score":{"name":"z","objective":"Coords"},"color":"light_purple"},{"text":".\n\n","color":"white"}]
//Edited command, look underneath, look at bottom
You can change whatever you want.
A warning: Because the chain command blocks are conditional, if you put the sad sound first the nice sound won't play unless there are other people around. The other way around (nice then sad) isn't a problem, because the commands won't be activates unless someone get the egg.
EDIT
Found a simpeler command, credit to Megacrafter107
execute as @p[tag=hasegg] run tellraw @a [{"text":"\n\nThe egg is with ","bold":true},{"selector":"@p[tag=hasegg]","color":"light_purple"},{"text":" at ","color":"white"},{"entity":"@s","nbt":"Pos[0]","color:"light_purple"},{"text":", ","color":"white"},{"entity":"@s","nbt":"Pos[1]","color:"light_purple"}{"text":", ","color":"white"},{"entity":"@s","nbt":"Pos[2]","color:"light_purple"},{"text":".\n\n","color":"white"}]
Help with /tellraw:
https://minecraftjson.com/
~Blue