Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • How to get item ID from name


    dorukanji

    Recommended Posts

    not currently located anywhere

     

    I am taking input as a String, eg. "Bronze sword", and then checking GE API, which uses ID, for its price

     

    I can find the ID from the Item class but just wondering if there was a way to get ID from name without the actual Item, seeing as Item only has ID constructor

     

    I have a workaround but just wondering. I'm guessing it doesn't work too well if two items have different ID but the same name.

    Link to comment
    Share on other sites

    Well, you can put the items in your own Map object. I think item names are unique (I can't think of any GE items with the same names but are different), so a Map<String, Integer> with name as the key and the id as the value could work.

     

    To make such a Map, you can take this JSON of all the items https://rsbuddy.com/exchange/names.json, iterate over the keys (the ids), take the name, put it in your Map as the key and take the current id key and put it as the value.

    Link to comment
    Share on other sites

    You don't even need a map. You could also make an Enum:

     

    BRONZE_SWORD("Bronze sword", <ID>);

     

    Then just make the constructor for it and grab the ID. ID's can be found on the internet. I don't think you can grab the ID's from the game without the actual item.

     

    Manually doing this for each item on RS will be a huge load of work, so Slasso's solution is way better!

    Link to comment
    Share on other sites

    Well, you can put the items in your own Map object. I think item names are unique (I can't think of any GE items with the same names but are different), so a Map<String, Integer> with name as the key and the id as the value could work.

     

    To make such a Map, you can take this JSON of all the items https://rsbuddy.com/exchange/names.json, iterate over the keys (the ids), take the name, put it in your Map as the key and take the current id key and put it as the value.

    Names are not unique, multiple items have the same name (For example, noted version of an item has the same name as the unnoted verson).

    Link to comment
    Share on other sites

    not currently located anywhere

     

    I am taking input as a String, eg. "Bronze sword", and then checking GE API, which uses ID, for its price

     

    I can find the ID from the Item class but just wondering if there was a way to get ID from name without the actual Item, seeing as Item only has ID constructor

     

    I have a workaround but just wondering. I'm guessing it doesn't work too well if two items have different ID but the same name.

     

     

    Here you go. I iterated through all the items and auto generated the puts you need.

    Some item names have multiple ids so I have a custom put method that handles that and adds it to the list.

     

    http://pastebin.com/UM9c9rU5 edit: make the public methods in this class static.

     

     

    In your main class, call Items.initMap() in the onStart() and you can make a Map variable, Map<String, Integer> itemsMap = Items.getMap().

     

    Then you can do what you wanted originally. int id = itemsMap.get("Bronze sword");

     

     

    Names are not unique, multiple items have the same name (For example, noted version of an item has the same name as the unnoted verson).

     
    Map which has a List<Integer> as value works fine
    Link to comment
    Share on other sites

     

    Here you go. I iterated through all the items and auto generated the puts you need.

    Some item names have multiple ids so I have a custom put method that handles that and adds it to the list.

     

    http://pastebin.com/UM9c9rU5 edit: make the public methods in this class static.

     

     

    In your main class, call Items.initMap() in the onStart() and you can make a Map variable, Map<String, Integer> itemsMap = Items.getMap().

     

    Then you can do what you wanted originally. int id = itemsMap.get("Bronze sword");

     

     

     
    Map which has a List<Integer> as value works fine

     

     

    You're a real hero

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.