Random TP

Discussion in 'Plugin Development' started by killerzz1, Jun 6, 2015.

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

    killerzz1

    Hello,

    I am working on a plugin right now and i need to add a random Tp part to the plugin but i do not know how to do this.

    I need it to randomly tp the player (Not on water or in the sky/blocks)

    How would i do this?

    Thanks
     
  2. Offline

    killerzz1

    I have a random TP but it is not really working properly as it is TPint the players but it is sending the players around the same distance
     
  3. @killerzz1 Can we see the code you have so far?
     
  4. Offline

    killerzz1

    Code:
    public static void tp(Player p){
           
           
             Location originalLocation = p.getLocation();
          
             Random random = new Random();
           
             Location teleportLocation = null;
           
             int x = random.nextInt(50) + -50;
             int y1 = 150;
             int z = random.nextInt(50)+ -50;
            
             teleportLocation = new Location(p.getWorld(), x, y1, z);
     
             boolean isOnLand = false;
           
            
             while (isOnLand == false) {
                
                 teleportLocation = new Location(p.getWorld(), x, y1, z);
               
                 if (teleportLocation.getBlock().getType() != Material.AIR ) {
                    
                         isOnLand = true;
                 } else y1--;
       
         }
                
        p.teleport(new Location(p.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 1, teleportLocation.getZ()));
       
        p.sendMessage(ChatColor.GREEN + "You have been teleported " + (int)teleportLocation.distance(originalLocation) + " blocks away!");
      
        return;
    }
    
     
  5. @killerzz1 Your code doesn't allow for a wide range of X or Z co-ordinates.
     
  6. Offline

    killerzz1

    Okay, so could you help me as i am kinda new to bukkit :D
     
  7. Offline

    Zombie_Striker

    @killerzz1
    Your random will only teleport the player from -50 to 49. Please set the random to the size you want plus one, which will then teleport the player from -50 to 50.
     
Thread Status:
Not open for further replies.

Share This Page