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

Need help with InventoryListener

Featured Replies

I seem to be having some trouble with caching the inventory amounts.

Halp :x

import java.util.Map;
import java.util.TreeMap;

import org.osbot.rs07.api.model.Item;

import dependencies.script.BotreScript;

/**
 * @author 		Bjorn Krols (Botre)
 * @version		0.0
 * @since		April 20, 2015
 */

public class InventoryListener extends Thread {

	private final BotreScript script;
	
	private Map<String, Integer> oldCache, newCache;
	
	public InventoryListener(final BotreScript script) {
		this.script = script;
		oldCache = new TreeMap<String, Integer>();
		newCache = new TreeMap<String, Integer>();
	}
	
	@Override
	public void run() {
		while (script.isRunning()) {
			if (script.isOnline()) {
				oldCache = newCache;
				newCache.clear();
				for (Item item : script.getInventory().getItems()) if (item != null && !newCache.containsKey(item.getName())) newCache.put(item.getName(), (int) script.getInventory().getAmount(item.getName()));
				onUpdate();
			}
			try {
				Thread.sleep(3000); // SLOW FOR READABILITY
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void onUpdate() { }
	
	public int getDifference(String name) {
		if (oldCache.containsKey(name) && newCache.containsKey(name)) {
			script.log("old " + oldCache.get(name));
			script.log("new" + newCache.get(name));
			return newCache.get(name) - oldCache.get(name);
		}
		else return 0;
	}

} 

How it currently logs:

[INFO][Bot #1][04/21 02:55:09 AM]: old 7
[INFO][Bot #1][04/21 02:55:09 AM]: new7
[INFO][Bot #1][04/21 02:55:12 AM]: old 9
[INFO][Bot #1][04/21 02:55:12 AM]: new9
[INFO][Bot #1][04/21 02:55:15 AM]: old 10
[INFO][Bot #1][04/21 02:55:15 AM]: new10
[INFO][Bot #1][04/21 02:55:18 AM]: old 12
[INFO][Bot #1][04/21 02:55:18 AM]: new12

How it's supposed to log:

[INFO][Bot #1][04/21 02:55:09 AM]: old 5
[INFO][Bot #1][04/21 02:55:09 AM]: new7
[INFO][Bot #1][04/21 02:55:12 AM]: old 7
[INFO][Bot #1][04/21 02:55:12 AM]: new9
[INFO][Bot #1][04/21 02:55:15 AM]: old 9
[INFO][Bot #1][04/21 02:55:15 AM]: new10
[INFO][Bot #1][04/21 02:55:18 AM]: old 10
[INFO][Bot #1][04/21 02:55:18 AM]: new12



Solved:

	if (script.isOnline()) {
				oldCache.clear();
				oldCache.putAll(newCache);
				newCache.clear();
				for (Item item : script.getInventory().getItems()) if (item != null && !newCache.containsKey(item.getName())) newCache.put(item.getName(), (int) script.getInventory().getAmount(item.getName()));
				onUpdate();
			}

Edited by Botre

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.