aekramer Posted December 29, 2014 Share Posted December 29, 2014 Hey all, I am trying to figure something out and I really need to clear my head on this one probably lol. How would I go around checking if a certain tile or area does NOT contain ANY NPC? I've tried creating a Position list for the area, then looping through all these positions (I only use small area's, like 3x3), then grabbing a List of all local NPCs and checking for every Tile if none of those NPCs are on it. private boolean isAreaClear(Area area) { List<NPC> npcs = getNpcs(); if (area == null) { return true; } List<Position> areaPos = area.getPositions(0); for (NPC npc : npcs) { for (Position pos : areaPos) { if (npc.getPosition().equals(pos)) { return false; } } } return true; } private List<NPC> getNpcs() { List<NPC> list = new LinkedList<>(); for (NPC npc : sC.npcs.getAll()) { if (npc.getDefinition() != null) { search: { if(npc.getDefinition().getName() != null){ String name = npc.getDefinition().getName(); if (name.equalsIgnoreCase("bandit")) { list.add(npc); break search; } } } } } return list; } Link to comment Share on other sites More sharing options...
Eliot Posted December 29, 2014 Share Posted December 29, 2014 (edited) I don't remember exact OSBot API, but something like this should work (this is one of several ways to do it): //TODO add whatever null checks are needed... public boolean NpcInArea(Area area) { for (NPC npc : npcs.getAll()) { if (area.contains(npc)) return true; } return false; } Edited December 29, 2014 by Eliot 2 Link to comment Share on other sites More sharing options...
aekramer Posted December 29, 2014 Author Share Posted December 29, 2014 I don't remember exact OSBot API, but something like this should work (this is one of several ways to do it): //TODO add whatever null checks are needed... public boolean NpcInArea(Area area) { for (NPC npc : npcs.getAll()) { if (area.contains(npc)) return true; } return false; } Thank you, apparantly I was overcomplicating things again.. Link to comment Share on other sites More sharing options...