2

So, I'm trying to find a way to make every player have a randomized spawn point. I know I can try by using /spreadplayers and then make everyone set their spawn point to where they landed and, other than maybe non-uniform distribution of /spreadplayers, that would be it.

The thing is, is there a way to make this so any new player that enters gets a randomized spawn point automatically? I was thinking of doing it manually (aka, tp the new player to a random location and then set their spawnpoint by command line) or maybe having some kind of structure in the spawn with command blocks, but I'm curious as to see if there may be other ways.

1 Answer 1

2

Yes. If I recall correctly, there is no native way to detect player world join, so we can test for a player without a tag and at the last line give them the line:

execute as @a[tag=!has_spawn] run spreadplayers ...
execute as @a[tag=!has_spawn] at @s run spawnpoint @s ~ ~ ~
execute as @a[tag=!has_spawn] run tag @s add has_spawn

The order of the commands is important, especially the last one.

You don't need this running in the background all the time to work, but having it all the time will make the process automatic. If you want non uniform distribution, you can run the spreadplayer individually (like it is done in the second line).

You can't really have uniformity since you won't be using spreadplayer on all players at the same time. You could have a much more complex system to test and make sure no one landed nearby (have an armorstand sit on top of the player's initial spawnpoint and test if the new player landed nearby).

6
  • 1
    If I'm not mistaken, /scoreboard can be used to detect player-joins? I might be making that up, and your solution works fine.
    – slink
    Commented Nov 7, 2021 at 18:23
  • 1
    @Pikatchoo32 Close, the scoreboard can be used to detect re-joins, because it updates every time you quit.
    – One 2 Many
    Commented Nov 7, 2021 at 19:34
  • 1
    Exactly what they said. It detects quits, but you can't execute as someone who is offline, so your code will run once they re-join.
    – BunnyMerz
    Commented Nov 7, 2021 at 20:29
  • Huh. Thanks a lot! I'll try to work with that. The armor stand idea is pretty neat. I'm a bit of a noob with command blocks, so, may I ask what do "..." and "~ ~ ~" stand" for?
    – Rararat
    Commented Nov 10, 2021 at 12:38
  • 1
    the ... is just letting you, the OP, decide how the spreadplayer is gonna work. Idk what coordinates you want, or how big the radius is. The ~ means relative position; Notice how there is a at @s in the execute. It will use the target's current coordinate.
    – BunnyMerz
    Commented Nov 10, 2021 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.