Jump to content

Explv's Scripting 101


Explv

Recommended Posts

  • 4 weeks later...
  • 2 weeks later...
On 5/26/2018 at 12:31 PM, shaba123 said:

Thanks a lot for this, really helpful.

Will you be expanding on the GUI section at any point? or can you point me to a tutorial you think is useful for GUI's?

 

 


Finished off the GUI section. Still not happy with it (don't think it is very tidy or well explained) but it is better than it was before.

I may revisit again in the future.

  • Heart 1
Link to comment
Share on other sites

  • 2 weeks later...

I know there haven't been many posts to this recently. I was just running through the tutorial to see if I could get a script working (using Explv's pre-made script), then was going to delve into trying my own. How do you get the script to show up within OSBot's possible scripts to run? I'm using a mac so I created an artifact and put it into the correct file structure from step 2 I believe it is. Then step 3 mentions building the artifact and then refreshing the script list and it should be there. Are there any steps that I'm missing? Thanks for the help and awesome guide!

Link to comment
Share on other sites

  • 3 weeks later...
Entity tree = getObjects().closest("Tree");
if (tree != null && tree.interact("Chop down")) {
      new ConditionalSleep(5000) {
        @Override
        public boolean condition() {
            return myPlayer().isAnimating() || !tree.exists();
        }
    }.sleep();
}

New to OSBot, but not new to Java. I was following through your tutorial, and I am curious about your sleep condition in this snippet. Why do we want to stop sleeping if myPlayer is animating. Maybe I do not understand what that method will return, but my naive assumption is that myPlayer is animating while in the act of "chopping". It seems to me that this wouldn't sleep at all as it would meet the condition upon either "chopping" or walking to the next tree. Your thoughts on this would be much appreciated :) Thank you for an awesome guide.

Edited by JaguarKnight
Link to comment
Share on other sites

30 minutes ago, JaguarKnight said:

Entity tree = getObjects().closest("Tree");
if (tree != null && tree.interact("Chop down")) {
      new ConditionalSleep(5000) {
        @Override
        public boolean condition() {
            return myPlayer().isAnimating() || !tree.exists();
        }
    }.sleep();
}

New to OSBot, but not new to Java. I was following through your tutorial, and I am curious about your sleep condition in this snippet. Why do we want to stop sleeping if myPlayer is animating. Maybe I do not understand what that method will return, but my naive assumption is that myPlayer is animating while in the act of "chopping". It seems to me that this wouldn't sleep at all as it would meet the condition upon either "chopping" or walking to the next tree. Your thoughts on this would be much appreciated :) Thank you for an awesome guide.


Walking != animating

Once the player clicks the tree, this sleep will sleep until the player starts chopping the tree, or until the tree no longer exists, or until 5 seconds has passed.

You would want to check if the player is chopping a tree (animating) first:
 

if (!myPlayer().isAnimating()) { // If the player is not chopping a Tree
    Entity tree = getObjects().closest("Tree"); // Get the closest Tree
    if (tree != null && tree.interact("Chop down")) { // If the "Chop down" interaction is successful
        new ConditionalSleep(5000) { // Sleep for 5 seconds, or until the player is animating (chopping the tree), or until the tree no longer exists (someone else chopped it down)
            @Override
            public boolean condition() {
                return myPlayer().isAnimating() || !tree.exists();
            }
        }.sleep();
    }
}


You could also write this in a different way, by having a very long sleep:

if (!myPlayer().isAnimating()) { // If the player is not chopping a Tree
    Entity tree = getObjects().closest("Tree"); // Get the closest Tree
    if (tree != null && tree.interact("Chop down")) { // If the "Chop down" interaction is successful
        new ConditionalSleep(90_000, 600) { // Sleep for 90 seconds, or until the tree no longer exists, checking if the tree exists at 600ms intervals
            @Override
            public boolean condition() {
                return !tree.exists();
            }
        }.sleep();
    }
}


 

Edited by Explv
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hey Explv! Thank you for your tuts, you're a shining light in the dark, especially for brainlets like me. 

On that note, if anyone else was having trouble with your gui, (I was getting this since the recent 2.5.24 update: "Cannot call invokeAndWait from the event dispatcher thread" ), on a guess I just removed the try/catch blocks, and it turns out this is all you need: 

(doing this is probably very wrong, I'm no one to learn from, but if you need your code to work, this solution may help, it did for me) Cheers!

In your main class:

private GUI gui = new GUI();


In onStart:

gui = new GUI();
gui.open();

if (!gui.isStarted()) {
    stop();
    return;
}
Edited by someguy69
Removed sentence fragments
Link to comment
Share on other sites

  • 3 months later...

So I've been working on this Oak larder project for a bit now and I'm wondering where I would go from here: 

@Override
	public void onStart() {
		log("Welcome to Simple larders! Let's get started.");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
	
		Entity larder_space = getObjects().closest("Larder space");
		if (larder_space != null && larder_space.interact("Build")) {
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() {
					return !larder_space.exists();  // Not sure I'm using this right either 
					}
				}.sleep();
		}
	return 1000;
	}

		

	@Override
	public void onExit() {
		log("Thanks for using Simple larders!");
	}
}

Now that I got the bot interacting with the "Larder space" and clicking "Build" I'm trying to get it to interact with the widget: 

RS2Widget widget = widgets.get(458, 5, 4);

Which is the "Oak larder" icon but I'm having trouble on implementing this so it flows step by step.

My plans for the bot are too: 

// 0. Make sure your in front of "Larder space" in build mode before starting.
	// 1.Make bot check inventory to see if "Oak planks" exist.
	// 2.If true, "Build" the "Larder space"
	// 3."Remove" the "Larder" and repeat till > 5 "Oak planks"
	// 4.If > 5 then call butler to un-note "Oak planks" 
	// 5.Wait for butler to get back with "Oak planks"
	// 6.Repeat 

You're tutorials helping a lot but some tips or a push in the right direction from someone that knows what they're talking about would be great!

 

 

Edited by Imthabawse
Link to comment
Share on other sites

  • 2 months later...

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...