I tried following a boss achievement and tracker code made by hc747 and zach.
Code:
package com.rs.game.player.content;
import java.io.Serializable;
import java.util.HashMap;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.World;
import com.rs.game.player.Player;
public class NpcCounts implements Serializable {
private static final long serialVersionUID = -6650338643379886360L;
private Player player;
private HashMap<Integer,Integer> NPC_COUNTS;
/**
* In the player class, place:
* private NpcCounts npcCounts;
* public NpcCounts getNpcCounts() {
* return npcCounts();
* }
*
* Then in your initialisation methods
* if (npcCounts == null)
* npcCounts = new NpcCounts();
*
* and
*
* npcCounts.setPlayer(this);
*
* In the npc class, within the sendDeath method, place:
*
* final NpcCounts npcCounts = player.getNpcCounts();
* if (npcCounts != null)
* npcCounts.incrementCounts(npcId);
*
* In your commands class:
* if (cmd[0].equalsIgnoreCase("bosskills") {
* final NpcCounts counts = player.getNpcCounts();
* if (counts == null)
* return true;
* counts.showProgress();
* return true;
* }
*/
public void setPlayer(final Player player) {
this.player = player;
}
private static final int[] VALID_NPCS = {
/**
* Add the npc ids you want to be tracked in here
*/
};
private static final int[] ANNOUNCED_COUNTS = {
/**
* Add the counts that you want to be announced here
*/
50,150,250,500,750,1000,1500,2000
};
public NpcCounts() {
NPC_COUNTS = new HashMap<Integer,Integer>();
for (final int i : VALID_NPCS)
NPC_COUNTS.put(i, 0);
}
private void announceAchievement(String name, int count) {
if (player == null)
return;
World.sendWorldMessage("<col=ff0000>"+player.getDisplayName()+" has just reached "+count+" "+name+" kills!");
}
private static boolean isValidNpc(final int npcId) {
for (final int i : VALID_NPCS)
if (npcId == i)
return true;
return false;
}
public void incrementCount(final int npcId) {
if (player == null || !isValidNpc(npcId))
return;
final NPCDefinitions defs = NPCDefinitions.getNPCDefinitions(npcId);
if (defs == null)
return;
Integer previous = NPC_COUNTS.remove(npcId);
if (previous == null)
previous = 0;
previous+=1;
player.getPackets().sendGameMessage("<col=00ff00>You have now killed "+previous+" "+defs.getName()+"!");
NPC_COUNTS.put(npcId, previous);
for (final int i : ANNOUNCED_COUNTS) {
if (previous == i) {
announceAchievement(defs.getName(),previous);
break;
}
}
}
public void showProgress() { if (player == null)
return;
player.getInterfaceManager().sendInterface(1245);
player.getPackets().sendIComponentText(1245, 330, "Your Total Boss Kills:");
int count = 13;
if (NPC_COUNTS.isEmpty()) {
player.getPackets().sendIComponentText(1245, count, "You have no tracked kills.");
return;
}
for (final int i : NPC_COUNTS.keySet()) {
final NPCDefinitions defs = NPCDefinitions.getNPCDefinitions(i);
if (defs == null)
continue;
player.getPackets().sendIComponentText(1245, count++, "You have killed "+defs.getName()+" "+NPC_COUNTS.get(i)+" times.");
}
}
}
When I followed the guide inside of the code I didnt know where I were supposed to place this
Code:
* Then in your initialisation methods
* if (npcCounts == null)
* npcCounts = new NpcCounts();
*
* and
*
* npcCounts.setPlayer(this);
So I was wondering if anyone knew? Thank you!