Jump to content

Only click once until log is harvested


opafmoremedic

Recommended Posts

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.

image.png.65c4601db61ef5b9ac54ed0a47eea8dc.png

 

Link to comment
Share on other sites

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 by Nbacon
  • Like 2
Link to comment
Share on other sites

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.

image.png.65c4601db61ef5b9ac54ed0a47eea8dc.png

 

All you need is this mate :D
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 ...
            }
        }

 

  • Like 2
Link to comment
Share on other sites

@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!

Link to comment
Share on other sites

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 by Khaleesi
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...