TransWikia.com

How to detect a player’s x coordinate and teleport them to the other side of the map in 1.15.2?

Arqade Asked on January 11, 2021

I have a Minecraft Earth map and I want it so if you go too far on one side, it will teleport you to the other side: so players can get from Japan to America by going through the Pacific Ocean. I tried the following command, but it didn’t work. What should I do?

/execute as @e[x=5375,y=~,z=~,distance=..2] at @s run tp @s ~-10750 ~ ~

2 Answers

Tilde notation with ~ is not available in target selectors, and even if it was supported, it wouldn't work, because the tilde is relative to the command block, not to the players selected.

What I would do is use a rectangular volume to make this work.

... as @e[x=5375,y=64,z=10,dx=0,dy=999,dz=999]

This makes a giant selection box starting at coordinates (5375, 64,10) and extending one block east, 1000 blocks up, and 1000 blocks south (an implicit 1 is added to all 3 delta values).

To determine x, y, and z, go to the lower northwest corner of your selection box. dx, dy, and dz should be the number of blocks east, up, and south to extend the border wall.

Correct answer by ExpertCoder14 on January 11, 2021

For my method, we will use scoreboards. First you must make a scoreboard with a dummy critera we'll name it xpos. Then you have to put it in a repeating command block or in a ticking function (a function running every tick) the following command.

execute as @a at @s store result score @s xpos run data get entity @s Pos[0]

That will at every tick store the x value of every player in the world to their scoreboard value. This is multiplayer friendly. Next, we test if they have a specific value or a range in the scoreboard with the following command.

execute as @a[scores={xpos=<range/value>}] at @s run tp <cordinates>

Keep in mind, for this to work, both commands I gave you must be in a repeating command block or in a ticking function. In your case replace <range/value> with 5375.. and <cordinates> to -5375 ~ ~. If you have any questions please ask I'll be happy to help.

Answered by randomuser922 on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP