Here are two snippets of code that allow you to get the drop table of any npc on the osrs wiki(as far as i know that's all the npcs)
for this to work you need to add jsoup code to your project (you can find it here: https://github.com/jhy/jsoup).
The only real use for this is the gui of fighter scripts.
The item name and icon will always have the same index in the arrays used.
Example usage:
package Test;
import Utils.WikiParser;
import Utils.DropTable;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
public class test {
public static void main(String[] args){
DropTable testTable = WikiParser.getMonsterDroptable("Chicken"); //if you look at chicken on wiki you will see the first item is bones
System.out.println(testTable.getItemNames()[0]); // therefore bones have the index 0
ImageIO.write(imageToBufferedImage(testTable.getItemImages[0]), "png" , new File("Bones.png")); /will save Bones.png
}
private static BufferedImage imageToBufferedImage(Image im) {
BufferedImage bi = new BufferedImage
(im.getWidth(null),im.getHeight(null),BufferedImage.TYPE_INT_ARGB);
Graphics bg = bi.getGraphics();
bg.drawImage(im, 0, 0, null);
bg.dispose();
return bi;
}
}
Source:
WikiParser.java
package Utils;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import Utils.JSoup.Jsoup;
import Utils.JSoup.nodes.Document;
import Utils.JSoup.select.Elements;
public class WikiParser {
public static DropTable getMonsterDroptable(String monsterName){
try {
Document doc = Jsoup.connect("http://oldschoolrunescape.wikia.com/wiki/" + monsterName.replaceAll(" ", "_")).get();
Elements tables = doc.getElementsByClass("wikitable sortable dropstable");
System.out.println("tables: " + tables.size());
Elements rows = tables.select("tr");
System.out.println("rows: " + rows.size());
Image[] images = new Image[rows.size() - tables.size()];
String[] names = new String[rows.size() - tables.size()];
int skipped = 0;
for(int i = 1; i < rows.size(); i++){
Elements collumns = rows.get(i).select("td");
if(collumns.size() == 5){
images[i - (1 + skipped)] = getImage(collumns.get(0).getElementsByTag("img").get(0).attr("data-src"));
names[i - (1 + skipped)] = collumns.get(1).text();
}else{
skipped++;
}
}
return new DropTable(names, images);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static Image getImage(String url) {
try {
return ImageIO.read(new URL(url));
} catch (IOException e) {
return null;
}
}
}
DropTable.java
package Utils;
import java.awt.Image;
public class DropTable {
String[] itemNames;
Image[] itemImages;
public DropTable(String[] itemNames, Image[] itemImages){
this.itemNames = itemNames;
this.itemImages = itemImages;
}
public Image[] getItemImages(){
return itemImages;
}
public String[] getitemNames(){
return itemNames;
}
public void addItem(String itemName, Image itemImage){
String[] tempStrings = new String[itemNames.length + 1];
Image[] tempImages = new Image[itemImages.length + 1];
for(int i = 0; i < itemNames.length; i++){
tempStrings[i] = itemNames[i];
tempImages[i] = itemImages[i];
}
tempStrings[itemNames.length] = itemName;
tempImages[itemImages.length] = itemImage;
itemNames = tempStrings;
itemImages = tempImages;
}
}