Jump to content

Search the Community

Showing results for tags 'inventoryitem'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • RuneLocus
    • News & Announcements
    • Information Booth
    • Website Support
    • Introductions
    • Chat
    • Forum Games
  • RuneScape Development
    • RSPS General
    • RuneScape Private Server (RS2)
    • RuneScape Private Server (503+)
    • RuneScape Private Server (EoC 742+)
  • Other
    • Digital Art
    • Gaming
    • Webdevelopment
    • Computers
  • Marketplace
    • RuneScape Market
    • RSPS Market
    • Others Market
    • Freelance Middleman Services
  • Super Secret Club's Topics

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Okay so, I currently have my items list saved in a .xml file and what I want to do is basically get the info from the xml for the specific item. Mm... Like Lets say in my item list file I have 3 items: health_potion, coins, wooden_sword I want to be able to get the item from the xml and use it in the game (like be able to get the specific items info like examine and shop price etc) and save it in Playersinvy.txt (I'm storing it in a .txt because I can't seem to get the inventory to save in the players XML file like RSPS do, if someone can help with that I would appreciate it!) Here's my Item related stuff and XMLParser(don't know if you need that though) [code] public class XMLParser { private List<Map<String, String>> elements = new ArrayList<Map<String, String>>(); private BufferedReader reader; public XMLParser(final String file) throws IOException { reader = new BufferedReader(new FileReader(file)); } public void setByElement(String name) throws IOException { String line; String endName = "</" + name + ">"; name = "<" + name + ">"; while ((line = reader.readLine()) != null) { if (line.contains(name)) { Map<String, String> element = new HashMap<String, String>(); while (!(line = reader.readLine()).contains(endName)) { element.put(line.substring(line.indexOf("<") + 1, line.indexOf(">")), line.substring(line.indexOf(">") + 1, line.lastIndexOf("<"))); } elements.add(element); } } reader.close(); } public List<Map<String, String>> getElements() { return elements; } public String getStringByTag(Map<String, String> element, String name) { return element.get(name); } public long getLongByTag(Map<String, String> element, String name) { return Long.parseLong(element.get(name)); } public int getIntByTag(Map<String, String> element, String name) { return Integer.parseInt(element.get(name)); } public short getShortByTag(Map<String, String> element, String name) { return Short.parseShort(element.get(name)); } public byte getByteByTag(Map<String, String> element, String name) { return Byte.parseByte(element.get(name)); } }[/code] [code]public class ItemList { private int id; private String name; private String examine; private boolean stackable; private int minPrice; private int normPrice; private int maxPrice; private int classType; public ItemList(int id, String name, String examine, int minPrice, int normPrice, int maxPrice, int classType, boolean stackable) { this.id = id; this.name = name; this.examine = examine; this.stackable = stackable; this.minPrice = minPrice; this.normPrice = normPrice; this.maxPrice = maxPrice; this.classType = classType; } public int getId() { return id; } public String getName() { return name; } public String getExamine() { return examine; } public boolean isStackable() { return stackable; } public int getMinPrice() { return minPrice; } public int getNormPrice() { return normPrice; } public int getMaxPrice() { return maxPrice; } public int getClassType() { return classType; } }[/code] [code]public class ItemManager { private static Map<Integer, ItemList> itemLists = new HashMap<Integer, ItemList>(); public ItemManager() { loadItemXML(); } public ItemList getList(int id) { return itemLists.get(id); } public int getItemClassType(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getClassType() : -1; } public String getItemName(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getName() : "Item"; } public boolean getStackable(int itemId) { ItemList list = itemLists.get(itemId); return list != null && list.isStackable(); } public String getItemExamine(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getExamine() : "an Item."; } public int getItemShopMinValue(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getMinPrice() : 1; } public int getItemShopNormPrice(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getNormPrice() : 1; } public int getItemShopMaxPrice(int itemId) { ItemList list = itemLists.get(itemId); return list != null ? list.getMaxPrice() : 1; } public static void loadItemXML() { try { XMLParser itemInfoXML = new XMLParser("data/items/items.xml"); itemInfoXML.setByElement("Item"); for(int i = 0; i < itemInfoXML.getElements().size(); i++) { Map<String, String> element = itemInfoXML.getElements().get(i); int id = itemInfoXML.getIntByTag(element, "Id"); String name = itemInfoXML.getStringByTag(element, "Name"); String examine = itemInfoXML.getStringByTag(element, "Examine"); boolean stackable = Boolean.parseBoolean(itemInfoXML.getStringByTag(element, "Stackable")); int minPrice = itemInfoXML.getIntByTag(element, "MinPrice"); int normPrice = itemInfoXML.getIntByTag(element, "NormPrice"); int maxPrice = itemInfoXML.getIntByTag(element, "MaxPrice"); int classType = itemInfoXML.getIntByTag(element, "ClassType"); itemLists.put(id, new ItemList(id, name, examine, classType, minPrice, normPrice, maxPrice, stackable)); } Constants.println("Item info loaded: "+itemLists.size()); } catch (Exception e) { System.out.println("Error loading items!"); } } }[/code] Item XML list [code]<Item> <Id>1</Id> <Name>Health_Potion</Name> <Examine>It's a health potion!</Examine> <Stackable>true</Stackable> <MinPrice>2</MinPrice> <NormPrice>5</NormPrice> <MaxPrice>10</MaxPrice> <ClassType>0</ClassType> </Item> <Item> <Id>2</Id> <Name>Wooden_Sword</Name> <Examine>Carved from a normal tree.</Examine> <Stackable>false</Stackable> <MinPrice>3</MinPrice> <NormPrice>8</NormPrice> <MaxPrice>13</MaxPrice> <ClassType>0</ClassType> </Item>[/code]
×