Jump to content

onMessage help


Stinji

Recommended Posts

Hey guys,

I'm writing a bot that buys items from a shop and banks them when inventory is full. The thing is that the restock rate is pretty fast and the bot will repeatedly buy items until the inventory is full (the line that says hop worlds when getAmount() == 0; doesn't even get activated because of how fast it is). That's why I decided to hop worlds whenever the message "The shop has run out of stock." appears. My code looks like this:

public void onMessage(Message m) throws InterruptedException {
	if (m.getMessage().contains("The shop has run out of stock.")) {
			log("Shop ran out of stock, hopping worlds");
			currentWorld = getWorlds().getCurrentWorld();
			getWorlds().hopToP2PWorld();
			new ConditionalSleep(5000) {

				@Override
				public boolean condition() throws InterruptedException {
					return getWorlds().getCurrentWorld() != currentWorld && getWorlds().isOpen();
				}
			}.sleep();
	}
}

However, it doesn't get overridden long enough for all of the code to be executed. I know this because I tested the following code:

public void onMessage(Message m) throws InterruptedException {
		if (m.getMessage().contains("The shop has run out of stock.")) {
			sleep(10000);
	}
}

The logger gives an error message after about 5 seconds, so I'm thinking the onMessage doesn't store the message until the end of the code. Is there a way to change the length it stores the value or is there another way of achieving the same result?

Thanks guys!

 

PS. Can anyone please let me know if the 'currentWorld' line is necessary. In other words: will the hopToP2PWorld() recognize the current world and consider not hopping to this world on its own?

Link to comment
Share on other sites

7 minutes ago, Stinji said:

Something like this?


@Override
	public void onMessage(Message m) throws InterruptedException {
		if (m.getMessage().contains("The shop has run out of stock.")) {
			outOfStock = true;
		}
	}

...

	if (outOfStock.equals(true)) {
		insert hop here;
		outOfStock = false;				//to reset the boolean
}

 

Yeah something like that.

Please note that 

if (outOfStock.equals(true)) { }

Can be used as 

if (outOfStock) { }

 

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