Run command whenever someone joins a Minecraft server

Run command whenever someone joins a Minecraft server - Woman With White Sunvisor Running

Is there any way to run a command automatically when a player joins the server? I need to do this without the use of a Bukkit plugin. I think it's possible with MCP but I want to know how!



Best Answer

First, create a scoreboard objective of type "stat.leaveGame":

/scoreboard objectives add quits stat.leaveGame

Next, put this commands into a always active repeating command block:

/execute as @a[scores={quits=1..}] at @s run <COMMAND TO RUN>

And in a chain command block in the direction that the first command block points to:

/scoreboard players set @a[scores={quits=1..}] quits 0

The command you put in the place of <COMMAND TO RUN> will now run every time a player rejoins the game.




Pictures about "Run command whenever someone joins a Minecraft server"

Run command whenever someone joins a Minecraft server - Close Up Photo of Programming of Codes
Run command whenever someone joins a Minecraft server - Grayscale Photo of Couple Walking on Road
Run command whenever someone joins a Minecraft server - Women in White Dress Running on Green Grass Field



Quick Answer about "Run command whenever someone joins a Minecraft server"

  • Run this in the chat: /scoreboard objectives add joined dummy.
  • In command blocks on a fill clock: /scoreboard players add @a joined 0 /execute @a[score_joined=0] ~ ~ ~ [command you want to run]


  • How do you execute someone in Minecraft?

    For the command to kill a player or other entity, see Commands/kill. /execute executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.

    How do you make a Minecraft welcome message?

    How to set someone to OP on your Minecraft server
  • Head to the server panel and click on the console tab on the left.
  • In the command line type \u201cop (Username)\u201d and press enter.
  • You should see a message that says \u201cPlayer is now an operator\u201d.
  • You can also do this in-game by typing \u201c/op (Username)\u201d.


  • How do you op someone on a server?

    To use a command in the game, type a \u201c/\u201d then the command and just hit enter. Otherwise you can just type the command into your server's console without the \u201c/\u201d to run it. Here is a full list of commands available in Vanilla Minecraft.



    Welcome Message on Login - Minecraft Command Block Tutorial [1.14+]




    More answers regarding run command whenever someone joins a Minecraft server

    Answer 2

    It's very simple. Using functions it'd look like:

    Repeating command block:

    execute as @a[tag=!Joined] run function1
    

    function1:

    <insert commands>
    tag @s add Joined
    

    Using Command Blocks

    1. Repeating, always active:

      execute as @a[tag=!Joined] run <inert command you want to run>
      
    2. Chain, conditional:

      <commands>
      
    3. Chain, conditional

      execute as @a[tag=!Joined] run tag @s add Joined
      

    Answer 3

    The previous answer is good if you want it to run the command every time they join. (i see an exploit if its a good item)

    If you only want it to run the command the first time they join, try this:

    1. Run this in the chat:

      /scoreboard objectives add joined dummy
      
    2. In command blocks on a fill clock:

      /scoreboard players add @a joined 0
      /execute @a[score_joined=0] ~ ~ ~ [command you want to run]
      
    3. And finally, this command in a command block powered by a comparator signal from the execute command

      /scoreboard players set @a[score_joined=0] joined 1
      

    And this will make sure that the command only runs the first time a player joins the server.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Pixabay, luis gomes, Flora Westbrook, Anna Shvets