Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

onMessage help

Featured Replies

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?

I wouldn't put that code in onMessage if I were you. Use it to set a boolean and hop based on that.

  • Author

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
}

 

You can always set it to hop when it reaches 10 or below(assume you're doing a high stocked item) if you don't get the onmessage working

or just have it hop after every instance of buying the item(s)

Edited by hreyvirtue

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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.