Jump to content

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


Apaec

Recommended Posts

@Imthabawse Read up on the api, it's super usefull! :D https://osbot.org/api/ 

You will find that it has an inventory method.

getInventory();

This method actually has a build in drop all function.

  dropAll()
  Drops all the items.

getInventory().dropAll();

This also returns a boolean (true or falese)

So you can check if it succsfully dropped all items.

More so you can add a filter to this function so that for example it only drops items containing the word log. (This is a bit more advanced)

  dropAll(Filter<Item>... filters)
  Drops all the items in the filters.
    
getInventory().dropAll(item -> item.nameContains("log"));

Again this returns a boolean so you can check if you dropped the items correctly! :) 

These drop functions uses shift dropping if it's enabled.

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

  • 2 weeks later...

So, say i wanted to use an item with a fire, how would i do this? Like this?

if (getInventory().isFull()) 
        {
            getInventory().contains("Trout");
            {
                getInventory().use("Trout") RS2Object  Fire = getObjects().closest("Fire");; 
            }

I've been trying to find how to use fires to cook in the api, but can't find an object, or interactable for fire

Edited by mitsuki
Link to comment
Share on other sites

11 hours ago, mitsuki said:

So, say i wanted to use an item with a fire, how would i do this? Like this?


if (getInventory().isFull()) 
        {
            getInventory().contains("Trout");
            {
                getInventory().use("Trout") RS2Object  Fire = getObjects().closest("Fire");; 
            }

I've been trying to find how to use fires to cook in the api, but can't find an object, or interactable for fire

Well, it looks like you've correctly defined the fire:

RS2Object fire = getObjects().closest("Fire");

Then all you have to do is select the item in your inventory:

getInventory().interact("Trout", "Use");

.. and once that is selected (you will have to add checks for this), you can interact with the fire:

fire.interact("Use");

-Apa

Link to comment
Share on other sites

if (getInventory().isFull()) 
        {
            getInventory().contains("Trout");
            {
                RS2Object  Fire = getObjects().closest("Fire");
                {
                   getInventory().interact("Trout", "Use");
                   {
                       fire.interact("Use);
                   }
                }
            }

So it would be like that? I'm just confused because i didn't find anything about using a fire or anything in the api. Cheers for the help

Link to comment
Share on other sites

1 hour ago, mitsuki said:

if (getInventory().isFull()) 
        {
            getInventory().contains("Trout");
            {
                RS2Object  Fire = getObjects().closest("Fire");
                {
                   getInventory().interact("Trout", "Use");
                   {
                       fire.interact("Use);
                   }
                }
            }

So it would be like that? I'm just confused because i didn't find anything about using a fire or anything in the api. Cheers for the help

 kinda inefficient-> its going to resupply with 27 or 26 raw trout.

try to use: for loops, or events :) 

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

3 hours ago, mitsuki said:

if (getInventory().isFull()) 
        {
            getInventory().contains("Trout");
            {
                RS2Object  Fire = getObjects().closest("Fire");
                {
                   getInventory().interact("Trout", "Use");
                   {
                       fire.interact("Use);
                   }
                }
            }

So it would be like that? I'm just confused because i didn't find anything about using a fire or anything in the api. Cheers for the help

There's no specific reference to 'fire' in the API - we're working with Java objects here.

It seems you've got the brackets and semi colons a little confused as well, it might be worth looking up some basic java tutorials to get the basics down before trying to do this :)

Apa

  • Like 1
Link to comment
Share on other sites

1 hour ago, extatus said:

 kinda inefficient-> its going to resupply with 27 or 26 raw trout.

try to use: for loops, or events :) 

Ohh, i thought that everything within the curly brackets would be handled first, so if you nest another line of code within another set of them, i thought that would happen first 

9 minutes ago, Apaec said:

There's no specific reference to 'fire' in the API - we're working with Java objects here.

It seems you've got the brackets and semi colons a little confused as well, it might be worth looking up some basic java tutorials to get the basics down before trying to do this :)

Apa

okay, thanks guys

Link to comment
Share on other sites

  • 3 months later...

 

@Apaec - This is a fantastic guide. We all very much appreciate you taking the time to create this. Thanks :)

I'm familiar with basic Java programming concepts but don't know anything about the osbot API, so will have to get used to that and the nomenclature for finding objects around me once i start making scripts. I do have a particular question about the mouse movements, patterns, speeds, etc. How do we control this within our script? My initial thought is that when i pickup something, attack something, etc. using a bot then my mouse will fly across the screen with super precision or just appear elsewhere (as if using a touchpad?) and this would lead me to be banned immediately by the detection software. Does this happen? How do we control these mouse elements which would give away "bot-like behavior" ?  

And for this very simple tea thieving script that you've written via tutorial - is this actually functional? Or would the script click on the same identical spot of the tea stall and we'd be banned in 10 minutes? I'm trying to understand the level of randomization (mouse speed, pattern, delays, click positions) that is necessary in the scripts so we don't get banned in <10 minutes. (obviously at the beginning levels). Thoughts? 

And if this has already been discussed in another thread, please direct me to it! thanks! 

Link to comment
Share on other sites

9 hours ago, laxdude815 said:

 

@Apaec - This is a fantastic guide. We all very much appreciate you taking the time to create this. Thanks :)

I'm familiar with basic Java programming concepts but don't know anything about the osbot API, so will have to get used to that and the nomenclature for finding objects around me once i start making scripts. I do have a particular question about the mouse movements, patterns, speeds, etc. How do we control this within our script? My initial thought is that when i pickup something, attack something, etc. using a bot then my mouse will fly across the screen with super precision or just appear elsewhere (as if using a touchpad?) and this would lead me to be banned immediately by the detection software. Does this happen? How do we control these mouse elements which would give away "bot-like behavior" ?  

 And for this very simple tea thieving script that you've written via tutorial - is this actually functional? Or would the script click on the same identical spot of the tea stall and we'd be banned in 10 minutes? I'm trying to understand the level of randomization (mouse speed, pattern, delays, click positions) that is necessary in the scripts so we don't get banned in <10 minutes. (obviously at the beginning levels). Thoughts? 

And if this has already been discussed in another thread, please direct me to it! thanks! 

Hey,

The API does take a bit of getting used to, but if you've used other APIs in the past, it shouldn't be too bad.

As for mouse movements, most of this is abstracted away. OSbot handles all of the low level mouse interactions, and exposes a high level API for you to work with. As a result, the mouse doesn't 'teleport' as you alluded to, rather the movement is smooth and nonlinear. You can visualise this by adding a pixel trail to the mouse pointer in the paint method (or there might be a debug option to enable moues trail? not sure).

The tea thieving script is functional, but very basic. For example, it will spam-click the stall when tea is available.

Rather than me writing a paragraph about bans, i'd suggest having a read of this: https://osbot.org/forum/topic/124429-preventing-rs-botting-bans-v3/

Best

Apa

Link to comment
Share on other sites

  • 1 month later...
  • 1 month 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...