Jump to content

chatWorld() - Find the world most of the people in clan chat are in.


Fay

Recommended Posts

Could probably be done better but I don't think there is a built-in function to find it nor did I see any PC bots utilizing it. (Yes this was originally made for automatic world hopping in PC.)

 

 

The Code for mode() was found here: http://deveshsharma.info/2013/07/16/find-most-common-element-in-a-list-in-java/

^ because I didn't want to make it.

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.ui.RS2InterfaceChild;
import org.osbot.script.rs2.ui.Tab;

private static int mode(List < Integer > list) {

    Map < Integer, Integer > map = new HashMap < Integer, Integer > ();

    for (int i = 0; i < list.size(); i++) {

        Integer frequency = map.get(list.get(i));
        if (frequency == null) {
            map.put(list.get(i), 1);
        } else {
            map.put(list.get(i), frequency + 1);
        }
    }

    int mostCommonKey = -1;
    int maxValue = -1;
    for (Map.Entry < Integer, Integer > entry: map.entrySet()) {

        if (entry.getValue() > maxValue) {
            mostCommonKey = entry.getKey();
            maxValue = entry.getValue();
        }
    }

    return mostCommonKey;
}

public int chatWorld() throws InterruptedException {
    openTab(Tab.CLANCHAT);
    List < Integer > chatWorlds = new ArrayList < Integer > ();
    int hopWorld = -1;
    RS2InterfaceChild chatbox = client.getInterface(589).getChild(5);
    RS2InterfaceChild[] people = chatbox.getChildren();
    for (RS2InterfaceChild world: people) {
        if (world.getMessage().contains("World ")) {
            chatWorlds.add(Integer.parseInt(world.getMessage().replace("World ", "")));
        }
    }
    hopWorld = mode(chatWorlds);
    return hopWorld;
}

Edited by Fay
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...