So I am making an adventure map when I ran into a problem that might be impossible to solve with the limitations of bedrock edition. So what I wanted to know is, can I randomly teleport players to certain positions without the chance of more than 1 player teleporting in the same position?
-
1Do you mean you want to teleport all players at the same time, to randomly selected coordinates, to random coordinates, or just select player(s) at random intervals?– BenCommented Dec 10, 2020 at 7:15
-
1I want to teleport players at specific positions but random. Kinda like hunger games, it randomly teleports players in certain coordinates.– user262579Commented Dec 10, 2020 at 16:25
2 Answers
If you know approximately where everyone is going to be before they are teleported (i.e. a lobby), put some armor stands down, name them something like spawn_0
and a bunch of different ones and then tp them with:
execute @e[type=armor_stand,name="spawn_0"] ~ ~ ~ tp @r[x=5,y=10,z=5,r=30] @s
Have that happen as many as you want, like spawn_1
, spawn_2
, etc. Obviously adjust r
for your needs. Adjust x=
, y=
, z=
to where your lobby/place before people are teleported.
If you don't know where anyone is going to be, you may want to look into the /tag
command. This answer should suffice for most situations, though.
-
1
-
1@ExpertCoder14 "If you don't know where anyone is going to be..." I don't know how else to be more clear?– PenguinCommented Dec 10, 2020 at 19:50
-
This solution requires no additional entities. The idea here is to number players randomly, and then teleport them based on their ID. This is useful because you can then target players based on their IDs.
To set this up, you first need a scoreboard objective to hold the players' ID numbers, and a fake player to hold the current ID number:
scoreboard objectives add id dummy
scoreboard players set #current id -1
Now for the solution itself. We start off by setting everybody's ID to -1.
scoreboard players set @a id -1
Next, we repeatedly run the following commands to increment the ID and assign it to a random player who has not yet received an ID:
scoreboard players add #current id 1
scoreboard players operation @r[scores={id=-1}] id = #current id
After that is done, we can target the desired players with @a[scores={id=…}]
:
tp @a[scores={id=0}] 12 23 34
tp @a[scores={id=1}] 23 34 45
As with most computer-science based indices, the first index is id=0
, not id=1
.