Darek855 Posted March 20, 2019 Share Posted March 20, 2019 Why does this not work? i am trying to see if there is an npc in 1 tile radius around my player. Not getting any errors on compiling but it wont run. (npc id is not correct in this example but it is correct in my code) NPC goblin = npcs.closest(123); @Override public int onLoop(){ if (myPlayer().getArea(1).contains(goblin)) { log("Goblin next to me"); } return random(200, 300); } Quote Link to comment Share on other sites More sharing options...
Ragboys is back Posted March 20, 2019 Share Posted March 20, 2019 (edited) Try NPC goblin = getNpcs().closest(myPlayer().getArea(1), "Goblin"); if(goblin != null){ log("Goblin is near me"); } Edited March 20, 2019 by Ragboys is back 1 Quote Link to comment Share on other sites More sharing options...
Darek855 Posted March 20, 2019 Author Share Posted March 20, 2019 26 minutes ago, Ragboys is back said: Try NPC goblin = getNpcs().closest(myPlayer().getArea(1), "Goblin"); if(goblin != null){ log("Goblin is near me"); } Worked! Thank you. Quote Link to comment Share on other sites More sharing options...
HunterRS Posted March 20, 2019 Share Posted March 20, 2019 (edited) Try looking into filters too: Filter<NPC> goblinFilter = npc -> npc.getName().equalsIgnoreCase("Goblin") && myPlayer().getArea(1).contains(npc) && !npc.isHitBarVisible() && npc.isAttackable() && !npc.isUnderAttack() && npc.isVisible(); . . . . NPC goblin = getNpcs().closest(goblinFilter); Using them will result in cleaner code. EDIT: Don't just copy and paste this, i just threw a couple of methods of the top of my head. Edited March 20, 2019 by HunterRS Quote Link to comment Share on other sites More sharing options...
Darek855 Posted March 20, 2019 Author Share Posted March 20, 2019 2 hours ago, HunterRS said: Try looking into filters too: Filter<NPC> goblinFilter = npc -> npc.getName().equalsIgnoreCase("Goblin") && myPlayer().getArea(1).contains(npc) && !npc.isHitBarVisible() && npc.isAttackable() && !npc.isUnderAttack() && npc.isVisible(); . . . . NPC goblin = getNpcs().closest(goblinFilter); Using them will result in cleaner code. EDIT: Don't just copy and paste this, i just threw a couple of methods of the top of my head. Filters looks super useful, i was also wondering how to make something like this shorter and cleaner if(getInventory().contains("Prayer potion(4)") && getInventoy().contains("Prayer potion(3)")) Would be nice to know for the future as many things has x amount of charges or doses etc Quote Link to comment Share on other sites More sharing options...
HunterRS Posted March 20, 2019 Share Posted March 20, 2019 2 minutes ago, Darek855 said: Filters looks super useful, i was also wondering how to make something like this shorter and cleaner if(getInventory().contains("Prayer potion(4)") && getInventoy().contains("Prayer potion(3)")) Would be nice to know for the future as many things has x amount of charges or doses etc Filter<Item> prayerPotFilter = item -> item.getName().contains("Prayer potion("); . . . . if (getInventory().contains(prayerPotFilter)) { log("We have a prayer potion"); } This should work, play around with filters and the API, super usefull stuff. Quote Link to comment Share on other sites More sharing options...
Darek855 Posted March 20, 2019 Author Share Posted March 20, 2019 38 minutes ago, HunterRS said: Filter<Item> prayerPotFilter = item -> item.getName().contains("Prayer potion("); . . . . if (getInventory().contains(prayerPotFilter)) { log("We have a prayer potion"); } This should work, play around with filters and the API, super usefull stuff. Right you can use filters for more than just npcs My next bot that i write will be so much more compact and clean. recently wrote a bot that kills 1 creature over and over and banks, and that is 1090 rows... of course it includes tons of checks so it never dies or gets stuck also tons of anti-pattern things even tho i am not sure how much that helps with banrates. wont hurt the GP hour so whatever. anyways, thanks for the tips! Quote Link to comment Share on other sites More sharing options...