Thread: Random teleport help....

Results 1 to 5 of 5
  1. #1 Random teleport help.... 
    Registered Member
    Join Date
    Dec 2014
    Posts
    65
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    Hello, I want to make it so when you type a command you teleport to a random location between x coords 3000 and 3251 and I've tried it like this just for test:

    int testX = (int )(Math.random() * 3251 + 3000);
    int testY = (int )(Math.random() * 50 + 1);
    if(playerCommand.startsWith("teletest")) {
    c.sendMessage("Coords: " + TestX);
    c.sendMessage("Coords: " + TestY);
    }
    And TestY works fine, that gives me numbers between 1 and 50 but with TestX it gives me random numbers always above 3251 and I have no clue why that wont work or does it only work with number up to 50? Any help would be appreciated.
    Sorry for my english.
    (I posted the same topic in rs2 client help and I saw after that it was the wrong section, can a mod please delete that topic for me?)
    Reply With Quote  
     

  2. #2  
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    Quote Originally Posted by dutchgala View Post
    Hello, I want to make it so when you type a command you teleport to a random location between x coords 3000 and 3251 and I've tried it like this just for test:

    int testX = (int )(Math.random() * 3251 + 3000);
    int testY = (int )(Math.random() * 50 + 1);
    if(playerCommand.startsWith("teletest")) {
    c.sendMessage("Coords: " + TestX);
    c.sendMessage("Coords: " + TestY);
    }
    And TestY works fine, that gives me numbers between 1 and 50 but with TestX it gives me random numbers always above 3251 and I have no clue why that wont work or does it only work with number up to 50? Any help would be appreciated.
    Sorry for my english.
    (I posted the same topic in rs2 client help and I saw after that it was the wrong section, can a mod please delete that topic for me?)

    Try this?

    Code:
    				int TestX = Utils.random (3000, 3251); 
    				int TestY = Utils.random (1, 50);
    If rs2 don't have utils.random already use this

    Code:
    	public static final int getRandom(int maxValue) {
    		return (int) (Math.random() * (maxValue + 1));
    	}
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2014
    Posts
    65
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by BoomScape View Post
    Try this?

    Code:
    				int TestX = Utils.random (3000, 3251); 
    				int TestY = Utils.random (1, 50);
    If rs2 don't have utils.random already use this

    Code:
    	public static final int getRandom(int maxValue) {
    		return (int) (Math.random() * (maxValue + 1));
    	}
    Yes didnt have Utils.random in it and for the second code, I assume maxValue would be the variable that I have to add to the code? If so, that gave me error where it said that it cant find the variable or that it doesnt exists for some reason.
    Reply With Quote  
     

  4. #4  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by dutchgala View Post
    Yes didnt have Utils.random in it and for the second code, I assume maxValue would be the variable that I have to add to the code? If so, that gave me error where it said that it cant find the variable or that it doesnt exists for some reason.
    He obviously gave you the wrong method. Use this method for minimum and maximum values:
    Code:
    	public static final int random(int min, int max) {
    		final int n = Math.abs(max - min);
    		return Math.min(min, max) + (n == 0 ? 0 : random(n));
    	}
    PS: You will need to add his method as well as that's being used too.
    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Dec 2014
    Posts
    65
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Kris View Post
    He obviously gave you the wrong method. Use this method for minimum and maximum values:
    Code:
    	public static final int random(int min, int max) {
    		final int n = Math.abs(max - min);
    		return Math.min(min, max) + (n == 0 ? 0 : random(n));
    	}
    PS: You will need to add his method as well as that's being used too.
    Thanks m8, already fixed it tho
    I did it like this
    int min = 3000;

    int max = 3251;

    int test = rand.nextInt(max-min+1)+min;
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Random teleport help....
    By dutchgala in forum Help
    Replies: 1
    Last Post: 02-19-2017, 07:07 PM
  2. Making a random teleport. Please help!
    By Formality in forum Help
    Replies: 13
    Last Post: 12-27-2013, 07:41 PM
  3. Teleport help
    By Skillz Ftw in forum Help
    Replies: 3
    Last Post: 11-26-2012, 05:21 AM
  4. Pi help how do i make random teleport
    By Obito Uchiha in forum Help
    Replies: 20
    Last Post: 04-24-2012, 03:18 AM
  5. Random Teleport Areas
    By Shobaky in forum Tutorials
    Replies: 6
    Last Post: 12-26-2007, 05:03 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •