June 23, 20178 yr Hey guys, I'm trying to learn Java, and script writing. I've been reading some tutorials and I just wrote this SUPER basic first script, however, it does NOTHING. I'm wondering if anyone can tell me where I went wrong, and why it does not attack "Chickens" import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; import java.lang.Thread.State; @ScriptManifest(author = "MySQLi", info = "Basic Chicken Killer", name = "MyChickenKiller", version = 1.0, logo = "") public class Main extends Script { @Override public void onStart() { log("Thank you for using my script, Let's kill chickens!"); } //What are we going to do in our script private enum State{ KILL,WAIT }; //Declare our conditions private State getState(){ RS2Object chicken = getObjects().closest("Chicken"); if(chicken != null) return State.KILL; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()){ case KILL: RS2Object chicken = getObjects().closest("Chicken"); if(chicken != null) { chicken.interact("Attack"); } break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } @Override public void onExit() { log("Thanks for running my Chicken Killer!"); } @Override public void onPaint(Graphics2D g) { } }
June 23, 20178 yr @MySQLi Pretty sure its because you're using Objects. Read this guide: Use Entity & getNpc. Entity chicken = getNpcs().closest("Chicken"); Edited June 23, 20178 yr by Phaibooty
June 23, 20178 yr just use onLoop bro @Override public int onLoop() throws InterruptedException { if (!getCombat().isFighting() || myPlayer().getInteracting() == null){ //if not fighting or get interacting does not exist //NPC npc = getNpcs().closest("Chicken"); basic NPC npc = getNpcs().closest(new Filter<NPC>() { //filter api @Override public boolean match(NPC npc) { return npc.hasAction("Attack") && npc.getName().equals("Chicken") && npc.getHealthPercent() > 0 && npc.getInteracting() == null; } }); if (npc != null && npc.interact("Attack")) { new ConditionalSleep(2000) { //timout time. once 2000ms passes it will stop @Override public boolean condition() throws InterruptedException { return getCombat().isFighting() || !npc.isAttackable(); //sleep until WE ARE FIGHTING OR WE CANT ATTACK THE NPC <- our condition true? stop sleeping :false sleep until 2000ms } }.sleep(); } } /// else we sleep the looptime. return 600; } | https://osbot.org/api/org/osbot/rs07/api/filter/Filter.html https://osbot.org/api/org/osbot/rs07/api/model/Character.html https://osbot.org/api/org/osbot/rs07/api/Combat.html https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html
June 23, 20178 yr 1 minute ago, Chris said: just use onLoop bro @Override public int onLoop() throws InterruptedException { if (!getCombat().isFighting() || myPlayer().getInteracting() == null){ //if not fighting or get interacting does not exist //NPC npc = getNpcs().closest("Chicken"); basic NPC npc = getNpcs().closest(new Filter<NPC>() { //filter api @Override public boolean match(NPC npc) { return npc.hasAction("Attack") && npc.getName().equals("Chicken") && npc.getHealthPercent() > 0 && npc.getInteracting() == null; } }); if (npc != null && npc.interact("Attack")) { new ConditionalSleep(2000) { //timout time. once 2000ms passes it will stop @Override public boolean condition() throws InterruptedException { return getCombat().isFighting() || !npc.isAttackable(); //sleep until WE ARE FIGHTING OR WE CANT ATTACK THE NPC <- our condition true? stop sleeping :false sleep until 2000ms } }.sleep(); } } /// else we sleep the looptime. return 600; } | https://osbot.org/api/org/osbot/rs07/api/filter/Filter.html https://osbot.org/api/org/osbot/rs07/api/model/Character.html https://osbot.org/api/org/osbot/rs07/api/Combat.html https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html How're we going to piss off @Explv if we do that Edited June 23, 20178 yr by HeyImJamie
June 23, 20178 yr 28 minutes ago, MySQLi said: Hey guys, I'm trying to learn Java, and script writing. I've been reading some tutorials and I just wrote this SUPER basic first script, however, it does NOTHING. I'm wondering if anyone can tell me where I went wrong, and why it does not attack "Chickens"
June 23, 20178 yr Author Thanks guys, I now have a basic chicken killer script running, I will now use this to build off and learn, appreciate the help!