Jump to content

Getting most common world in clan chat


Beenrange

Recommended Posts

 

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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