Jump to content

Help with onMessage


Recommended Posts

Posted

This is code http://pastebin.com/mRq0sijB

Problem is that it spamms if it sees Hi AND HAVE NO IDEA how to fix it!?

 

maybe try giving it a timer and check if it's the last thing said in the chatbox messages instead of just contained by the chatbox messages? it's just going to loop repeatedly if you leave it as it is because the condition is continuously met - it's going to continue saying 'hellow' until there's no 'hi' in the chatbox

Posted

maybe try giving it a timer and check if it's the last thing said in the chatbox messages instead of just contained by the chatbox messages? it's just going to loop repeatedly if you leave it as it is because the condition is continuously met - it's going to continue saying 'hellow' until there's no 'hi' in the chatbox

 

if i understand coreccly onMessage should have that timer implemented?

Posted (edited)

Just check what the latest message was, you don't need the chatbox api.

 

m.getMessage() i think it would be, or something similar.

 

What you are doing is checking the entire chatbox every time someone sends a message, which of course it contains the same thing that was said before.

 

Also, String#contains is case sensetive, so this would only work if it was a capital H, you should change it to

 

m.getMessage().toLowerCase().contains("hi")

Edited by Tom
Posted

The onMessage method gets triggered when a new message gets added to the chatbox.

There is no point in looping over the chatbox and all that...

 

Example for logs chopped:

public void onMessage(Message message) {
   if (message.getMessage().contains("You get some"))
      logCount++;
}

Enjoy! smile.png

 

tryin steal my thunder br0?

Posted

Just check what the latest message was, you don't need the chatbox api.

 

m.getMessage() i think it would be, or something similar.

 

What you are doing is checking the entire chatbox every time someone sends a message, which of course it contains the same thing that was said before.

 

Also, String#contains is case sensetive, so this would only work if it was a capital H, you should change it to

 

m.getMessage().toLowerCase().contains("hi")

 

But runescape Automaticly canges hi to Hi :/

The onMessage method gets triggered when a new message gets added to the chatbox.

There is no point in looping over the chatbox and all that...

 

Example for logs chopped:

public void onMessage(Message message) {
   if (message.getMessage().contains("You get some"))
      logCount++;
}

Enjoy! smile.png

 

Will test later when have time but thanks for in front

  • Like 1
Posted

But runescape Automaticly canges hi to Hi :/

 

Will test later when have time but thanks for in front

 

Not if its mid sentence, you are checking 'contains' after all.

If you wanted to check the start of the sentence, use startsWith i believe.

 

The solution i provided will work none the less, it converts the message received to lower case afterwards so runescape wont fuck around with it

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