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.

InventoryMonitor snippet

Featured Replies


/**

* Created by Bjorn on 20/06/2015.

*/

public abstract class InventoryMonitor extends Thread {

private final BotreScript script;

/**

* Previous and current copies of the inventory instance.

*/

private final Map<String, Integer> previous, current;

public InventoryMonitor(final BotreScript script) {

this.script = script;

previous = new TreeMap<>();

current = new TreeMap<>();

}

@Override

public void run() {

// Run thread while script is running.

while (script.isRunning()) {

Inventory inventory;

if (script.isOnline() && (inventory = script.getInventory()) != null) {

// Clear previous cache.

previous.clear();

// Copy mappings of the current cache to the previous cache.

previous.putAll(current);

// Clear current cache.

current.clear();

// Rebuild current cache.

for (Item item : inventory.getItems()) {

if (item != null ) {

String name = item.getName();

if (name != null && !current.containsKey(name)) current.put(name, (int) inventory.getAmount(name));

}

}

}

try {

// Call onLoop and sleep for its return value.

Thread.sleep(onLoop());

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

public abstract int onLoop();

public int getDifference(String name) {

if (current.containsKey(name)) return current.get(name) - (previous.containsKey(name) ? previous.get(name) : 0);

else if (previous.containsKey(name)) return 0 - previous.get(name);

else return 0;

}

}

You could include an example on how to use this method to simplify for some scripters.

 

Other than that, good job! :)

  • Author

@Woody, here's a little example (written without an IDE, "fletchedBows" is a global variable holding the total amount of fletched bows).

in onStart():

new InventoryMonitor(this) {

@override
public int onLoop() {

fletchedBows += getDifference("Oak longbow");

return 100;
}	
	
}.start();
  • 4 weeks later...

for those that need a replacement

   @Override
	public void run() {
        // Run thread while script is running.
    	if (script != null) {
			while (script.getBot().getScriptExecutor().isRunning()) {
	            Inventory inventory;
	            if ((inventory = script.getInventory()) != null) {
	                // Clear previous cache.
					previous.clear();

Edited by josedpay

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.