Alakazizam Posted January 28, 2023 Share Posted January 28, 2023 (edited) I've been trying to teach myself how to write my own scripts and I've been having trouble with hopToF2PWorld and hopToP2PWorld. It would randomly hang up on trying to select Speed Running worlds and occasionally there would just be a world that didn't want to let me connect for whatever reason and it would stop my scripts. I decided to try to make my own function. It takes note of whether you are in a F2P or P2P world and hops accordingly. I wanted to share incase anyone else is having this issue and more importantly incase someone who know a bit more can tell me why this would be bad to do lol. void HopRandomWorld() { int P2PWorlds[] = {303, 304, 305, 306, 307, 309, 310, 311, 312, 313, 314, 315, 317, 318, 319, 320, 321, 322, 323, 324, 325, 327, 328, 329, 330, 331, 332, 333, 334, 336, 337, 338, 339, 340, 341, 342, 343, 344, 346, 347, 348, 350, 351, 352, 354, 355, 356, 357, 358, 359, 360, 362, 367, 368, 370, 374, 375, 376, 377, 378, 386, 387, 388, 389, 390, 395, 421, 422, 424, 443, 444, 445, 446, 463, 464, 465, 466, 477, 478, 480, 481, 482, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 531, 532, 534, 535}; int F2PWorlds[] = {308, 316, 335, 371, 382, 383, 384, 394, 397, 398, 399, 417, 418, 430, 431, 433, 434, 435, 436, 437, 451, 452, 453, 454, 455, 456, 470, 471, 475, 476, 483, 497, 498, 499, 500, 501, 537, 542, 543, 544, 545, 546, 547, 552, 553, 554, 556, 557, 562, 563, 571, 575}; if (getWorlds().isMembersWorld()) { int TargetIndex = random(0, P2PWorlds.length); if (P2PWorlds[TargetIndex] != getWorlds().getCurrentWorld()) { getWorlds().hop(P2PWorlds[TargetIndex]); } else { HopRandomWorld(); } } else { int TargetIndex = random(0, F2PWorlds.length); if (F2PWorlds[TargetIndex] != getWorlds().getCurrentWorld()) { getWorlds().hop(F2PWorlds[TargetIndex]); } else { HopRandomWorld(); } } } Edited January 28, 2023 by Alakazizam Quote Link to comment Share on other sites More sharing options...
TheJacob Posted January 28, 2023 Share Posted January 28, 2023 (edited) I didn't test your method, but immediately I see there's a chance to throw an array out of bounds exception (not providing array.length - 1 on indexing). Here's a more condensed implementation that might help: static final int[] fWorlds = { 1, 8, 16, ... }; static final int[] mWorlds = { 2, 3, 4, ... }; public static void hopRand() { final int[] hWorlds = getWorlds().isMembersWorld() ? mWorlds : fWorlds; if (!getWorlds().hop(300 + hWorlds[random(0, hWorlds.length - 1)])) { hopRand(); } } Edited January 28, 2023 by TheJacob Added example 1 Quote Link to comment Share on other sites More sharing options...
Czar Posted January 28, 2023 Share Posted January 28, 2023 (edited) Good work, should be helpful to many people Also nice to see more scripters ^^ A quick heads up though, it's useful to try Filter<Worlds> to filter out worlds, it's possible to exclude speedrunning worlds this way too: Filter<World> worldFilter = a -> !a.isFull() && a.isMembers() && !a.isHighRisk() && !a.isPvpWorld() && a.getActivity() != null && !getHoppedWorlds().contains(a.getId()) && !a.getActivity().contains("kill t") && !a.getActivity().contains("eedrun") && !a.getActivity().contains("arget") && a.getId() != getContext().getWorlds().getCurrentWorld(); and then match them with getWorlds().getAvailableWorlds(true).stream().filter(worldFilter::match) to find the result E.g. this is what I use in my prayer bot to hop to safe world when doing chaos altar bones. It avoids skill total worlds, target worlds pvp worlds etc. you could easily modify this to suit your needs Edited January 28, 2023 by Czar 1 Quote Link to comment Share on other sites More sharing options...
Alakazizam Posted January 28, 2023 Author Share Posted January 28, 2023 57 minutes ago, TheJacob said: I didn't know this until reading your post, but getWorlds().getAvailableWorlds(...) doesn't dump an OSRS world list, rather a subset of maybe 30 worlds (appears to be an ordered list from W301?). I didn't test your method, but immediately I see there's a chance to throw an array out of bounds exception (not providing array.length - 1 on indexing). Here's a more condensed implementation that might help: static final int[] fWorlds = { 1, 8, 16, ... }; static final int[] mWorlds = { 2, 3, 4, ... }; public static void hopRand() { final int[] hWorlds = getWorlds().isMembersWorld() ? mWorlds : fWorlds; if (!getWorlds().hop(300 + hWorlds[random(0, hWorlds.length - 1)])) { hopRand(); } } Good catch! thank you. Quote Link to comment Share on other sites More sharing options...