Snowydell Posted January 25, 2015 Share Posted January 25, 2015 (edited) Here's the code NPC cow = npcs.closest("Cow", "Cow calf"); if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack() && !cow.isUnderAttack() && cow != null) { cow.interact("Attack"); } Now basically what happens is it will target the closest cow even if it's in combat so it will just wait until the cow is dead to target a new cow. How would I make it do something like: npc.closest("Cow", "Cow calf").!isUnderAttack Sorry for all the questions, but this script i'm working on i'll put in the local script section so hopefully if it works Edited January 25, 2015 by Snowydell Link to comment Share on other sites More sharing options...
Mysteryy Posted January 25, 2015 Share Posted January 25, 2015 Make a filter for it. A filter will basically only accept npcs that meet a specific criteria, i.e. the cow is not under attack. There might be something in the api for this already, but this is a way you can do it without an api method. 1 Link to comment Share on other sites More sharing options...
Isolate Posted January 25, 2015 Share Posted January 25, 2015 (edited) Here's the code NPC cow = npcs.closest("Cow", "Cow calf"); if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack() && !cow.isUnderAttack() && cow != null) { cow.interact("Attack"); } Now basically what happens is it will target the closest cow even if it's in combat so it will just wait until the cow is dead to target a new cow. How would I make it do something like: npc.closest("Cow", "Cow calf").!isUnderAttack Sorry for all the questions, but this script i'm working on i'll put in the local script section so hopefully if it works you could always try NPC cow = npcs.closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null && npc.getHealth() >0 && npc.isAttackable() && !npc.isUnderAttack(); } }); if(!inventory.isFull() && COW_AREA.contains(myPlayer()) && !myPlayer().isUnderAttack() && cow != null) { cow.interact("Attack"); } Edited January 25, 2015 by Isolate 2 Link to comment Share on other sites More sharing options...
Snowydell Posted January 25, 2015 Author Share Posted January 25, 2015 Thanks guys I will try that Isolate Link to comment Share on other sites More sharing options...
Dog_ Posted January 25, 2015 Share Posted January 25, 2015 you could always try return npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null && npc.getHealth() >0 && npc.isAttackable() && !npc.isUnderAttack(); why are you checking for if the pointer is null after your already using the instance Link to comment Share on other sites More sharing options...
Isolate Posted January 25, 2015 Share Posted January 25, 2015 why are you checking for if the pointer is null after your already using the instance Because I like to be sure ;) long time no doge Link to comment Share on other sites More sharing options...
Mysteryy Posted January 25, 2015 Share Posted January 25, 2015 why are you checking for if the pointer is null after your already using the instance Because I like to be sure long time no doge He means why are you doing this: npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null null checking npc after you call npc.getName is pointless. If there is an NPE you will get it on npc.getName, and thus null checking after you call a method from that object is pointless. The NPE will not be avoided at all. Link to comment Share on other sites More sharing options...
Isolate Posted January 25, 2015 Share Posted January 25, 2015 He means why are you doing this: npc.getName().contains("Cow") && !npc.getName().contains("Dairy") && npc != null null checking npc after you call npc.getName is pointless. If there is an NPE you will get it on npc.getName, and thus null checking after you call a method from that object is pointless. The NPE will not be avoided at all. move it to the start then. Link to comment Share on other sites More sharing options...