Jump to content

Getting most common world in clan chat


Recommended Posts

Posted (edited)

 

Based on this thread: https://osbot.org/forum/topic/44402-chatworld-find-the-world-most-of-the-people-in-clan-chat-are-in/

 

I have tried to implement something similar

    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 {
        List < Integer > chatWorlds = new ArrayList <Integer> ();
        int hopWorld = -1;
        RS2Widget chatbox = widgets.get(589, 5);
        RS2Widget[] people = chatbox.getChildWidgets();
        for (RS2Widget world: people) {
            if (world.getMessage().contains("World ")) {
                chatWorlds.add(Integer.parseInt(world.getMessage().replace("World ", "")));
            }
        }
        hopWorld = mode(chatWorlds);
        return hopWorld;
    }

I get an error at the line:

       RS2Widget[] people = chatbox.getChildWidgets();

 

Where am I going wrong? Basically all I want to do is get the most common world in the clan chat that I'm currently in.

 

Thank you

Edited by Beenrange
Posted (edited)
17 minutes ago, Beenrange said:

I get an error at the line:

       RS2Widget[] people = chatbox.getChildWidgets();

Where am I going wrong? Basically all I want to do is get the most common world in the clan chat that I'm currently in.

Thank you

In the future, including the error may be helpful.

Probably the widget 'chatbox' is null in this case, though. In other words a widget with those IDs was not loaded or visible at the time.

Edited by FrostBug
Posted
10 minutes ago, FrostBug said:

In the future, including the error may be helpful.

Probably the widget 'chatbox' is null in this case, though. In other words a widget with those IDs was not loaded or visible at the time.

Sorry - the error is as follows:

 

[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.chatWorld(ArdyKnightsHailzy.java:206)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.hop(ArdyKnightsHailzy.java:218)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.thieve(ArdyKnightsHailzy.java:110)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.onLoop(ArdyKnightsHailzy.java:55)
[INFO][Bot #1][06/28 02:07:27 PM]: org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(kl:223)
[INFO][Bot #1][06/28 02:07:27 PM]: java.lang.Thread.run(Unknown Source)

 

I found it largely unhelpful so thats why I didn't include it. Essentially what I'm trying to do is this:

 

//get the chatbox containing the list of all users in clan and their worlds 
RS2Widget chatbox = widgets.get(589, 5);
//get an array of people in the clan chat including their world
 RS2Widget[] people = chatbox.getChildWidgets();

 

I can't see why it doesn't work, as to my knowledge them ID's are correct. My only thought atm is that I need to move into the clan 'tab' before I call them lines, but I'm unsure of how to do that atm. 

Posted
1 minute ago, Beenrange said:

Sorry - the error is as follows:

 

[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.chatWorld(ArdyKnightsHailzy.java:206)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.hop(ArdyKnightsHailzy.java:218)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.thieve(ArdyKnightsHailzy.java:110)
[INFO][Bot #1][06/28 02:07:27 PM]: scripts.ArdyKnightsHailzy.onLoop(ArdyKnightsHailzy.java:55)
[INFO][Bot #1][06/28 02:07:27 PM]: org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(kl:223)
[INFO][Bot #1][06/28 02:07:27 PM]: java.lang.Thread.run(Unknown Source)

 

I found it largely unhelpful so thats why I didn't include it. Essentially what I'm trying to do is this:

 


//get the chatbox containing the list of all users in clan and their worlds 
RS2Widget chatbox = widgets.get(589, 5);
//get an array of people in the clan chat including their world
 RS2Widget[] people = chatbox.getChildWidgets();

 

I can't see why it doesn't work, as to my knowledge them ID's are correct. My only thought atm is that I need to move into the clan 'tab' before I call them lines, but I'm unsure of how to do that atm. 

That is not the full error, but we'll work with it :xboge:
you can use the Tabs api to switch tabs

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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