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.

Getting itemID by name

Featured Replies

I was wondering is there a way to failproof code by not hardcoding item(or any other) ID's? 

 

For example I know that I can get the ID if I have have the item in inventory or somewhere else

		Item item = inventory.getItem(new Filter<Item>() {
			@[member=Override]
			public boolean match(Item item) {
				return item.getName() == "SOME ITEM NAME";
			}
		});
		
		log(item.getId());

But what if I don't have the item in my inventory/region/etc? 

Why do you want to know it? Well in most cases there are multiple items that have the same name. The easiest example to mention is noted and unnoted items.

 

You can use the ItemDefinition class, but I believe you have to load the items first.

  • Author

Why do you want to know it? Well in most cases there are multiple items that have the same name. The easiest example to mention is noted and unnoted items.

 

You can use the ItemDefinition class, but I believe you have to load the items first.

 

Thanks, but any idea how to load them? I need the ID for grand exchange (and probably would find more places where to apply them), as I don't have the items on me when I want to buy them. I'm using the OSBot GE API for the buying part, but it requires item ID's. 

Edited by krapstaunosi

Thanks, but any idea how to load them? I need the ID for grand exchange (and probably would find more places where to apply them), as I don't have the items on me when I want to buy them. I'm using the OSBot GE API for the buying part, but it requires item ID's. 

 

You have several options.

 

  1. If you know what items you want to buy, just hardcode the item ids
  2. Write your own buy method that uses item names instead of ids
  3. Use an existing buy method that uses item names instead of ids, there are already snippets around on the forum, for example: http://osbot.org/forum/topic/90148-simple-ge-api

Edited by Explv

 

You have several options.

 

  1. If you know what items you want to buy, just hardcode the item ids
  2. Write your own buy method that uses item names instead of ids
  3. Use an existing buy method that uses item names instead of ids, there are already snippets around on the forum, for example: http://osbot.org/forum/topic/90148-simple-ge-api

 

 

Additionally you also do an API suggestion here:

 

http://osbot.org/forum/forum/102-client-bugs-suggestions/

 

Could be useful for everybody else if an method is added that supports item names.

  • Author

 

You have several options.

 

  1. If you know what items you want to buy, just hardcode the item ids
  2. Write your own buy method that uses item names instead of ids
  3. Use an existing buy method that uses item names instead of ids, there are already snippets around on the forum, for example: http://osbot.org/forum/topic/90148-simple-ge-api

 

 

Thanks

use colour







:kappa:

Edited by ES Asp

itemdb.biz :) 


thats a site just copy paste it (mainly used for rsps spawns but works for rs aswell obv)

  • Author

itemdb.biz smile.png

thats a site just copy paste it (mainly used for rsps spawns but works for rs aswell obv)

 

Thanks for the heads up. Didn't know about this one. But immediately I see a couple of concerns:

 

1) How do I know if the site will be available for a long time?

2) This is strange

itemdb.png

 

The current raw lobbie D is 377. The site gives me two ID's with the same revision number.

Thanks for the heads up. Didn't know about this one. But immediately I see a couple of concerns:

 

1) How do I know if the site will be available for a long time?

2) This is strange

itemdb.png

 

The current raw lobbie D is 377. The site gives me two ID's with the same revision number.

 

2nd one is noted ID. 1st one is regular ID

Thanks for the heads up. Didn't know about this one. But immediately I see a couple of concerns:

 

1) How do I know if the site will be available for a long time?

2) This is strange

itemdb.png

 

The current raw lobbie D is 377. The site gives me two ID's with the same revision number.

One is probably the noted ID and the other is without, just a guess though :D

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Example {

    public static void main(String[] args) {
        Example example = new Example();
        example.getItemsJson().ifPresent(json -> {
            example.getItemID(json, "Greenman's ale").ifPresent(System.out::println);
            example.getItemID(json, "Cannonball").ifPresent(System.out::println);
            example.getItemID(json, "Raw trout").ifPresent(System.out::println);
            example.getItemID(json, "Rune scimitar").ifPresent(System.out::println);
            example.getItemID(json, "Lobster").ifPresent(System.out::println);
        });
    }

    private Optional<Integer> getItemID(final String json, final String itemName) {
        return getItemFromJson(json, itemName).flatMap(this::getItemIDFromItemJson);
    }

    private Optional<String> getItemFromJson(final String json, final String itemName) {
        Matcher matcher = Pattern.compile("(\\{[^}]*\"name\"\\s*:\\s*\"" + Pattern.quote(itemName) + "\"[^}]*})").matcher(json);
        return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
    }

    private Optional<Integer> getItemIDFromItemJson(final String json) {
        Matcher matcher = Pattern.compile("\"id\"\\s*:\\s*(\\d*)").matcher(json);
        return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty();
    }

    private Optional<String> getItemsJson() {
        try {
            URL url = new URL("https://rsbuddy.com/exchange/summary.json");
            URLConnection con = url.openConnection();
            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            con.setUseCaches(true);

            try (InputStreamReader in = new InputStreamReader(con.getInputStream());
                 BufferedReader br = new BufferedReader(in)) {
                String json = br.readLine();
                json = json.replaceAll("\\\\u0027", "'");
                json = json.replaceAll("\\\\u0026", "&");
                return Optional.of(json);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Optional.empty();
    }
}


Output:

 

8522
2
335
1333
379

 

Edited by Explv

  • Author

@Explv Kudos to you. Extremely useful. Thanks

Edited by nosepicker

Thanks for the heads up. Didn't know about this one. But immediately I see a couple of concerns:

 

1) How do I know if the site will be available for a long time?

2) This is strange

itemdb.png

 

The current raw lobbie D is 377. The site gives me two ID's with the same revision number.

One is noted other isnt. i thougt first one was un-noted not 100% sure bout that tho

Also this site been around since 2007 i think lol, so yea doubt they leave anytime soon

  • 1 year later...
On 11/27/2016 at 8:29 PM, Explv said:

 

 

Also another solution if you just want to get the IDs of Grand Exchange items, and can't hardcode the IDs into your script you can do something like this:


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Example {

    public static void main(String[] args) {
        Example example = new Example();
        example.getItemsJson().ifPresent(json -> {
            example.getItemID(json, "Cannonball").ifPresent(System.out::println);
            example.getItemID(json, "Raw trout").ifPresent(System.out::println);
            example.getItemID(json, "Rune scimitar").ifPresent(System.out::println);
            example.getItemID(json, "Lobster").ifPresent(System.out::println);
        });
    }

    private Optional<Integer> getItemID(final String json, final String itemName) {
        return getItemFromJson(json, itemName).flatMap(this::getItemIDFromItemJson);
    }

    private Optional<String> getItemFromJson(final String json, final String itemName) {
        Matcher matcher = Pattern.compile("(\\{[^}]*\"name\"\\s*:\\s*\"" + Pattern.quote(itemName) + "\"[^}]*})").matcher(json);
        return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
    }

    private Optional<Integer> getItemIDFromItemJson(final String json) {
        Matcher matcher = Pattern.compile("\"id\"\\s*:\\s*(\\d*)").matcher(json);
        return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty();
    }

    private Optional<String> getItemsJson() {
        try {
            URL url = new URL("https://rsbuddy.com/exchange/summary.json");
            URLConnection con = url.openConnection();
            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            con.setUseCaches(true);
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String json = br.readLine();
            br.close();
            return Optional.of(json);
        } catch(Exception e) {
            e.printStackTrace();
        }
        return Optional.empty();
    }
}

Output:


2
335
1333
379

great example,

but if you input item name with Apostrophe character, e.g Greenman's ale,

it doesn't print anything.

Create an account or sign in to comment

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.