first you would need to import the NPC class into the class your stalls method is in.
Code:
import server.model.npcs.NPC;
then inside the stall method, where it has you fail the method
Code:
if (Misc.random(10) == 8 && c.playerLevel[c.playerThieving] < 99) {
NPC n = c.getCloseRandomNpc(10);
if (n != null) {
n.killerId = c.playerId;
n.underAttack = true;
n.forceChat("Get your thieving hands out of my stalls!");
return;
}
}
and add this method to your Player.java:
Code:
public NPC getCloseRandomNpc(int distance) {
ArrayList<NPC> npcs = new ArrayList<NPC>();
for (int j = 0; j < Server.npcHandler.npcs.length; j++) {
if (Server.npcHandler.npcs[j] != null) {
NPC n = Server.npcHandler.npcs[j];
if (distanceToPoint(n.getX(), n.getY()) <= distance) {
if (!n.underAttack)
if (n.heightLevel == heightLevel)
npcs.add(n);
}
}
}
if (npcs.size() > 0)
return npcs.get(Misc.random(npcs.size() -1));
else
return null; // No near npcs :C
}
here is my method with it implemeted so you can see:
Code:
public void stealFromStall(int id, int xp, int level) {
if (System.currentTimeMillis() - c.lastThieve < 2500)
return;
if (Misc.random(100) == 0) {
return;
}
if (Misc.random(6) == 5 && c.playerLevel[c.playerThieving] < 99) {
NPC n = c.getCloseRandomNpc(10);
if (n != null) {
n.killerId = c.playerId;
n.underAttack = true;
n.forceChat("Get your thieving hands out of my stalls!");
return;
}
}
if (c.playerLevel[c.playerThieving] >= level) {
if (c.getItems().addItem(id,1)) {
c.startAnimation(832);
c.getPA().addSkillXP(xp * Config.THIEVING_EXPERIENCE, c.playerThieving);
c.lastThieve = System.currentTimeMillis();
c.sendMessage("You steal a " + server.model.items.Item.getItemName(id) + ".");
}
} else {
c.sendMessage("You must have a thieving level of " + level + " to steal from this stall.");
}
}
if you dont have getX() and getY() in your NPC class, add them.
Code:
public int getX() {
return absX;
}
public int getY() {
return absY;
}
this is just off the top of my head. you get the picture tho.. x3