Hey guys, bringing a quick tutorial on a script I wrote for players to check the packed drop rates of NPCs ingame.
I did take the portion for formatting Item Amounts from the TizenX NetWealth class, but it's just for convenience.
First off, you're going to want to head to InterfaceManager.java and add these import statements
Code:
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.npc.Drop;
import com.rs.utils.NPCDrops;
import com.rs.cache.loaders.ItemDefinitions;
Next you will want to add this method anywhere in InterfaceManager.java
Code:
public void sendDropRates(int npcId, int amountKilled) {
NPCDefinitions defs = NPCDefinitions.getNPCDefinitions(npcId);
Drop[] drops = NPCDrops.getDrops(npcId);
if (drops == null) {
player.sendMessage("This NPC has no Drops");
return;
}
sendInterface(275);
player.getPackets().sendIComponentText(275, 2, defs.name +" Drop Table/Rates");
player.getPackets().sendIComponentText(275,16, "You have killed <col=ff0000>" + amountKilled +"</col> "+ defs.name +"s");
player.getPackets().sendIComponentText(275, 17, "");
player.getPackets().sendIComponentText(275, 18, "<col=00BFFF><shad=000000>Drop Amount Rate</shad></col>");
for (int i = 0;i<drops.length;i++)
player.getPackets().sendIComponentText(275, 19 + i, !drops[i].oneAmount() ? "<col=ff0000><shad=000000>" +
ItemDefinitions.getItemDefinitions(drops[i].getItemId()).getName() + " " +
drops[i].getFormattedMinAmount() + "-" + drops[i].getFormattedMaxAmount() + " " + drops[i].getFormattedRate() + "</col></shad>" :
"<col=ff0000> <shad=000000>" +ItemDefinitions.getItemDefinitions(drops[i].getItemId()).getName() + " " +
drops[i].getFormattedMaxAmount() + " " + drops[i].getFormattedRate() + "</col></shad>");
for (int i = 19 + drops.length; i < 316; i++)
player.getPackets().sendIComponentText(275, i, "");
}
Next you want to head over to Drop.java and add these lines of code in
Code:
public boolean oneAmount() {
return maxAmount == minAmount;
}
public String getFormattedMinAmount() {
return Utils.formatGP(minAmount);
}
public String getFormattedMaxAmount() {
return Utils.formatGP(maxAmount);
}
public String getFormattedRate() {
return Utils.formatPercentage(rate);
}
Next head to Utils.java and add this in
Code:
public static String formatGP(int coins) {
double total = 0;
total += (double)coins/1000000;
String mark = "";
if(total < 0.001) {
mark = "";
total = total * 1000000;
} else if(total >= 0.001 && total < 1) {
mark = "K";
total = total * 1000000;
} else if(total >= 1 && total < 1000) {
mark = "M";
} else if(total >= 1000 && total < 1000000) {
mark = "B";
total = total / 1000;
} else if(total >= 1000000 && total < 1000000000) {
mark = "T";
total = total / 1000000;
}
DecimalFormat df = new DecimalFormat("#0.00");
String formatted = df.format(total);
double finished = Double.parseDouble(formatted);
return "" + finished + mark;
}
public static String formatPercentage(double percent) {
if (percent == 0.0)
return "0";
String formatted = "";
double doubPercent = (100.0/percent);
double roundOff = (double) Math.round(doubPercent * 100) / 100;
formatted = "1/"+ roundOff + "";
return formatted;
}
That's all the code you will need to add. To call the method, you will obviously need to have some way of getting the NPC ID, I made a dialogue. For the part that says "amountkilled" you want to add the counter for the npc killed if available. Example: player.killedBandos;
If you would like an example dialogue here it is:
DropRates.java
Code:
/*package com.rs.game.player.dialogues;
import com.rs.Settings;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.dialogues.Dialogue;
import com.rs.game.player.Player;
import com.rs.utils.KillStreakRank;
import com.rs.utils.PkRank;
import com.rs.utils.ShopsHandler;
public class DropRates extends Dialogue {
@Override
public void start() {
sendDialogue(SEND_4_OPTIONS, "Select an NPC",
"Slayer Monsters", "Bosses", "Revenants", "Frost Dragons");
}
public void run(int interfaceId, int componentId) {
if (stage == -1) {
if (componentId == 1) {
sendDialogue(SEND_4_OPTIONS, "Select an NPC",
"Abyssal Demons", "Dark Beasts", "Abyssal Demons (ice)", "Back");
stage = 0;
} else if (componentId == 2) {
sendDialogue(SEND_5_OPTIONS, "Select an NPC",
"Godwars", "Blink", "Vorago", "Corporeal Beast", "Next Page");
stage = 1;
} else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(13479,player.killedRevenant);
end();
} else if (componentId == 4) {
player.getInterfaceManager().sendDropRates(51,player.killedFrostie);
end();
}
} else if (stage == 0) {
if (componentId == 1) {
player.getInterfaceManager().sendDropRates(1615,player.killedAbyssalDemon);
end();
} else if (componentId == 2) {
player.getInterfaceManager().sendDropRates(2783,player.killedDarkBeast);
end();
}else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(15668,player.killedIceAbyssalDemon);
end();
} else {
sendDialogue(SEND_4_OPTIONS, "Select an NPC",
"Slayer Monsters", "Bosses", "Revenants", "Frost Dragons");
stage = -1;
}
} else if (stage == 1) {
if (componentId == 1) {
sendDialogue(SEND_5_OPTIONS, "Select an NPC",
"Armadyl", "Bandos", "Zamorak", "Saradomin", "Back");
stage = 2;
} else if (componentId == 2) {
player.getInterfaceManager().sendDropRates(12878,player.killedBlink);
end();
} else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(8141,player.killedVorago);
end();
} else if (componentId == 4) {
player.getInterfaceManager().sendDropRates(8133, player.killedCorp);
end();
} else {
sendDialogue(SEND_5_OPTIONS, "Select an NPC",
"Corporeal Beast (L33T)", "King Black Dragon", "Tormented Demon", "Nomad", "Next Page");
stage = 3;
}
} else if (stage == 2) {
if (componentId == 1) {
player.getInterfaceManager().sendDropRates(6222,player.killedKree);
end();
} else if (componentId == 2) {
player.getInterfaceManager().sendDropRates(6260,player.killedGraardor);
end();
} else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(6203,player.killedKril);
end();
} else if (componentId == 4) {
player.getInterfaceManager().sendDropRates(6247, player.killedZilyana);
end();
} else {
sendDialogue(SEND_5_OPTIONS, "Select an NPC",
"Godwars", "Blink", "Vorago", "Corporeal Beast", "Next Page");
stage = 1;
}
} else if (stage == 3) {
if (componentId == 1) {
player.getInterfaceManager().sendDropRates(14500,player.killedL33t);
end();
} else if (componentId == 2) {
player.getInterfaceManager().sendDropRates(50,player.killedKBD);
end();
} else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(8349,player.killedTD);
end();
} else if (componentId == 4) {
player.getInterfaceManager().sendDropRates(8528, player.killedNomad);
end();
} else {
sendDialogue(SEND_5_OPTIONS, "Select an NPC",
"Avatar of Destruction", "BeastPk Demon", "Thunder", "Evil Chicken", "Flamebeed");
stage = 4;
}
} else if (stage == 4) {
if (componentId == 1) {
player.getInterfaceManager().sendDropRates(8596,player.killedAOD);
end();
} else if (componentId == 2) {
player.getInterfaceManager().sendDropRates(15881,player.killedBPD);
end();
} else if (componentId == 3) {
player.getInterfaceManager().sendDropRates(11872,player.killedThunder);
end();
} else if (componentId == 4) {
player.getInterfaceManager().sendDropRates(3375, player.killedChicken);
end();
} else {
player.getInterfaceManager().sendDropRates(3494, player.killedFlambeed);
end();
}
}
}
@Override
public void finish() {
}
}*/
If done correctly, this will be the outcome: