Jump to content

Help with onMessage


Bloodycub

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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?

Link to comment
Share on other sites

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

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

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