3

Trigger a function only once when a player joins

RADI0R's Avatar RADI0R6/5/22 6:39 pm
3 emeralds 1.5k 1
6/5/2022 7:53 pm
garlicbreathinator's Avatar garlicbreathinator
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?
Posted by RADI0R's Avatar
RADI0R
Level 42 : Master Loremaster
58

Create an account or sign in to comment.

1

garlicbreathinator
06/05/2022 7:53 pm
Level 31 : Artisan Engineer
garlicbreathinator's Avatar
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
7
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome