allomaxis Posted June 5, 2015 Share Posted June 5, 2015 (edited) I've been learning to script for a couple of days now and I've written a script to string magic longbows. I haven't ran it yet because I've had problems getting it to show up on the client. It showed up once, ran it, there was a bug, fixed it, but now it won't show up on the client again. Not that I can do much about anyway, since mirror mode isn't working due to the update. Anyway, here is my script: package stringer; import org.osbot.rs07.script.Script; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Me", info = "Magic bow stringer", name = "fletcher", version = 0.1, logo = "") public class Main_stringer extends Script { final private String unfBow = "Magic longbow (u)"; final private String bowString = "Bow string"; @Override public void onStart() { log("Starting script..."); } @Override public int onLoop() { if( !bank.isOpen() && !inventory.contains(unfBow) && !inventory.contains(bowString) ) { log("Opening bank..."); openBank(); return random(700, 1400); } if( bank.isOpen() && inventory.contains("Magic longbow") && !inventory.contains(unfBow) && !inventory.contains(bowString) ) { log("Depositing..."); deposit(); return random(700, 1400); } if( inventory.isEmpty() && bank.isOpen() ) { log("Withdrawing..."); withdraw(); return random(700, 1400); } if( inventory.contains(unfBow) && inventory.contains(bowString) && !bank.isOpen() ) { log("Stringing bows..."); stringBows(); while( myPlayer().isAnimating() ) { //empty loop } return random(700, 1000); } log("Done goofed."); return random(700, 1200); } @Override public void onExit() { log("Exiting"); } @Override public void onPaint(Graphics2D g) { } public void openBank() { RS2Object bankBooth = objects.closest("Bank booth"); bankBooth.interact("Bank"); } public void deposit() { bank.depositAll(); } public void withdraw() { bank.withdraw(unfBow, 14); Sleep( random(300, 500) ); bank.withdraw(bowString, 14); Sleep( random(300, 500) ); bank.close(); } public void stringBows() { inventory.interact("Use", unfBow); Sleep( random(300, 600) ); inventory.interact("Use", bowString); RS2Widget widget = widgets.get(309, 2); while( !widget.isVisible() ) { //empty loop } Sleep( random(200, 400) ); widget.interact("Make All"); } public void Sleep(int ms) { try { sleep(ms); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } } } What do you guys think? Am i doing anything wrong? Edited June 5, 2015 by allomaxis Quote Link to comment Share on other sites More sharing options...
Novak Posted June 5, 2015 Share Posted June 5, 2015 try to avoid having like 99999 if statements in your loop. look into a stateful framework Quote Link to comment Share on other sites More sharing options...
Volta Posted June 5, 2015 Share Posted June 5, 2015 try to avoid having like 99999 if statements in your loop. look into a stateful framework y 1 Quote Link to comment Share on other sites More sharing options...
allomaxis Posted June 5, 2015 Author Share Posted June 5, 2015 (edited) try to avoid having like 99999 if statements in your loop. look into a stateful framework Better? package stringer; import org.osbot.rs07.script.Script; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "Me", info = "Magic bow stringer", name = "fletcher", version = 0.1, logo = "") public class Main_stringer extends Script { final private String unfBow = "Magic longbow (u)"; final private String bowString = "Bow string"; private enum State { BANK, DEPOSIT, WITHDRAW, STRING }; @Override public void onStart() { log("Starting script..."); } @Override public void onExit() { log("Exiting"); } @Override public void onPaint(Graphics2D g) { } @Override public int onLoop() { switch() { case BANK: log("Opening bank..."); openBank(); return random(700, 1400); break; case DEPOSIT: log("Depositing..."); deposit(); return random(700, 1400); break; case WITHDRAW: log("Withdrawing..."); withdraw(); return random(700, 1400); break; case STRING: log("Stringing bows..."); stringBows(); while( myPlayer().isAnimating() ) { //empty loop } return random(700, 1000); break; } log("Done goofed."); return random(700, 1200); } private State getState() { if( !bank.isOpen() && !inventory.contains(unfBow) && !inventory.contains(bowString) ) { return State.BANK; } if( bank.isOpen() && inventory.contains("Magic longbow") && !inventory.contains(unfBow) && !inventory.contains(bowString) ) { return State.DEPOSIT; } if( inventory.isEmpty() && bank.isOpen() ) { return State.WITHDRAW; } if( inventory.contains(unfBow) && inventory.contains(bowString) && !bank.isOpen() ) { return State.STRING; } } public void openBank() { RS2Object bankBooth = objects.closest("Bank booth"); bankBooth.interact("Bank"); } public void deposit() { bank.depositAll(); } public void withdraw() { bank.withdraw(unfBow, 14); Sleep( random(300, 500) ); bank.withdraw(bowString, 14); Sleep( random(300, 500) ); bank.close(); } public void stringBows() { inventory.interact("Use", unfBow); Sleep( random(300, 600) ); inventory.interact("Use", bowString); RS2Widget widget = widgets.get(309, 2); while( !widget.isVisible() ) { //empty loop } Sleep( random(200, 400) ); widget.interact("Make All"); } public void Sleep(int ms) { try { sleep(ms); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } } } Edited June 5, 2015 by allomaxis Quote Link to comment Share on other sites More sharing options...
Novak Posted June 5, 2015 Share Posted June 5, 2015 much Quote Link to comment Share on other sites More sharing options...
Cooper1992 Posted June 5, 2015 Share Posted June 5, 2015 Good job. Quote Link to comment Share on other sites More sharing options...
ProjectPact Posted June 5, 2015 Share Posted June 5, 2015 If statements to the max hahahaha try using switch statements instead for a cleaner look with enums Quote Link to comment Share on other sites More sharing options...