Discussion in 'Plugin Development' started by elementalgodz11, Dec 10, 2013.

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


  2. Offline


    Make a random number generator method that returns an int.
    Then do something like (*world stuff*,1696.7 + randMethodHere(), 0 + randMethodHere(), 1176 + randMethodHere())

    A simple google search will show you how to do random, I shouldn't need to explain it.
    Random method should generate say 1-30 then just do -15 so it is a radius of like 15 up or down in each direction.
  3. Offline


    elementalgodz11 use the random as a percentage.
    double x = origin.getX() + ((random.nextDouble()*2)-1)*radius);
    double z = origin.getZ() + ((random.nextDouble()*2)-1)*radius);
    double y = (double)world.getHighestBlockYAt((int)x, (int)z);
    player.teleport(new Location(world, x, y, z));
    • random.nextDouble()*2 gets a number between 0 and 2
    • -1 will make the number range between -1 and 1
    • multiplying by the radius gives the range you like
  4. Offline


    You want something like -15 to 15 for a 15 radius right ?
    which means of course the diameter of your circle is 30

    double x = ((random.nextDouble()*DIAMETER)-RADIUS);

    Multiply the nextDouble() by 30 to get a double in the [0,30] range and substract 15 to get a negative value for [0,15] results.

    And as I've understood, the y value isn't random is it ?
    Please tell us what errors do you get doing this ;)

    What you're looking for is getHighestBlockYAt(Location loc)

    I believe the Location you've got to provide is your current (world, x + random x, y , z + random z)

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


    That happens when you just copy-paste :3
    L33m4n123 likes this.
  6. double xUpperLimit=somevalue;
    double xLowerLimit=somevalue;
    double xDifference=xUpperLimit=xLowerLimit;
    double xResult=(double)(random.nextInt((int)xDifference)+xLowerLimit) //do this with the y and z axis
Thread Status:
Not open for further replies.

Share This Page