XZybez 2 Share Posted May 8, 2020 Hi Community, i was playing around with API and was wondering how to get the World Population before i hop to a new world? I run into issue that my script fails in case i hop to a full world. Thank you in forward and stay safe. Link to comment Share on other sites More sharing options...
RetroBot 35 Share Posted May 8, 2020 The db api doesn't have a method to get the world population unfortunately. You will need to get the world population from the rs site. Here's a world info class I found forever ago and tweaked it a little bit to work for db. package utils; import java.io.DataInputStream; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class World { private final int id; private final boolean member; private final boolean pvp; private final boolean highRisk; private final boolean deadman; private final String host; private final String activity; private final int serverLoc; private final int playerCount; private final int flag; public World(int id, int flag, boolean member, boolean pvp, boolean highRisk, String host, String activity, int serverLoc, int playerCount) { this.id = id; this.flag = flag; this.member = member; this.pvp = pvp; this.highRisk = highRisk; this.host = host; this.activity = activity; this.serverLoc = serverLoc; this.playerCount = playerCount; deadman = activity.toLowerCase().contains("deadman"); } public int getId() { return id; } public int getFlag() { return flag; } public boolean isMember() { return member; } public boolean isPvp() { return pvp; } public boolean isHighRisk() { return highRisk; } public boolean isDeadman() { return deadman; } public String getHost() { return host; } public String getActivity() { return activity; } public int getServerLoc() { return serverLoc; } public int getPlayerCount() { return playerCount; } public static List<World> load() throws IOException { List<World> worldList = new ArrayList<>(); URLConnection conn = new URL("http://oldschool.runescape.com/slr").openConnection(); try (DataInputStream dis = new DataInputStream(conn.getInputStream())) { int size = dis.readInt() & 0xFF; int worldCount = dis.readShort(); for (int i = 0; i < worldCount; i++) { int world = dis.readShort() & 0xFFFF; int flag = dis.readInt(); boolean member = (flag & 0x1) != 0; boolean pvp = (flag & 0x4) != 0; boolean highRisk = (flag & 0x400) != 0; String host = null, activity = null; StringBuilder sb = new StringBuilder(); byte b; while (true) { b = dis.readByte(); if (b == 0) { if (host == null) { host = sb.toString(); sb = new StringBuilder(); } else { activity = sb.toString(); break; } } else { sb.append((char) b); } } int serverLoc = dis.readByte() & 0xFF; int playerCount = dis.readShort(); worldList.add(new World(world, flag, member, pvp, highRisk, host, activity, serverLoc, playerCount)); } } worldList.sort(Comparator.comparingInt(World::getId)); return Collections.unmodifiableList(worldList); } } Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted May 9, 2020 Alternatively you can probably grab and parse the data from the world hopper widgets in game. Link to comment Share on other sites More sharing options...
AsBakedAsCake 203 Share Posted May 9, 2020 14 hours ago, XZybez said: Hi Community, i was playing around with API and was wondering how to get the World Population before i hop to a new world? I run into issue that my script fails in case i hop to a full world. Thank you in forward and stay safe. Tbh, I just filtered out worlds that tend to be full. World 2, etc, etc. There's really not that many worlds that actually get full. Probably 3-4 MAX. Link to comment Share on other sites More sharing options...
XZybez 2 Author Share Posted May 9, 2020 Thank you for the reply's. Will see how i can get this data. Kinda just started to get into the osrs and dream bot API so will take a while to learn all possibility here. Link to comment Share on other sites More sharing options...
DontGetBanned 3 Share Posted May 27, 2020 might not be the "best" way but it is a way to worldhop none the less.... private boolean hopWorlds = false; private final int[] Worlds = new int[]{ 301, 302, 303 ,etc.}; //insert ALL WORLDS YOU LIKE, they do change from time to time. Onloop or something: if ( Condition ) { int hopTo = Worlds[Calculations.random(0,Worlds.length-1)]; while(hopTo == getClient().getCurrentWorld()) hopTo = Worlds[Calculations.random(0,Worlds.length-1)]; getWorldHopper().hopWorld(hopTo); } else { try { Thread.sleep(Calculations.random(8000,15000)); } catch (InterruptedException e) { e.printStackTrace(); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.