3
Trigger a function only once when a player joins
I'd like to create a fun datapack that automatically executes a function when I join my server.
The function could be anything such as a large title or a /playsound of the new goat horn at every player's location.
Why?
Because I'd like to let my friends know the big boss himself has joined, nothing too special lmao
I know I can just copypaste the command into chat myself when I join but I thought about how this could be automated to make it more funny. Any elegant ideas?
The function could be anything such as a large title or a /playsound of the new goat horn at every player's location.
Why?
Because I'd like to let my friends know the big boss himself has joined, nothing too special lmao
I know I can just copypaste the command into chat myself when I join but I thought about how this could be automated to make it more funny. Any elegant ideas?
Create an account or sign in to comment.
1
The scoreboard criteria minecraft.custom:minecraft.leave_game is what you want.
I THINK these commands are fine, but they are untested so syntax might be bad.
This version will work entirely with command blocks:
Do once:
scoreboard objectives add leave minecraft.custom:minecraft.leave_game
In repeating command block chain:
execute as (username)[scores={leave=1..}] run playsound ...
execute as (username)[scores={leave=1..}] run title ...
scoreboard players reset @a leave
And this version will run as a datapack (a little bit more efficient)
In load function:
scoreboard objectives add leave minecraft.custom:minecraft.leave_game
In tick function:
execute as (username)[scores={leave=1..}] run function mypack:join ...
In mypack:join:
playsound ...
title...
scoreboard players reset @s leave
I THINK these commands are fine, but they are untested so syntax might be bad.
This version will work entirely with command blocks:
Do once:
scoreboard objectives add leave minecraft.custom:minecraft.leave_game
In repeating command block chain:
execute as (username)[scores={leave=1..}] run playsound ...
execute as (username)[scores={leave=1..}] run title ...
scoreboard players reset @a leave
And this version will run as a datapack (a little bit more efficient)
In load function:
scoreboard objectives add leave minecraft.custom:minecraft.leave_game
In tick function:
execute as (username)[scores={leave=1..}] run function mypack:join ...
In mypack:join:
playsound ...
title...
scoreboard players reset @s leave