Swizzbeat Posted December 31, 2013 Share Posted December 31, 2013 (edited) public static int[] WORLDS = {301, 302, 303, 304, 305, 306, 308, 309, 310, 311, 312, 313, 314, 316, 317, 318, 319, 320, 321, 322, 326, 327, 328, 329, 330, 333, 334, 335, 336, 338, 341, 342, 343, 344, 345, 346, 349, 350, 351, 352, 353, 354, 357, 358, 359, 360, 361, 362, 365, 366, 367, 368, 369, 370, 373, 374, 375, 376, 377, 378}; And to hop to a random one: new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length)]); Had to make this last night and might save someone a couple minutes This list CONTAINS F2P worlds: 308, 316 This list DOES NOT CONTAIN PvP worlds: 325, 337 Edited January 1, 2014 by Swizzbeat 1 Link to comment Share on other sites More sharing options...
Soldtodie Posted December 31, 2013 Share Posted December 31, 2013 (edited) What is when random(WORLDS.length) = 0 is ? You subtract 1 then its -1. A array with -1 is impossible. Don't subtract 1 then it will work. Edited December 31, 2013 by Soldtodie Link to comment Share on other sites More sharing options...
Swizzbeat Posted December 31, 2013 Author Share Posted December 31, 2013 What is when random(WORLDS.length) = 0 is ? You subtract 1 then its -1. A array with -1 is impossible. Don't subtract 1 then it will work. The first index of an array is zero, however the length method returns the total number of items in the array not taking this into account. Link to comment Share on other sites More sharing options...
Pandemic Posted December 31, 2013 Share Posted December 31, 2013 The first index of an array is zero, however the length method returns the total number of items in the array not taking this into account. He's actually right though, the random function's max is exclusive, so it already goes from 0 - max-1 Link to comment Share on other sites More sharing options...
Soldtodie Posted December 31, 2013 Share Posted December 31, 2013 You can test it. int test = -999; while((test = random(WORLDS.length)-1) != -1) { } log("It's " + test + " !"); Link to comment Share on other sites More sharing options...
Swizzbeat Posted December 31, 2013 Author Share Posted December 31, 2013 He's actually right though, the random function's max is exclusive, so it already goes from 0 - max-1 Hmm I always thought the random method started at 1 my apologies then, I'll fix now. Thanks to both 1 Link to comment Share on other sites More sharing options...
Mr def nerd Posted December 31, 2013 Share Posted December 31, 2013 You have to subtract by one, the length of an array with one object is 1, while the object index is 0. If the random method returns the length of this array it will give you a nullpointer as the object that has the index of the length doesnt exist (in short words: the lenght of an array is its total objects +1) Link to comment Share on other sites More sharing options...
Swizzbeat Posted December 31, 2013 Author Share Posted December 31, 2013 You have to subtract by one, the length of an array with one object is 1, while the object index is 0. If the random method returns the length of this array it will give you a nullpointer as the object that has the index of the length doesnt exist (in short words: the lenght of an array is its total objects +1)Hmm so my original code was right I just need to add a min/max value in....I'll fix when I get on a computer! Link to comment Share on other sites More sharing options...
liverare Posted December 31, 2013 Share Posted December 31, 2013 Your code is too broad and it doesn't take into consideration potential latency issues someone may experience, e.g., I don't play on American servers because there would be too much latency at times. If I were to bot, this would undoubtedly effect the bot's performance. Link to comment Share on other sites More sharing options...
Swizzbeat Posted January 1, 2014 Author Share Posted January 1, 2014 Your code is too broad and it doesn't take into consideration potential latency issues someone may experience, e.g., I don't play on American servers because there would be too much latency at times. If I were to bot, this would undoubtedly effect the bot's performance. This is just an array for all the possible worlds people can hop to without the PvP ones. I don't think anyone really cares if their on an American/Germany server :p Link to comment Share on other sites More sharing options...
Celeos Posted January 1, 2014 Share Posted January 1, 2014 new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length - 1)]); No need to put the 0 in there. ^_^ Link to comment Share on other sites More sharing options...
Swizzbeat Posted January 1, 2014 Author Share Posted January 1, 2014 new WorldHopper(MethodProvider).hopWorld(WORLDS[random(WORLDS.length - 1)]);No need to put the 0 in there. ^_^Fixed it right after I changed it :p it's 2 in the morning my brains a little loopy! 1 Link to comment Share on other sites More sharing options...
Omoshu Posted January 1, 2014 Share Posted January 1, 2014 An instance of WorldHopper is already accessible from MethodProvider. MethodProvider#worldHopper Link to comment Share on other sites More sharing options...
FrostBug Posted January 1, 2014 Share Posted January 1, 2014 Thanks for this Alot of people might want to remove the f2p worlds, though Link to comment Share on other sites More sharing options...
Soldtodie Posted January 1, 2014 Share Posted January 1, 2014 Sorry but this is not right: random(WORLDS.length() - 1) An example: random(28); This can gives you the number 0 or the number 27 and all numbers beetween this two numbers. But not the number 28. This is right: random(WORLDS.length()) Link to comment Share on other sites More sharing options...