opafmoremedic Posted August 26, 2020 Share Posted August 26, 2020 Hey, everyone. For starters, I'm brand new and started writing scripts today actually. I followed a very basic tutorial on this website that gave me a scripting backbone and showed me the basics. I've since been learning and scouring all sorts of forums and attempting to make a simple tree chopping script. I want the bot to chop a tree, drop the logs, chop another tree, etc. However, the bot keeps clicking multiple times while running to the tree. I attempted a sleep while moving, but it would still click a second time as it got to the tree. I tried to sleep while animating but there's still a split second in between animation and moving. I don't want to extend the sleep an overwhelming amount of time because then it'll slow down the chopping trees that are close. I was thinking, is there a line of code that would allow the player to only click once until the action is completed? This is my code, sorry if this is a dumb question. Quote Link to comment Share on other sites More sharing options...
Nbacon Posted August 26, 2020 Share Posted August 26, 2020 (edited) hello opafmoremedic. Yes there is. [This is a common question that has been asked be for many times but don't let that discourage you for asking it] Look in to conditonal sleep and changing your random(200,300) a tic is 600 ms so up it to like (1000,1500). This same question about spaming trees (later in the post). TLDR; if( (!(myPlayer().isAnimating() || myPlayer().isMoving() || tree == null) && tree.interact("Chop down")))){ Sleep.sleepUntil(()->myPlayer().isAnimating(),4000,300); } But Look at this there is alot of good info and a youtube video Edited August 26, 2020 by Nbacon 2 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted August 26, 2020 Share Posted August 26, 2020 1 hour ago, opafmoremedic said: Hey, everyone. For starters, I'm brand new and started writing scripts today actually. I followed a very basic tutorial on this website that gave me a scripting backbone and showed me the basics. I've since been learning and scouring all sorts of forums and attempting to make a simple tree chopping script. I want the bot to chop a tree, drop the logs, chop another tree, etc. However, the bot keeps clicking multiple times while running to the tree. I attempted a sleep while moving, but it would still click a second time as it got to the tree. I tried to sleep while animating but there's still a split second in between animation and moving. I don't want to extend the sleep an overwhelming amount of time because then it'll slow down the chopping trees that are close. I was thinking, is there a line of code that would allow the player to only click once until the action is completed? This is my code, sorry if this is a dumb question. All you need is this mate You need to make use of your onLoop, No need to do multiple actions in 1 onLoop cycle ^^ if (getInventory().contains("Logs")) { getInventory().drop("Logs"); } else { if (!myPlayer().isAnimating()) { RS2Object tree = getObjects().closest("Tree"); if (tree != null) { if (tree.interact("Chop down")) { new ConditionalSleep(random(4000, 5000)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { //No Valid Tree Found } } else { //Do nothing, We are Chopping, Just wait ... } } 2 Quote Link to comment Share on other sites More sharing options...
opafmoremedic Posted August 26, 2020 Author Share Posted August 26, 2020 @Khaleesi Thanks a lot for the response, I'm having a bit of trouble though (the script works great btw). This code pretty much says, if I understand correctly, if my player isn't animating, search for the closest tree. If there's a closest tree, click chop down. If you click chop down, go to sleep for anywhere from 4-5 seconds. After that I get lost. I don't understand this part. 10 hours ago, Khaleesi said: @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); Could you possibly explain these? @NBacon Thanks a lot for the response, I've bookmarked all of the pages you linked me too and read through the previous forum that had this same issue. It looks like he used the same tutorial I did, based on what he has written. Thanks for going into so much detail and explain the && more clearly! Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted August 27, 2020 Share Posted August 27, 2020 (edited) 11 hours ago, opafmoremedic said: @Khaleesi Thanks a lot for the response, I'm having a bit of trouble though (the script works great btw). This code pretty much says, if I understand correctly, if my player isn't animating, search for the closest tree. If there's a closest tree, click chop down. If you click chop down, go to sleep for anywhere from 4-5 seconds. After that I get lost. I don't understand this part. Could you possibly explain these? @NBacon Thanks a lot for the response, I've bookmarked all of the pages you linked me too and read through the previous forum that had this same issue. It looks like he used the same tutorial I did, based on what he has written. Thanks for going into so much detail and explain the && more clearly! It's means it should sleep for max 4-5 seconds OR stop the sleep when the player is animating That's a conditionalsleep, it sleep until the condition is met or until the time is up ^^ it is to prevent spamm clicking the tree after clicking it Edited August 27, 2020 by Khaleesi Quote Link to comment Share on other sites More sharing options...