Sure I have five minutes.
@ScriptManifest(name = "Demo 3", info = "Demoooo", version = 1.0, author = "DeadCommon")
public class Demo3 extends Script {
NPC[] attackable;
@Override
public int onLoop() throws InterruptedException {
attackable = getAllAttackableNPC("Guard", "Goblin", "Cow", "Chicken");
return 550;
}
@Override
public void onPaint(Graphics arg0) {
if (attackable != null) {
boolean closest = true;
for (NPC next : attackable)
if (next != null) {
arg0.setColor(closest ? Color.GREEN : Color.RED);
arg0.drawPolygon(next.getPosition().getPolygon(bot));
closest = false;
}
}
}
public NPC[] getAllAttackableNPC(String... arg0) {
List<NPC> cache = client.getLocalNPCs();
if (cache == null || cache.isEmpty())
return null; // No NPCs found (whatsoever)
final Player me = myPlayer();
for (Iterator<NPC> i = cache.iterator(); i.hasNext(); ) {
NPC next = i.next();
if (next == null || !next.exists()
|| !contains(arg0, next.getName())
|| next.getHealth() == 0
|| (next.getFacing() != null && !next.isFacing(me)))
i.remove();
}
if (cache.isEmpty())
return null; // No valid NPCs filtered
Collections.sort(cache, new Comparator<NPC>() {
@Override
public int compare(NPC o1, NPC o2) {
return new Integer(o1.getPosition().distance(me.getPosition()))
.compareTo(new Integer(o2.getPosition().distance(
me.getPosition())));
}
});
return cache.toArray(new NPC[cache.size()]);
}
public static boolean contains(String[] a, String b) {
if (a == null || a.length == 0 || b == null || b.isEmpty())
return false;
else for (String next : a)
if (next != null && !next.isEmpty() && next.equals(b))
return true;
return false;
}
}