Paradox68 Posted December 28, 2015 Posted December 28, 2015 (edited) Probably super simple I'm just not sure. Been a while since I've been on here. Also my script keeps getting stuck saying there are arrows to be picked up but there aren't. Any ideas why? public boolean arrowsPresent() { if (getGroundItems().closest(arrowType) != null) { return true; } return false; } Edited December 28, 2015 by Paradox68
AresScripts Posted December 28, 2015 Posted December 28, 2015 (edited) Probably super simple I'm just not sure. Been a while since I've been on here. I would use a filter like this: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { if (n.getId() != monsterID) return false; if(!n.getName().equals(monsterName)) return false; if(n.isUnderAttack()) return false; return true; } }; then you can just say: NPC monster = getNpcs().closest(monsterFilter); Did that help? Edited December 28, 2015 by AresScripts
Paradox68 Posted December 28, 2015 Author Posted December 28, 2015 (edited) I would use a filter like this: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { if (n.getId() != monsterID) return false; if(!n.getName().equals(monsterName)) return false; if(n.isUnderAttack()) return false; return true; } }; then you can just say: NPC monster = getNpcs().closest(monsterFilter); Did that help? A lot actually, thanks dude. Not to be mr. stupid but what's this about? Edited December 28, 2015 by Paradox68
AresScripts Posted December 28, 2015 Posted December 28, 2015 (edited) A lot actually, thanks dude. Not to be mr. stupid but what's this about? I haven't used eclipse in a while but i remember that being not necessary to fix. Warnings usually aren't an actual problem(someone correct me if im wrong) Edited December 28, 2015 by AresScripts
Explv Posted December 28, 2015 Posted December 28, 2015 (edited) I would use a filter like this: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { if (n.getId() != monsterID) return false; if(!n.getName().equals(monsterName)) return false; if(n.isUnderAttack()) return false; return true; } }; then you can just say: NPC monster = getNpcs().closest(monsterFilter); Did that help? Or you could just do: NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack()); A lot actually, thanks dude. Not to be mr. stupid but what's this about? Just suppress it, the warning is for an operation that is potentially unsafe, but in this case we know it is fine. @SuppressWarnings("unchecked") NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack()); Also with regards to your arrow method, it can be simplified to: public boolean arrowsPresent() { return getGroundItems().closest(arrowType) != null; } And it should work fine, it is probably an issue somewhere else in your code. Edited December 28, 2015 by Explv 1
AresScripts Posted December 28, 2015 Posted December 28, 2015 Or you could just do: NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack()); Just suppress it, the warning is for an operation that is potentially unsafe, but in this case we know it is fine. @SuppressWarnings("unchecked") NPC monster = getNpcs().closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack()); Also with regards to your arrow method, it can be simplified to: public boolean arrowsPresent() { return getGroundItems().closest(arrowType) != null; } And it should work fine, it is probably an issue somewhere else in your code. Ah. I need to study up on lambda expressions
Explv Posted December 29, 2015 Posted December 29, 2015 (edited) Ah. I need to study up on lambda expressions I found your Filter to be written a little oddly as well Why would you do: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { if (n.getId() != monsterID) return false; if(!n.getName().equals(monsterName)) return false; if(n.isUnderAttack()) return false; return true; } }; when you could just do: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { return n.getName().equals("Cow") && !n.isUnderAttack(); } }; But yeah, lambdas make everything more simple anyway ^_^ Edited December 29, 2015 by Explv
AresScripts Posted December 29, 2015 Posted December 29, 2015 I found your Filter to be written a little oddly as well Why would you do: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { if (n.getId() != monsterID) return false; if(!n.getName().equals(monsterName)) return false; if(n.isUnderAttack()) return false; return true; } }; when you could just do: Filter<NPC> monsterFilter = new Filter<NPC>() { @Override public boolean match(NPC n) { return n.getName().equals("Cow") && !n.isUnderAttack(); } }; But yeah, lambdas make everything more simple anyway Even though that takes up less lines of code, I like to only do one "filter" per if statement because its easier to debug for me. 1