Mechagoober Posted June 18, 2016 Share Posted June 18, 2016 I'm going off Saiyan's chicken killer, trying to customize it so it will actually run and look legit. Well, I've tried to customize it and I am not having much luck learning. So I thought I would post a topic and request some help. Remember, I'm fairly new to java and am trying not to give up. I think i'm looking how to use a Filter so it attacks the right npc.. not sure if this is the same thing as a filter or not.Also, here is a link to Saiyan's chicken killer he posted a half year ago. http://osbot.org/forum/topic/89682-open-source-chicken-killer-can-copy-and-paste-and-improve5-min-script/ Do I need to create my own methods to start using them in if statements so for ex. I can call a method to have a conditional Sleep? Idk how to use a filter, i think i need that to be successful. This is what I found for a filter, i think this is the most relevant to my script but idk!! Any help is appreciated!And yes I have looked at the API, its intimidating at a glance NPC chicken = getNpcs().closest("Chicken"); NPC chicken = getNpcs().closest(filters) import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import org.osbot.rs07.api.filter.NameFilter; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import java.awt.*; @ScriptManifest(author = "Kitten Krazy", info = "Adam's Chicken Killer", name = "Chicken Killer", version = 0, logo = "") public class main extends Script { final Area CHICKEN_AREA = new Area(3226, 3001, 3236, 3295); @Override public void onStart() { log("Kitten Krazy's chicken killer"); } private enum State { KILL, SLEEP; } private State getState() { NPC chicken = getNpcs().closest("Chicken"); if(chicken != null){ return State.KILL; } return State.SLEEP; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case KILL: NPC chicken = getNpcs().closest("Chicken"); if(!getCombat().isFighting()){ if(!myPlayer().isUnderAttack()){ if(chicken != null){ chicken.interact("Attack"); } } } if(chicken.interact("Attack")){ new ConditionalSleep(3000, 500){ public boolean condition() throws InterruptedException{ return myPlayer().isInteracting(chicken); } }.sleep(); } if(myPlayer().isInteracting(chicken)){ new ConditionalSleep(3000, 500){ public boolean condition() throws InterruptedException{ return myPlayer().isInteracting(chicken); } }.sleep(); } } return 0; } @Override public void onExit() { log("Thanks for running my chicken killer!"); } @Override public void onPaint(Graphics2D g) { } } 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted June 18, 2016 Share Posted June 18, 2016 (edited) NPC chicken = getNpcs().closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc != null && npc.exists() && npc.getName().equals("Chicken") && npc.isAttackable(); } }); //ConditionalSleep example if (chicken != null){ if (chicken.interact("Attack")){ new ConditionalSleep(5000) { // 5000ms timeout @Override public boolean condition() throws InterruptedException { return myPlayer().isInteracting(chicken); } }.sleep(); } } Hope it helps Edited June 18, 2016 by Christopher Quote Link to comment Share on other sites More sharing options...
Mechagoober Posted June 18, 2016 Author Share Posted June 18, 2016 (edited) Why exactly does Filter stay having red lines under it? I copyed that exact code and it still gives red lines. Did I not import something I appreciate your response Edited June 18, 2016 by Kitten Krazy 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted June 18, 2016 Share Posted June 18, 2016 (edited) Why exactly does Filter stay having red lines under it? I copyed that exact code and it still gives red lines. Did I not import something I appreciate your response Yes you need to import import org.osbot.rs07.api.filter.Filter; You could also use lambda NPC blah = getNpcs().closest(npc -> npc.getName().equals("Cat") && //other conditions); then interact View this thread for some helpful information. Edited June 18, 2016 by Christopher Quote Link to comment Share on other sites More sharing options...
Mechagoober Posted June 18, 2016 Author Share Posted June 18, 2016 Thank you so much,Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closestIt has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again! Quote Link to comment Share on other sites More sharing options...
Chris Posted June 18, 2016 Share Posted June 18, 2016 I use intellij so idk about eclipse. I'm off to bed now. Good luck Thank you so much, Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closest It has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again! Quote Link to comment Share on other sites More sharing options...
Mechagoober Posted June 18, 2016 Author Share Posted June 18, 2016 (edited) Thank you!Switched to IntelliJ Helped me dearly Edited June 18, 2016 by Kitten Krazy Quote Link to comment Share on other sites More sharing options...
Auron Posted June 19, 2016 Share Posted June 19, 2016 Thank you so much, Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closest It has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again! Eclipse does tell to import if you hover over the red text. Ctrl+shift+o is a useful shortcut to sort out all imports, super useful. Another useful shortcut in eclipse is ctrl+shift+f which formats your code to make it more readable. As for the code, I'd split it up into logical steps: if (not in combat) NPC chicken = findChicken(); attack(chicken); else Sleep or do anything you would do in combat As for a findChicken method, something like this. private NPC findNPC(NPC... exceptions) { @SuppressWarnings("unchecked") NPC chicken = getNpcs().closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc.getName().equals("Chicken") && !npc.isUnderAttack() && (npc.getHealthPercent() > 0) } }); return chicken; } And for attack, maybe private void attack(NPC chicken) throws InterruptedException { if (chicken != null) { if (map.canReach(chicken)) { if (chicken.isVisible()) { chicken.interact("Attack"); } else { s.camera.toEntity(chicken); } } } } I think it's just a good habit overall to split your steps into methods, leads to cleaner code and makes it so you can reuse it often. 1 Quote Link to comment Share on other sites More sharing options...