Teleport players in a HashSet to random coordinates within a chosen radius

Discussion in 'Plugin Development' started by jimbo8, Feb 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    jimbo8

    Yeah, the title almost explains it all..

    What i'm trying to do, is get every single player saved in a HashSet, then teleport the players to random coordinates within a chosen radius.

    Let's say i have team red, blue and green, and i have this command called "scatter".

    When i write /scatter 200, team red, blue and green will be teleported to a random location within 200 blocks, each team will be teleported atleast 50 blocks away from eachother.

    I've got everything ready except for the teleportation-part, as i'm not really sure how to do this.

    Sorry if i didn't explain this well enough, i hope you understand.

    Thanks :)
     
  2. Offline

    xTrollxDudex

    jimbo8
    PHP:
    Set<Stringset = new HashSet<>();
     
    for(
    String s set) {
        
    Player p;
        if((
    Bukkit.getServer().getPlayerExact(s)) != null) {
            
    Random random = new Random();
            
    p.teleport(new Location(p.getWorld(), random.nextDouble(256), random.nextDouble(256), random.nextDouble(256)));
        }
    }
     
    jimbo8 likes this.
  3. Offline

    Gater12

    Knowing you, it might suffocate the player....
     
  4. Offline

    jimbo8

    Thanks, that's no problem. I'll just teleport the player to the highest block.

    Thanks xTrollxDudex

    nextDouble(256) isn't applicable for the arguments(int). :p

    If i remove the args, it just teleports everyone to 0,0,0.

    xTrollxDudex

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    Gater12

  6. Offline

    jimbo8

    Gater12

    Thanks mate, was pretty obvious, but anyways, thanks!

    Works like a charm. Now, how can i ensure that they are X-amount of blocks away from the other team?

    Also: Do you guys know how i can check if every team is empty without making a whole lot of a messy code?

    By the way, how did you get that awesome signature? I like it.
     
Thread Status:
Not open for further replies.

Share This Page