Jump to content

Reacting to messages in chatbox


scriptersteve

Recommended Posts

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

Link to comment
Share on other sites

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

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. 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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();
        }
    }
}

 

Link to comment
Share on other sites

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.

 

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