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.

Get item ID's and prices by name

Featured Replies

I made a snippet which will cache all item prices and ID's out of an array in a list at the start of the script.

If the price or ID isn't cached it will automatically add it.

 

Usage:

 

Add this to onStart:


cacheItems(items);
// Put in your own array as parameter

To get an item price:


getPrice(itemID);
getPrice(item Name);
// Will both return the price as an int;

To get an item ID: 


getID(item name);
// This doesn't work if the item isn't cached.

Code:

 


package API;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import static java.lang.Integer.parseInt;

/**
 * Created by The Undefeated.
 */
public class FetchItems {

    String itemName;
    public int price;
    public int ID;
    public static List<FetchItems> itemList = new ArrayList<>();
    public FetchItems(String itemName, int ID, int price) {
        this.itemName = itemName;
        this.ID = ID;
        this.price = price;
    }
  
    public static void cacheItems(String[] array) {
        for (String i : array) {
            getInfo(i);
        }
    }

    public static int getPrice(String name) {
        for (int i = 0; i < itemList.size(); i++) {
            if (itemList.get(i).itemName.equals(name)) {
                return itemList.get(i).price;
            }
        }
        getInfo(name);
        return itemList.get((itemList.size() - 1)).price;
    }

    public static int getID(String name) {
        for (int i = 0; i < itemList.size(); i++) {
            if (itemList.get(i).itemName.equals(name)) {
                return itemList.get(i).ID;
            }
        }
        getInfo(name);
        return itemList.get((itemList.size() - 1)).ID;
    }

    private static void getInfo(String item) {
        String fieldID = "GEDBID";
        String priceID = "GEPrice";
        int price2 = 0;
        int ID2 = 0;
        try {
            final URL url = new URL("http://2007.runescape.wikia.com/wiki/Exchange:" + item.replaceAll(" ", "_"));
            BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;

            while ((line = file.readLine()) != null) {
                if (line.contains("id=\"" + fieldID + "\"")) {
                    int beginIndex = line.indexOf(fieldID) + (fieldID.length() + 2);
                    ID2 = parseInt(line.substring(beginIndex, line.indexOf("<", beginIndex)));
                }
                if((line.contains("id=\"" + priceID + "\""))) {
                    int beginIndex = line.indexOf(priceID) + (priceID.length() + 2);
                    price2 = parseInt((line.substring(beginIndex, line.indexOf("<", beginIndex))).replace(",",""));
                }
            }
            if (price2 != 0 && ID2 != 0) {
                itemList.add(new FetchItems(item, ID2, price2));
            }
            file.close();
        } catch (IOException e) {

        }
    }

}

If you see any improvements I could make, don't hesitate to comment.

 

Edited by The Undefeated

Check out mine, it uses the Jagex website. I like your caching idea, but as a pricing api i dont think the caching is necessary, that should be on a script by script basis

 

 

Looks good. Since you asked for improvements, you could change the data structures. I think the best solution would be a two HashMaps, one mapping Names to item IDs and one mapping item IDs to price. The performance increase would be negligible in practice but it's better in terms of time complexity for this use case.

Even if there are many values, it (almost) always takes the same amount of time to execute put(), contains() and get(). The put() method is roughly equivalent to add().

With an ArrayList, it always takes the same time for add(), but the time it takes to execute contains() is proportional to the number of items in the list. This means if the number of items is very large, then it can take very long time to search through the list.

  • Author
1 hour ago, Polymorphism said:

Check out mine, it uses the Jagex website. I like your caching idea, but as a pricing api i dont think the caching is necessary, that should be on a script by script basis

 

 

The prices of the RS Grand Exchange API are not always right. Take for example the price of a bow string (ID:1777) so wouldn't recommend that.

 

1 hour ago, Diclonius said:

Looks good. Since you asked for improvements, you could change the data structures. I think the best solution would be a two HashMaps, one mapping Names to item IDs and one mapping item IDs to price. The performance increase would be negligible in practice but it's better in terms of time complexity for this use case.

Even if there are many values, it (almost) always takes the same amount of time to execute put(), contains() and get(). The put() method is roughly equivalent to add().

With an ArrayList, it always takes the same time for add(), but the time it takes to execute contains() is proportional to the number of items in the list. This means if the number of items is very large, then it can take very long time to search through the list.

I'll change that anytime soon.

 

3 hours ago, The Undefeated said:

The prices of the RS Grand Exchange API are not always right. Take for example the price of a bow string (ID:1777) so wouldn't recommend that.

 

 

 

I've never seen one that wasn't right...

6SjjXqV.png  AbKAZKK.png

  • Author
12 minutes ago, Polymorphism said:

 

I've never seen one that wasn't right...

6SjjXqV.png  AbKAZKK.png

OSBuddy price is way lower but their website is down 50% of the time.

I checked this afternoon, and people in chat can confirm, the API price of bow strings were 281 each.

 

Edited by The Undefeated

15 hours ago, Diclonius said:

Looks good. Since you asked for improvements, you could change the data structures. I think the best solution would be a two HashMaps, one mapping Names to item IDs and one mapping item IDs to price. The performance increase would be negligible in practice but it's better in terms of time complexity for this use case.

Even if there are many values, it (almost) always takes the same amount of time to execute put(), contains() and get(). The put() method is roughly equivalent to add().

With an ArrayList, it always takes the same time for add(), but the time it takes to execute contains() is proportional to the number of items in the list. This means if the number of items is very large, then it can take very long time to search through the list.

Yes definitely use map for this.

15 hours ago, The Undefeated said:

the API price of bow strings were 281 each.

 

 

OSBuddy price doesn't reflect in game prices i believe. Which is why i never use it

  • Author
8 minutes ago, Polymorphism said:

 

OSBuddy price doesn't reflect in game prices i believe. Which is why i never use it

But as I said, the official GE API fails many times. I used it in one my scripts and it's horrible to use because of the wrong prices sometimes. That's why I think using the wiki is the way to go.

 

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.