Jump to content

onMessage help


Recommended Posts

Posted

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?

Posted

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
}

 

  • Like 1
Posted
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) { }

 

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