Thanfor Posted March 17, 2018 Posted March 17, 2018 Hi, I noticed when i am trying to search for multi word sentences from chatbox e.g. "has happened", it doesn't compute. Thanks to some of the comments in this forums, I understand that rsns use non breaking linebreak, what about inside the chatbox?
d0zza Posted March 17, 2018 Posted March 17, 2018 What are you using to search the chatbox? You can use OnMessage to do something whenever the message you want has appeared in the chatbox.
Thanfor Posted March 17, 2018 Author Posted March 17, 2018 10 minutes ago, d0zza said: What are you using to search the chatbox? You can use OnMessage to do something whenever the message you want has appeared in the chatbox. Thanks for your reply. Would that method overwrite work for searching substrings with spaces? I am using getChatbox().contains()
dreameo Posted March 17, 2018 Posted March 17, 2018 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.")
d0zza Posted March 17, 2018 Posted March 17, 2018 23 minutes ago, Thanfor said: Thanks for your reply. Would that method overwrite work for searching substrings with spaces? I am using getChatbox().contains() Spaces don't need any work for the chatbox, only for player names. Like dreameo said, use the message listener that is part of the osbot api.
DeadPk3r Posted March 17, 2018 Posted March 17, 2018 (edited) 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 March 17, 2018 by DeadPk3r
inababila Posted March 17, 2018 Posted March 17, 2018 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.