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.

Inventory listener

Featured Replies

The class is named InventoryTrackers (with an s), the interface name is InventoryTracker (without the s, found statically in the class.)

package dependencies.trackers;

import java.util.ArrayList;
import java.util.List;

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

@SuppressWarnings("deprecation")
public class InventoryTrackers implements Runnable	{

	public static interface InventoryTracker	{
		public void handleAdded(Item item);	
		public void handleRemoved(Item item);
	}
	
 	private List<Item> current = new ArrayList<Item>();
 	private InventoryTracker event;
 	private boolean isRunning = true;
	private Script s;
	
	public InventoryTrackers(Script script, InventoryTracker e) {
		this.event = e;
		this.s = script;
		updateItems();
	}

	public void run() {
		while (isRunning)	{
			process(event);
			try {
				Thread.sleep(1200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void stop()	{
		this.isRunning = false;
	}
	
	public void updateItems()	{
		current.clear();
		
		if (s.inventory.getItems() != null)	{
			for (Item item: s.inventory.getItems())	{
				if (item != null) {
					current.add(item);
				}else{
					current.add(new Item(-1, -1));
				}
			}			
		}
	}

	public void process(InventoryTracker e)	{	
		List<Item> ourItems = current;
		List<Item> newItems = getNewList();

		for (int i = 0; i < ourItems.size(); i++)	{
			Item ourItem = ourItems.get(i);
			Item newItem = newItems.get(i);
			
			if (ourItem.getId() != newItem.getId())	{
				e.handleRemoved(ourItem);
				e.handleAdded(newItem);
			}
			else if (ourItem.getAmount() != newItem.getAmount())	{
				if (ourItem.getAmount() < newItem.getAmount())	{
					e.handleAdded(newItem);
				}else{
					e.handleRemoved(ourItem);
				}
			}			
		}
		updateItems();
	}
	
	private List<Item> getNewList()	{
		List<Item> list = new ArrayList<Item>();
		
		if (s.inventory.getItems() != null)	{
			for (Item item: s.inventory.getItems())	{
				if (item != null) {
					list.add(item);
				}else{
					list.add(new Item(-1, -1));
				}
			}			
		}
		return list;
	}
}

 

How do you use it, you must create a new thread and initialize it. You must also end the thread once the script is done. Dont for get to implement InventoryTracker.

 

Example:

public class ScriptName extends Script implements InventoryTracker	{
     private InventoryTrackers invTracker; //create a field
}

Next create a new thread, and initialize the tracker within the onStart

Override
public void onStart() throws InterruptedException {
	this.invTracker = new InventoryTrackers(this, this);
	new Thread(invTracker).start();

}

Now within your script you should have the two method overrided. Keep the condition so it doesn't affect your script once its paused or not logged in.

	@Override
	public void handleAdded(Item item) {
		if (!bot.getScriptExecutor().isPaused() && client.isLoggedIn())	{  }
	}

	@Override
	public void handleRemoved(Item item) {
		if (!bot.getScriptExecutor().isPaused() && client.isLoggedIn())	{  }
	}		
	

Kill the thread once the script is over.

@Override
public void onExit() throws InterruptedException {	invTracker.stop();	}

if you have any question feel free to ask.  if im missing something let me know.

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.