# Send all players X Block from each other.

Discussion in 'Plugin Development' started by Moon_werewolf, Apr 23, 2013.

Not open for further replies.
1. Offline

### Moon_werewolf

I need to know how many block I need to send each player for them to be X amount of block from each other. So far I have (all start from 0, 0)

Code:
```double degree = 360.0 / (double)players.size();
Then I know how many degrees the are between each player. But how far do i need to send them?

#1
2. Offline

### Tzeentchful

Do you want to calculate it in 2D space or 3D space?
If you only care about 2D then use Pythagoras
If you want to get the distance in 3D then apply Pythagoras twice.
Oh and make sure to use the delta between the two players not their actual coordinates.

#2
3. Offline

### Moon_werewolf

Thanks, and I only care about 2D. So pythagoras it is.
Its not only two players. It can be any number of players

#3
4. Offline

### Jake0oo0

You could get a list of players, then teleport one, get his location, add however many blocks to it, then teleport 1-4 more players since you have 4 directions. Then you can keep doing this for the rest of the players.

#4
CarPet likes this.
5. Offline

### CarPet

Jake0oo0
Round about way and would still get the job done. Great Job!

#5
6. Offline

### LucasEmanuel

If you want all players to be equally far from each other it's close to impossible when you have 5 or more players and only three dimensions.

#6
7. Offline

### Technius

No, it'll probably only be impossible with 1 player or no players. It'll just involve thinking. Math, everyone!

Something like this:

Code:
```double xOffs = center.getX() + (distance*Math.cos(Math.toRadians(angle))); //Distance may have to be reduced
double zOffs = center.getZ() + (distance*Math.sin(Math.toRadians(angle))); //Distance may have to be reduced
```
center is the Location that represents the center of the circle.

Then apply it to a vector. Velocity is applied every tick, so you'll have to be careful there.

#7
8. Offline

### LucasEmanuel

Technius
I know of no geometrical object with more then 4 edges where every edge is equally far from each other.
2 players is a line
3 players is a triangle
4 players is a tetrahedron
5 ?

Spreading them out in a circle where all players are equally far from the center is easy and possibly the best way to do it.

You could just do this:
Code:
```int radius = 100; // Players will be 100 blocks from center

double radians = (2 * Math.PI) / Bukkit.getOnlinePlayers().length;

int i = 0;
for(Player player : Bukkit.getOnlinePlayers()) {
i++;

double y = world.getHighestBlockYAt(x, z);

player.teleport(x, y, z);
}
```

#8
9. Offline

### Technius

Since the y-value doesn't really matter, you can just use 2D shapes.
5- Pentagon
6- Hexagon
7-Heptagon
8- Octagon
etc.

#9
10. Offline

### LucasEmanuel

Technius
What i meant when i said all edges are equally far from each other is that all edges are equally far from each other. In a pentagon, edge 2 and 4 for example are not equally close to each other as 3 and 4. #10
11. Offline

### Technius

I guess that's true.

Moon_werewolf
Like LucasEmanuel said, it's probably only possible by sending players out from the center.
Code:
```Location center; //Your location
double distance; //Distance you want to send the players
Player[] players; //The players you have
for(int i = 0; i < players.length; i ++) //Loop through the players
{
Player p = players[i];
double x = center.getX() + (distance*Math.cos(angle*i)); //x
double z = center.getZ() + (distance*Math.sin(angle*i)); //z
double y = p.getWorld().getHighestBlockAt(x, z);
//This teleports players, but you could try something else
p.teleport(new Location(p.getWorld(), x, y, z));
}
```

#11