GamerNation101 Posted September 2, 2019 Share Posted September 2, 2019 Hi, this is my first post. I've had no experience with coding but I gave it a go. I tried to write a script that works in my logic, and it does, kinda. I know that it is messy. I'm looking for guidance on how to improve the script because the main reason being after about 5 seconds of it loading it starts to lag a whole lot from a certain point. package FisherPack; import java.awt.Graphics2D; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Cal", info = "fisher", name = "Fisher", version = 0, logo = "") public class CalsFish extends Script { private int animateChange; private int getNet; @Override public void onStart() { animateChange = 0; log("Let's get started!"); } @Override public int onLoop() throws InterruptedException { ////////////////////////////////////////////////////////////////////////////////////////////////////////// if (getInventory().contains("Small fishing net")) { getNet = 2; } if (inventory.isEmpty()) { animateChange = 10; getNet = 1; } while (((getInventory().contains("Raw shrimps")) || (getInventory().contains("Raw anchovies"))) && (animateChange == 0)){ objects.closest("Cooking range").interact("Cook"); sleep(2000); widgets.interact(270, 14, "Cook"); if (myPlayer().isAnimating()) { animateChange = animateChange + 1; log(animateChange); log("animate Change"); //Sees if any raw anch or shrimp and cooks them } if (!myPlayer().isAnimating()) { animateChange = 0; //ill need to put this at end also sleep(100); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// if ((getInventory().contains("Shrimps")) || (getInventory().contains("Anchovies"))){ if ((!getInventory().contains("Raw shrimps")) || (!getInventory().contains("Raw anchovies"))){ } walking.webWalk(new Position(3208,3218,2)); sleep(random(100,500)); objects.closest("Bank booth").interact("Bank"); sleep(random(991,2873)); //when cook complete go and bank all widgets.interact(12, 42, "Deposit inventory"); sleep(random(798,981)); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (getNet == 1) { walking.webWalk(new Position(3208,3218,2)); sleep(random(100,500)); //walk to bank for net if none objects.closest("Bank booth").interact("Bank"); sleep(random(1289,2101)); bank.withdraw("Small fishing net", 1); sleep(random(867,1245)); walking.webWalk(new Position(3242,3154,0)); sleep(random(100,498)); getNet = 0; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// bank.withdraw("Small fishing net", 1); sleep(random(867,1245)); //withdraw net walking.webWalk(new Position(3242,3154,0)); sleep(random(100,498)); /////////////////////////////////////////////////////////////////////////////////////////////////////////// //fishing begins here if (getNet == 2) { walking.webWalk(new Position(3241,3152,0)); //if start with fish net sleep(random(809,1109)); getNet = 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// npcs.closest(1530).interact("Net"); sleep(random(2003,3001)); while (myPlayer().isAnimating()){ sleep(random(3506,5007)); } if ((!myPlayer().isAnimating()) && (!inventory.isFull())) { npcs.closest(1530).interact("Net"); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// return random(500, 1000); } @Override public void onExit() { log("Thanks for running my Tree Cutter!"); } @Override public void onPaint(Graphics2D g) { } } Quote Link to comment Share on other sites More sharing options...
FuryShark Posted September 2, 2019 Share Posted September 2, 2019 Tried pming you but it doesnt seem to work. Do you have discord? Quote Link to comment Share on other sites More sharing options...
GamerNation101 Posted September 2, 2019 Author Share Posted September 2, 2019 Cal #7354 Quote Link to comment Share on other sites More sharing options...
ihom Posted September 10, 2019 Share Posted September 10, 2019 Breaking your above code out into functions will allow for ease and better coding practise.. Also get rid of your "sleep"s & "while"s and look into conditional sleeps, feel free to add me on discord Quote Link to comment Share on other sites More sharing options...
ThoughtVNC Posted September 11, 2019 Share Posted September 11, 2019 "Thanks for running my Tree Cutter!" what tutorial did you pull this from... ^^this guys spot on 1 Quote Link to comment Share on other sites More sharing options...