Jump to content

A Beginners Guide to Writing OSBot Scripts (where to get started!) by Apaec


Apaec

Recommended Posts

15 hours ago, ReaperScripts said:

I'm missing the .setting section of the project

Does anyone know how to fix this?

I had the same issue, but it seems it's not a problem at all, might just be because his pictures were created from a while back, updates may have changed it. Just try running it and it should be fine.

I am confused about one thing though, why when I drop each cup of tea as it appears in my inventory it right clicks and presses drop, yet if I change that section to 
if (getInventory().isFull()) { //Checks if inventory is full
            getInventory().dropAll("Cup of Tea"); // drops all cups of tea
It just shift clicks them (the more optimal setting if turned on), I was wondering how to make this the general option for even just dropping one.

 

EDIT

Sorted this out by just changing the one that drops them as soon as they appear in your inventory to also dropAll("Cup of Tea") and then it shift click drops them, I'm actually so slow lmao. I guess dropAll > drop xddd

However on another note I'm trying to make a 3rd version of the tea script that banks, I've got it to locate the nearest bank and open the bank booth 

    @Override
    public int onLoop() throws InterruptedException {
        RS2Object stall = getObjects().closest("Tea Stall"); //Checks for nearest tea stall to player location
        if (getInventory().isFull()) { //Checks invo for cup of tea
            RS2Object bank = getObjects().closest("Bank booth"); // Checks for nearest bank booth
            bank.interact("Bank"); //Opens the banking interface
            
            sleep(500); //if invo contains cup of tea and proceeds to drop it then after this sleeps for 0.5s
            
        } else if (stall != null && !myPlayer().isAnimating()) { //if no tea in invo checks if player is animating
            stall.interact("Steal-from"); // if player ins't animating steals from the stall
            sleep(500); //After stealing from stall sleeps for 0.5s before looping to start of script
        }
        return random(200, 300);
    }

Just unsure how to actually either right click and deposit all the "Cup of Tea"s or how to click deposit inventory button. Any help would be greatly appreciated. (On a side note, sorry for my code not having colours in here, I'm not sure how to do that, I just copy and pasted it)

Edited by LostOtaku
Link to comment
Share on other sites

1 hour ago, LostOtaku said:

I had the same issue, but it seems it's not a problem at all, might just be because his pictures were created from a while back, updates may have changed it. Just try running it and it should be fine.

I am confused about one thing though, why when I drop each cup of tea as it appears in my inventory it right clicks and presses drop, yet if I change that section to 
if (getInventory().isFull()) { //Checks if inventory is full
            getInventory().dropAll("Cup of Tea"); // drops all cups of tea
It just shift clicks them (the more optimal setting if turned on), I was wondering how to make this the general option for even just dropping one.

 

EDIT

Sorted this out by just changing the one that drops them as soon as they appear in your inventory to also dropAll("Cup of Tea") and then it shift click drops them, I'm actually so slow lmao. I guess dropAll > drop xddd

However on another note I'm trying to make a 3rd version of the tea script that banks, I've got it to locate the nearest bank and open the bank booth 

    @Override
    public int onLoop() throws InterruptedException {
        RS2Object stall = getObjects().closest("Tea Stall"); //Checks for nearest tea stall to player location
        if (getInventory().isFull()) { //Checks invo for cup of tea
            RS2Object bank = getObjects().closest("Bank booth"); // Checks for nearest bank booth
            bank.interact("Bank"); //Opens the banking interface
            
            sleep(500); //if invo contains cup of tea and proceeds to drop it then after this sleeps for 0.5s
            
        } else if (stall != null && !myPlayer().isAnimating()) { //if no tea in invo checks if player is animating
            stall.interact("Steal-from"); // if player ins't animating steals from the stall
            sleep(500); //After stealing from stall sleeps for 0.5s before looping to start of script
        }
        return random(200, 300);
    }

Just unsure how to actually either right click and deposit all the "Cup of Tea"s or how to click deposit inventory button. Any help would be greatly appreciated. (On a side note, sorry for my code not having colours in here, I'm not sure how to do that, I just copy and pasted it)

Glad you got the dropping sorted! Although it is weird that just calling 'drop' doesn't shift drop as well..

As for banking, you would want to use the banking API:

https://osbot.org/api/org/osbot/rs07/api/Bank.html

Try something like

getBank().depositAll();

gl!

Apa

Link to comment
Share on other sites

On 12/15/2018 at 4:15 PM, Apaec said:

Glad you got the dropping sorted! Although it is weird that just calling 'drop' doesn't shift drop as well..

As for banking, you would want to use the banking API:

https://osbot.org/api/org/osbot/rs07/api/Bank.html

Try something like


getBank().depositAll();

gl!

Apa

Worked perfectly with what I had thanks, I also managed to play around with that line and get it deposit certain items etc. was lots of fun~

On another note would it be possible for you to create a WindowBuilder GUI tutorial? I've been trying for the last day using various tutorials on this website and nobody seems to lay out EVERY step (for someone like me with no brain xd) like you did in your tutorial here, which allowed me to learn SO much about different lines and how to improve this singular script in various ways. You have anything that would be useful, I've managed to create a GUI with a drop down list and a start button, but unsure how to either link my scripts to the various drop down lists or whatever I'm suppose to do. It would be incredibly useful if my list could for example like fetch said option (if I have each separate option as a different .class). Not sure if I'm looking at this the wrong way or what.

  • Like 1
Link to comment
Share on other sites

On 12/16/2018 at 6:43 PM, LostOtaku said:

Worked perfectly with what I had thanks, I also managed to play around with that line and get it deposit certain items etc. was lots of fun~

On another note would it be possible for you to create a WindowBuilder GUI tutorial? I've been trying for the last day using various tutorials on this website and nobody seems to lay out EVERY step (for someone like me with no brain xd) like you did in your tutorial here, which allowed me to learn SO much about different lines and how to improve this singular script in various ways. You have anything that would be useful, I've managed to create a GUI with a drop down list and a start button, but unsure how to either link my scripts to the various drop down lists or whatever I'm suppose to do. It would be incredibly useful if my list could for example like fetch said option (if I have each separate option as a different .class). Not sure if I'm looking at this the wrong way or what.

Glad that helped :)

I'd like to make a UI tutorial at some point, but i'm a little pushed for time at the moment.

The good thing about making a GUI is it is not specific to OSBot scripts. The UI code and indeed the way this code links to your script is very generic and as such all tutorials that you can find online should be relevant. Key words to google are 'Java swing gui'.

A simple initial way to get the two classes to communicate is by using static variables (although note that this solution is not very elegant and goes against object oriented principles). A better way would be for your script class to create a GUI class and call corresponding getter methods in said class.

Good luck!

Apa

Link to comment
Share on other sites

15 hours ago, Apaec said:

Glad that helped :)

I'd like to make a UI tutorial at some point, but i'm a little pushed for time at the moment.

The good thing about making a GUI is it is not specific to OSBot scripts. The UI code and indeed the way this code links to your script is very generic and as such all tutorials that you can find online should be relevant. Key words to google are 'Java swing gui'.

A simple initial way to get the two classes to communicate is by using static variables (although note that this solution is not very elegant and goes against object oriented principles). A better way would be for your script class to create a GUI class and call corresponding getter methods in said class.

Good luck!

Apa

Ah then of course that's fine, I know the one for sure.

I'll look into Java Swing UI and getter methods (and maybe some static variables too) and hopefully I'll have a lot more knowledge on the subject when all's done, thanks for at least helping me find the right way to go about things.

  • Like 1
Link to comment
Share on other sites

5 hours ago, LostOtaku said:

Ah then of course that's fine, I know the one for sure.

I'll look into Java Swing UI and getter methods (and maybe some static variables too) and hopefully I'll have a lot more knowledge on the subject when all's done, thanks for at least helping me find the right way to go about things.

It's certainly a pretty steep learning curve but it sounds like you're motivated enough to overcome it. Good luck! :)

Apa

Link to comment
Share on other sites

  • 4 weeks later...

Hey Apaec!

This was a wonderful tutorial! I have coding experience with Python, but never with Java. The IDE is a bit overwhelming but you explained it very well, and I was able to follow to the end.

Thing is, I went to go try my script and I realized: I'm not a member! So I can't thieve, and thus can't test my script. And I don't want to try my first simple script on my main, or any account with members really.

So point of the post, besides thanking you, is: how should I go about looking into the other commands or keywords from the osbot API. Like, if I want to try writing a woodcutting script, I would want to know how to get a tree from getObjects. I guess I'm looking for like documentation for the osbot commands/API. So that I could see all the possible commands and have a description of what each one does. 

Any idea if that exists? Or the closest thing to it?

Thank you again, and I appreciate it/this tutorial!

 

- Dan

Link to comment
Share on other sites

3 hours ago, dansb95 said:

Hey Apaec!

 This was a wonderful tutorial! I have coding experience with Python, but never with Java. The IDE is a bit overwhelming but you explained it very well, and I was able to follow to the end.

Thing is, I went to go try my script and I realized: I'm not a member! So I can't thieve, and thus can't test my script. And I don't want to try my first simple script on my main, or any account with members really.

So point of the post, besides thanking you, is: how should I go about looking into the other commands or keywords from the osbot API. Like, if I want to try writing a woodcutting script, I would want to know how to get a tree from getObjects. I guess I'm looking for like documentation for the osbot commands/API. So that I could see all the possible commands and have a description of what each one does. 

Any idea if that exists? Or the closest thing to it?

Thank you again, and I appreciate it/this tutorial!

 

- Dan

Thanks for the comments! In hindsight, it was a bit silly to use a thieving script as an example. Perhaps a wood cutter might have been better

The API can be found here: https://osbot.org/api/ and the classes available to you are listed on the left. It can sometimes take a bit of browsing to find what you're looking for, but most things are covered so you shouldn't have too much of a problem if you've read documentation before.

Malcolm gave a nice example of interacting with a tree so that is a good starting point!

Let me know if you have any further questions :)

-Apa

Link to comment
Share on other sites

  • 2 weeks later...

I give you guys a lot of credit, this scripting shit isn't for the faint of heart. I've been reading different tutorials, watching videos etc and all I've come up with so far is this: 

package oaklarders;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

// Start script lvl 33 Construction

@ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0)

public class Oaklarders extends Script {

    @Override
    public void onStart() {
        log("Sit back and relax");
    }
    @Override
    public int onLoop() throws InterruptedException {
        return random(200, 300);
    
    }
    @Override 
    public void onExit() {
        log("Thank's for using Oaklardersv1");
    }

    

    

// Make bot build and remove larders
// Make bot interact with butler to unote planks
// Make bot call servant if needed
// Add humanlike behavior sleeps etc
    
    
    
    }

 

To say the least I'm very new to this but I'm eager to learn from all the amazing scripters on Osbot and add to the community.

Link to comment
Share on other sites

11 hours ago, Imthabawse said:

I give you guys a lot of credit, this scripting shit isn't for the faint of heart. I've been reading different tutorials, watching videos etc and all I've come up with so far is this: 

package oaklarders;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

// Start script lvl 33 Construction

@ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0)

public class Oaklarders extends Script {

    @Override
    public void onStart() {
        log("Sit back and relax");
    }
    @Override
    public int onLoop() throws InterruptedException {
        return random(200, 300);
    
    }
    @Override 
    public void onExit() {
        log("Thank's for using Oaklardersv1");
    }

    

    

// Make bot build and remove larders
// Make bot interact with butler to unote planks
// Make bot call servant if needed
// Add humanlike behavior sleeps etc
    
    
    
    }

 

To say the least I'm very new to this but I'm eager to learn from all the amazing scripters on Osbot and add to the community.

Looks like a good start so far. I have to say, making oak larders is quite an adventurous script to write as your first. You may find it easier to work with something simpler to begin with, then work your way up :) Perhaps a simple oak chopping script?

Apa

  • Like 1
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...