Jump to content

reading text from chat box


Thanfor

Recommended Posts

15 minutes ago, Thanfor said:

Thanks for your reply.

Would that method overwrite work for searching substrings with spaces?

I am using


getChatbox().contains()

contains method in Chatbox checks for MessegeType instances

You want to use the message listener and then do a contains method that checks for sub strings equaling "has happened". You may encounter issues (depending on the method) with, exact phrases though. ("has happened" vs  "has happened.")

Link to comment
Share on other sites

Here is how you would go about doing this.

If a player (anyone) types "noob" or "nub" your bot will then reply "im not a noob you are!".

    public void onMessage(Message message) throws java.lang.InterruptedException {
	if(message.getType() == Message.MessageType.PLAYER) {
			if (message.getMessage().contains("noob") || message.getMessage().contains("nub")) {
				getKeyboard().typeString("im not a noob you are!");
			}
		}
    }

 

Edited by DeadPk3r
Link to comment
Share on other sites

And if you want to get recent messages from the chatbox after a while, here is what you will want to do.

You add this to your class

implements MessageListener

and this is the code

getChatbox().getMessages(MessageType.PLAYER).get(0).contains("noob")

Gets the last player message sent containing noob. I find it useful because I have a message tracking system inside my script.

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