Jump to content

Reacting to messages in chatbox


Recommended Posts

Posted

Hi, I want to basically stop my script if chatbox says: You don't have the runes to cast this spell.

 

Having some problems: trying to use chatbox.getMessages(), but keep getting errors in intellij, also just tried the normal message one but think something went wrong there:

 

Would someone be able to show me the correct snippet for detecting this?

 

Thanks

Posted (edited)

In your onStart() method:

this.getBot().addMessageListener(this);

Then you can use the messageListener:

public void onMessage(Message message) {
	String text = message.getMessage().toLowerCase();
	if (text.contains("you don't have the runes")) {
		//They don't have the runes so do something
	}
}

 

Edited by DrizzyBot
Posted
7 hours ago, DrizzyBot said:

In your onStart() method:


this.getBot().addMessageListener(this);

Then you can use the messageListener:


public void onMessage(Message message) {
	String text = message.getMessage().toLowerCase();
	if (text.contains("you don't have the runes")) {
		//They don't have the runes so do something
	}
}

 

Make sure to check if the message is from the game so people won't be able to log your accounts of by typing it in chatbox. 

Posted
15 minutes ago, Alek said:

He asked for a Chatbox API answer and literally every answer in here is not what he was asking for. Your IDE will tell you exactly what's wrong, please show a screenshot of the code you have.

That's probably because he doesn't know how to do it based on his other threads. His question is not based on having problems with Chatbox API but having problems with reading messages in general. 

Posted
4 hours ago, The Undefeated said:

That's probably because he doesn't know how to do it based on his other threads. His question is not based on having problems with Chatbox API but having problems with reading messages in general. 

Yeah, i don't know how to do it :').

This is my current setup had deleted previous attempts but pretty sure they were worse :'). Current problems are the m is unable to be resolved and the = Message.MessageType(GAME) is incorrect

 public void onMessage(Message m){
    if (m.getType() == Message.MessageType(GAME)) {

        String text = m.getMessage().toLowerCase();
        if (text.contains("rune")) {
            stop();
        }
        if(text.contains("arrow")){
            stop();
        }
    }
}
5 minutes ago, scriptersteve said:

Yeah, i don't know how to do it :').

This is my current setup had deleted previous attempts but pretty sure they were worse :'). Current problems are the m is unable to be resolved and the = Message.MessageType(GAME) is incorrect. Now it's just the Message.MessageType(GAME) that's wrong, fixed the other issue as i had a bracket messed up elsewhere


 public void onMessage(Message m){
    if (m.getType() == Message.MessageType(GAME)) {

        String text = m.getMessage().toLowerCase();
        if (text.contains("rune")) {
            stop();
        }
        if(text.contains("arrow")){
            stop();
        }
    }
}

 

Posted

It's possible you're getting a null string. 

Also, text.contains() may fail you later in the future for more general words.

text.equals("zz") is better for more exact phrases. You might run into messages that contain other elements other then just the phrase. I believe there is something in the API that could help you out. If you can't find it, there are easy work arounds that you should figure out.

 

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...