hellkeepers Posted November 12, 2014 Share Posted November 12, 2014 (edited) Hello osbot community, I've recently made an attempt at creating a script for osbot but i've had some problems; Im trying to recreate a thieving script (Master farmer) But im having some issues with using food >It detects if my hp is below 45% >eats one piece of food **Starts dropping all items while inventory isn't full** I just need some advice on how to write it the good way im still in the proccess of learning so any piece of information is welcome. **Also what i noticed that npcs.getclosest Laggs extremely badd is there a way arround that? **And how should i improve the Npc clicking /timing? /////////////////////////////////////// private enum State { STEAL, DROP, EAT, IDLE }; /////////////////////////////// private State getState() { if(myPlayer().getHealth() <45){ return State.EAT; } if (inventory.isFull()) return State.DROP; return State.STEAL; } //////////////////////////////////// @Override public void onStart() { log("Let's thief!"); } //////////////////////////////////////////////////// @Override public int onLoop() throws InterruptedException { switch (getState()) { case STEAL: if (!myPlayer().isAnimating()) { NPC farm = npcs.closest("Master farmer"); if(farm != null){ farm.interact("pickpocket"); } } break; case EAT: if(inventory.contains("Pike")){ inventory.getItem("Pike").interact("Eat"); } case DROP: inventory.dropAll(); break; case IDLE: sleep(200); break; default: break; } return random(200, 300); } //////////////////////////////////////////// @Override public void onExit() { log("Thanks for running my script."); } @Override public void onPaint(Graphics2D g) { } } Edited November 12, 2014 by hellkeepers Link to comment Share on other sites More sharing options...
hellkeepers Posted November 12, 2014 Author Share Posted November 12, 2014 Wait people still script here??? Atleast attempting to... trying to learn it. Link to comment Share on other sites More sharing options...
Eliot Posted November 12, 2014 Share Posted November 12, 2014 So is it not eating? What is the problem? Link to comment Share on other sites More sharing options...
hellkeepers Posted November 12, 2014 Author Share Posted November 12, 2014 problem is ; It does eats, But after that it starts dropping all items from my invent. Link to comment Share on other sites More sharing options...
Eliot Posted November 12, 2014 Share Posted November 12, 2014 problem is ; It does eats, But after that it starts dropping all items from my invent. That's because you don't have a break; statement after the end of the EAT state so your program is falling through into the DROP state. Fix: case EAT: if(inventory.contains("Pike")){ inventory.getItem("Pike").interact("Eat"); } break; 1 Link to comment Share on other sites More sharing options...
Dog_ Posted November 13, 2014 Share Posted November 13, 2014 (edited) Hello osbot community, I've recently made an attempt at creating a script for osbot but i've had some problems; Im trying to recreate a thieving script (Master farmer) But im having some issues with using food >It detects if my hp is below 45% >eats one piece of food **Starts dropping all items while inventory isn't full** I just need some advice on how to write it the good way im still in the proccess of learning so any piece of information is welcome. **Also what i noticed that npcs.getclosest Laggs extremely badd is there a way arround that? **And how should i improve the Npc clicking /timing? *CODE* Another point of interest is the break statement. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered. The program SwitchDemoFallThrough shows statements in a switch block that fall through. The program displays the month corresponding to the integer month and the months that follow in the year: public class SwitchDemoFallThrough { public static void main(String[] args) { java.util.ArrayList<String> futureMonths = new java.util.ArrayList<String>(); int month = 8; switch (month) { case 1: futureMonths.add("January"); case 2: futureMonths.add("February"); case 3: futureMonths.add("March"); case 4: futureMonths.add("April"); case 5: futureMonths.add("May"); case 6: futureMonths.add("June"); case 7: futureMonths.add("July"); case 8: futureMonths.add("August"); case 9: futureMonths.add("September"); case 10: futureMonths.add("October"); case 11: futureMonths.add("November"); case 12: futureMonths.add("December"); break; default: break; } if (futureMonths.isEmpty()) { System.out.println("Invalid month number"); } else { for (String monthName : futureMonths) { System.out.println(monthName); } } } } For more, see https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html Edited November 13, 2014 by dog_ Link to comment Share on other sites More sharing options...