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.

How to do an accurate loot tracker?

Featured Replies

I was thinking of having like..3 lists of items.

1. final list that you print.

2. current inv

3. new inv

 

check current inv against new inv, if they're different add whatever is new to the loot list, curr inv = new inv

 

But then I ran into things like

what if they use food?

what about stackable items?

etc

 

There's gotta be some easy way to do this that I'm not thinking of. hah

You better make that range support...even if none helps u or ill be sad :(

Here's what I did:

 

First create a class called PricedLoot. Has 3 important variables: String name, int price, int amount. In the constructor grab the price from zybez.

package def.api;

import org.osbot.script.rs2.Client;

public class PricedItem {
	private String name;
	private int lastCount = 0;
	private int amount = 0;
	private int price = 0;
	private int id = 0;
	
	public PricedItem(String name, Client c){
		this.name = name;
		if(c.getInventory().contains(name))
			lastCount = (int) c.getInventory().getAmount(name);
		price = PriceGrab.getInstance().getPrice(name, 2);	
	}
	
	public void update(Client c){
		int increase =  (int) (c.getInventory().getAmount(name)- lastCount);
		if(increase < 0)
			increase = 0;
		amount = amount + increase; 
		lastCount = (int) c.getInventory().getAmount(name);
	}
	
	public String getName(){
		return name;
	}
	public int getAmount(){
		return amount;
	}
	
	public int getPrice(){
		return price;
	}
	public int getValue(){
		return amount * price;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}

You'll also need this custom Zybez price grabbing class I found on here: 

package def.api;

import java.io.*;
import java.net.*;

public class PriceGrab {


    private static PriceGrab oneInstance;
    private URL zybez;
    private URLConnection urlConnection;
    private BufferedReader inputScan;
    private final String zybezUrl = "http://forums.zybez.net/runescape-2007-prices/api/item/";

    public static PriceGrab getInstance(){
        if(oneInstance == null){
            oneInstance = new PriceGrab();
        }
        return oneInstance;
    }

    public int getPrice(String itemName, int command){
        final String AVERAGE = "average",LOW= "recent_high", HIGH="recent_low";
        String item = format(itemName),extracted;
        int price = 0;
        openStream(item);
        extracted = retrieveData(item);
        switch (command){
            case 1:
                return parseInfo(extracted,LOW);

            case 2:
                return parseInfo(extracted,AVERAGE);

            case 3:
               return parseInfo(extracted,HIGH);
        }
        return price;
    }

    private String format(final String string){
        if(string.contains(" "))
            return string.replaceAll(" ", "+");
        else
            return string;
    }

    private void openStream(final String param){
        String appended = zybezUrl.concat(param);

                try {
                    zybez = new URL(appended);
                    urlConnection = zybez.openConnection();
                    urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                }
                catch (MalformedURLException e) {
                    System.out.println("Web address formatted incorrectly, printing stack trace");
                    e.printStackTrace();
                }
                catch(IOException exception) {
                    System.out.println("Url connection has thrown an IOException, printing stack trace");
                    exception.printStackTrace();
                }
    }

    private String retrieveData(final String param){
        String output = null;
        try {
            openStream(param);
            inputScan = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
             output =  inputScan.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {inputScan.close();} catch (IOException e){e.printStackTrace();}
        }
        return output;
    }

    private int parseInfo(String extracted,String value){
        int start, end, price = 0;
        if(extracted.contains(value)){
            start = extracted.indexOf(value);
            end = extracted.indexOf(",",start);
            price = Integer.parseInt(extracted.substring(start, end).replaceFirst(".*?(\\d+).*", "$1"));
        }
        else
            System.out.println("Could not retrieve price");
        return price;
    }
}

Then, create an array of PricedItems for everything you want to loot and update the PricedItems somewhere in your onLoop.

		for(PricedItem i : lootList){
			i.update(client);
		}
  • Author

You better make that range support...even if none helps u or ill be sad sad.png

..this is completely unrelated to the thread m8.

But I did, I pushed that update last night.

 

Here's what I did:

 

First create a class called PricedLoot. Has 3 important variables: String name, int price, int amount. In the constructor grab the price from zybez.

package def.api;

import org.osbot.script.rs2.Client;

public class PricedItem {
	private String name;
	private int lastCount = 0;
	private int amount = 0;
	private int price = 0;
	private int id = 0;
	
	public PricedItem(String name, Client c){
		this.name = name;
		if(c.getInventory().contains(name))
			lastCount = (int) c.getInventory().getAmount(name);
		price = PriceGrab.getInstance().getPrice(name, 2);	
	}
	
	public void update(Client c){
		int increase =  (int) (c.getInventory().getAmount(name)- lastCount);
		if(increase < 0)
			increase = 0;
		amount = amount + increase; 
		lastCount = (int) c.getInventory().getAmount(name);
	}
	
	public String getName(){
		return name;
	}
	public int getAmount(){
		return amount;
	}
	
	public int getPrice(){
		return price;
	}
	public int getValue(){
		return amount * price;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}

You'll also need this custom Zybez price grabbing class I found on here: 

package def.api;

import java.io.*;
import java.net.*;

public class PriceGrab {


    private static PriceGrab oneInstance;
    private URL zybez;
    private URLConnection urlConnection;
    private BufferedReader inputScan;
    private final String zybezUrl = "http://forums.zybez.net/runescape-2007-prices/api/item/";

    public static PriceGrab getInstance(){
        if(oneInstance == null){
            oneInstance = new PriceGrab();
        }
        return oneInstance;
    }

    public int getPrice(String itemName, int command){
        final String AVERAGE = "average",LOW= "recent_high", HIGH="recent_low";
        String item = format(itemName),extracted;
        int price = 0;
        openStream(item);
        extracted = retrieveData(item);
        switch (command){
            case 1:
                return parseInfo(extracted,LOW);

            case 2:
                return parseInfo(extracted,AVERAGE);

            case 3:
               return parseInfo(extracted,HIGH);
        }
        return price;
    }

    private String format(final String string){
        if(string.contains(" "))
            return string.replaceAll(" ", "+");
        else
            return string;
    }

    private void openStream(final String param){
        String appended = zybezUrl.concat(param);

                try {
                    zybez = new URL(appended);
                    urlConnection = zybez.openConnection();
                    urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                }
                catch (MalformedURLException e) {
                    System.out.println("Web address formatted incorrectly, printing stack trace");
                    e.printStackTrace();
                }
                catch(IOException exception) {
                    System.out.println("Url connection has thrown an IOException, printing stack trace");
                    exception.printStackTrace();
                }
    }

    private String retrieveData(final String param){
        String output = null;
        try {
            openStream(param);
            inputScan = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
             output =  inputScan.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {inputScan.close();} catch (IOException e){e.printStackTrace();}
        }
        return output;
    }

    private int parseInfo(String extracted,String value){
        int start, end, price = 0;
        if(extracted.contains(value)){
            start = extracted.indexOf(value);
            end = extracted.indexOf(",",start);
            price = Integer.parseInt(extracted.substring(start, end).replaceFirst(".*?(\\d+).*", "$1"));
        }
        else
            System.out.println("Could not retrieve price");
        return price;
    }
}

Then, create an array of PricedItems for everything you want to loot and update the PricedItems somewhere in your onLoop.

		for(PricedItem i : lootList){
			i.update(client);
		}

What do you do with PricedLoot? I think you meant PriceItem? That makes more sense. haha

Could you give an example on creating a PriceItem array? :x

Edited by Nezz

 

What do you do with PricedLoot? I think you meant PriceItem? That makes more sense. haha

Yep.

 

Could you give an example on creating a PriceItem array? :x

Did you get it working?

I'm confused as to why this would be needed?

EDIT: to clarify my post (you have to perform an action to receive loot or an item in runescape , so why not just track the items you receive from the action instead of comparing stored the inventories?)

Edited by LifezHatred

  • Author

Yep.

 
 

Did you get it working?

I think so, I have to test it still though.

 

I'm confused as to why this would be needed?

EDIT: to clarify my post (you have to perform an action to receive loot or an item in runescape , so why not just track the items you receive from the action instead of comparing stored the inventories?)

Because the action itself doesn't always work. There's no 100% accurate way to say "I picked this up." other than comparing inventories.

Like I used to have a log saying "Picking up: " + item_name or whatever

every time it went to pick up the item, it would print the log 3 or 4 times before it actually picked it up.

Why not just compare the before/after for individual items in the inventory? Say you have 10 noted diamonds and pick up 5 - you know that if 10 changes, you've successfully picked up the item. You could do this with counting how many items are in your inventory also

Guest
This topic is now closed to further replies.

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.