hajar424 Posted July 13, 2015 Share Posted July 13, 2015 (edited) My Al kharid warrior bot wont start, can anyone help me? import org.osbot.rs07.script.ScriptManifest; import java.awt.*; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.script.Script; import org.osbot.rs07.utility.Area; import javax.imageio.ImageIO; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.concurrent.TimeUnit; // Manifest @ScriptManifest(author = "Hajar424", info = "Kills Al Kharid Warrior", name = "AL Kharid Warrior", version = 1.18 , logo = "http://i.imgur.com/rYghTrD.png") public class main extends Script implements org.osbot.rs07.canvas.paint.Painter { private ArrayList alist = new ArrayList<String>(); //Variables private final Image bg = getImage("http://i.imgur.com/5ai2EYf.png"); private long timeBegan; private long timeRan; private int ATTcurrentLevel; private int ATTbeginningLevel; private int STRcurrentLevel; private int STRbeginningLevel; private int DEFcurrentLevel; private int DEFbeginningLevel; private int RANcurrentLevel; private int RANbeginningLevel; private int levelsGained; private int warrior_id = 3103; NPC warrior = npcs.closest(warrior_id); //Path private Position[] toWarrior = {new Position(3295,3171,0)}; //Areas private final Area door_area = new Area(3282,3177,3303,3167); private final Area warrior_area = new Area(3282,3177,3303,3167); private final Area bank_area = new Area(3272,3173,3269,3161); //Random Path public static Position[] getRandomPath(Position[] path, int radius){Position[] newPath = new Position[path.length];int idx = 0;for( Position node : path) newPath[idx++] = node.translate(MethodProvider.random(radius), MethodProvider.random(radius));return newPath;} //onLoop @Override public int onLoop() throws InterruptedException { switch (getState()) { case killWarrior: killMethod(); break; case banking: bankingMethod(); break; case walk_bank: walk_bankMethod(); break; case walk_warrior: walk_warriorMethod(); break; default:break; } return (0); } // OnStart @Override public void onStart() { ATTbeginningLevel = skills.getStatic(Skill.ATTACK); STRbeginningLevel = skills.getStatic(Skill.STRENGTH); DEFbeginningLevel = skills.getStatic(Skill.DEFENCE); RANbeginningLevel = skills.getStatic(Skill.RANGED); timeBegan = System.currentTimeMillis(); experienceTracker.startAll(); } private enum State { killWarrior, banking, walk_bank, walk_warrior, idle } private State getState() { if(!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.killWarrior; } else if (!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.banking; } else if (!bank_area.contains(myPlayer())) return State.walk_bank; else if (myPlayer().isAnimating() && myPlayer().getInteracting() != null) { return State.walk_warrior; } return (State.idle); } private void bankingMethod() throws InterruptedException { } // -----------Methods------------ public void killMethod() throws InterruptedException { NPC warrior = npcs.closest(warrior_id); if( !myPlayer().isMoving() && !myPlayer().isUnderAttack() && !inventory.isFull() && !doorHandler.handleNextObstacle(door_area)) { if(warrior != null && warrior.isAttackable() && warrior.isOnScreen() ) { warrior.interact("Attack"); } } else { camera.toEntity(warrior); } } private void walk_warriorMethod() throws InterruptedException { } private void walk_bankMethod() throws InterruptedException { } @Override public void onPaint(Graphics2D g) { //THEME g.setColor(new Color(25, 25, 25, 150)); g.fillRect(7, 345, 516, 320); g.setColor(new Color(255, 244, 243, 170)); g.setFont(new Font("Arial", Font.BOLD, 14)); g.fillRect(0, 325, 520, 20); //NAME OF THE BOT g.setColor(new Color(0, 0, 0)); g.setFont(new Font("Arial", Font.BOLD, 14)); g.drawString("AL KHARID WARRIOR", 10, 338); // XP tracker g.setColor(new Color(255, 255, 255)); g.setFont(new Font("Arial", Font.BOLD, 10)); g.drawString("Attack: " + experienceTracker.getGainedXP(Skill.ATTACK) + " Xp", 10, 364); g.drawString("Strength: " + experienceTracker.getGainedXP(Skill.STRENGTH) + " Xp", 10, 384); g.drawString("Defence: " + experienceTracker.getGainedXP(Skill.DEFENCE) + " Xp", 10, 404); g.drawString("Range: " + experienceTracker.getGainedXP(Skill.RANGED) + " Xp", 10, 424); // combat lvl ATTcurrentLevel = skills.getStatic(Skill.ATTACK); g.drawString("| LVL: " + ATTbeginningLevel+"/"+ATTcurrentLevel, 120,364); STRcurrentLevel = skills.getStatic(Skill.STRENGTH); g.drawString("| LVL: " + STRbeginningLevel+"/"+STRcurrentLevel, 120,384); DEFcurrentLevel = skills.getStatic(Skill.DEFENCE); g.drawString("| LVL:" + DEFbeginningLevel+"/"+DEFcurrentLevel, 120,404); RANcurrentLevel = skills.getStatic(Skill.RANGED); g.drawString("| LVL:" + RANbeginningLevel + "/" + RANcurrentLevel, 120, 424); // Paint time and xp per hour g.setFont(new Font("Arial", Font.BOLD, 12)); timeRan = System.currentTimeMillis() - this.timeBegan; g.drawString("[ Time: "+ft(timeRan)+" ]",10,444 ); String myskill = "STRENGTH"; g.drawString("Xp/Hour: " + experienceTracker.getGainedXPPerHour(Skill.forName(myskill)) + " Xp" , 120, 444); g.drawImage(bg, 397, 364, null); } //Image private Image getImage(String url) {try {return ImageIO.read(new URL(url));} catch (IOException e) {}return null; } //Time private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) {res = (hours + ":" + minutes + ":" + seconds); }else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } } Edited July 13, 2015 by hajar424 Quote Link to comment Share on other sites More sharing options...
Joseph Posted July 14, 2015 Share Posted July 14, 2015 any error log? Quote Link to comment Share on other sites More sharing options...
Precise Posted July 14, 2015 Share Posted July 14, 2015 what is happening exactly? your getState isnt efficient at all and will cause you issues. private State getState() { if(!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.killWarrior; } else if (!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.banking; } else if (!bank_area.contains(myPlayer())) return State.walk_bank; else if (myPlayer().isAnimating() && myPlayer().getInteracting() != null) { return State.walk_warrior; } return (State.idle); } have a read through this, you first if and else if statements are exactly the same yet return different states and some of it doesn't really make sense at all. do something like this: private State getState() { if(/*doesnt need to bank*/) { if(warrior != null) { if(myPlayer().getInteracting() == null && !myPlayer().isUnderAttack()) return State.killWarrior; else return State.idle; } else { return State.walk_warrior; } } else if(/* at bank*/) { //return bank } else { return State.walk_bank; } } Quote Link to comment Share on other sites More sharing options...
hajar424 Posted July 14, 2015 Author Share Posted July 14, 2015 (edited) any error log? ERROR][07/14 02:16:25 fm]: Failed to start script [AL Kharid Warrior] java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.osbot.auX.run(to:583) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at main.<init>(main.java:41) ... 8 more what is happening exactly? your getState isnt efficient at all and will cause you issues. private State getState() { if(!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.killWarrior; } else if (!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && warrior != null) { return State.banking; } else if (!bank_area.contains(myPlayer())) return State.walk_bank; else if (myPlayer().isAnimating() && myPlayer().getInteracting() != null) { return State.walk_warrior; } return (State.idle); } have a read through this, you first if and else if statements are exactly the same yet return different states and some of it doesn't really make sense at all. do something like this: private State getState() { if(/*doesnt need to bank*/) { if(warrior != null) { if(myPlayer().getInteracting() == null && !myPlayer().isUnderAttack()) return State.killWarrior; else return State.idle; } else { return State.walk_warrior; } } else if(/* at bank*/) { //return bank } else { return State.walk_bank; } } one question what should getstate return ? Edited July 14, 2015 by hajar424 Quote Link to comment Share on other sites More sharing options...