Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

  • Author
6 minutes ago, Rickest said:

Does anyone reccomend Eclipse today still? I have IntelliJ on my laptop but I'm having issues following step 2. on this guide. Trying to get a vers of eclipse if this doesnt work

I'm still using eclipse, not sure about set up for IntelliJ as i've not used it, but the idea is probably the same. I'm sure you can find an online tutorial for attaching a jar dependency for intelliJ somewhere!

I think i've followed everything correctly, even used the exact code. But when I go to run the script ingame it does nothing.

NVM figured it out... Got it up in running. Nearly zero coding experience so this guide is great... 

Edited by Botislife

  • Author
3 hours ago, Botislife said:

I think i've followed everything correctly, even used the exact code. But when I go to run the script ingame it does nothing.

NVM figured it out... Got it up in running. Nearly zero coding experience so this guide is great... 

Glad you got it working! Sorry that the guide is a little disorganised at the moment, i'm working on re-writing it but I cannot do it all in one go!

Good luck with your scripting journey, let me know if/when you need any help! (:

Apa

I got this code that teleports me to GE... The teleporting works fine but when I arrive at the GE it keeps teleporting until I run out of charges. Shouldn't the "if" statement only work if my player ISN'T inside the geArea? I know I can fix this by just adding more code after my character teleports... but that makes me wonder if "if" statements are even necessary or do they even work?

I don't know much about Java but it seems like the script just ignores all of the "if" statements and executes all methods from top to bottom. 

Code:

        case TELEPORT: 
            Area geArea = new Area(3165, 3480, 3161, 3476); //area of all possible squares in GE that you can get teleported to.
            Position current2 = myPlayer().getPosition();

            log("STARTING");  
            
            if (!geArea.contains(myPlayer()));{
                getEquipment().interact(EquipmentSlot.RING, "Grand exchange");
                log("teleporting");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return !myPlayer().getPosition().equals(current2);
                    }
                }.sleep();        
            }
            sleep(random(500, 600));
                        
            break;
 

Edited by theinadequacy

  • Author
1 hour ago, theinadequacy said:

I got this code that teleports me to GE... The teleporting works fine but when I arrive at the GE it keeps teleporting until I run out of charges. Shouldn't the "if" statement only work if my player ISN'T inside the geArea? I know I can fix this by just adding more code after my character teleports... but that makes me wonder if "if" statements are even necessary or do they even work?

I don't know much about Java but it seems like the script just ignores all of the "if" statements and executes all methods from top to bottom. 

Code:

        case TELEPORT: 
            Area geArea = new Area(3165, 3480, 3161, 3476); //area of all possible squares in GE that you can get teleported to.
            Position current2 = myPlayer().getPosition();

            log("STARTING");  
            
            if (!geArea.contains(myPlayer()));{
                getEquipment().interact(EquipmentSlot.RING, "Grand exchange");
                log("teleporting");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return !myPlayer().getPosition().equals(current2);
                    }
                }.sleep();        
            }
            sleep(random(500, 600));
                        
            break;
 

If statements do work! lol (:

Your code looks well structured - nicely done! The reason it is failing is purely syntactical - you've got a rogue ';' on line 7.

It may be a bit confusing, but long story short if you delete it, the code should work. The if statement is interpreted as a one-line (curly bracket-less) block and the empty expression is the conditional code. The curly brackets then form their own block which is always executed. Your code would look like this if properly formatted:

        case TELEPORT: 
            Area geArea = new Area(3165, 3480, 3161, 3476); //area of all possible squares in GE that you can get teleported to.
            Position current2 = myPlayer().getPosition();

            log("STARTING");  
            
            if (!geArea.contains(myPlayer()))
              	;
		{
                getEquipment().interact(EquipmentSlot.RING, "Grand exchange");
                log("teleporting");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return !myPlayer().getPosition().equals(current2);
                    }
                }.sleep();        
            }
            sleep(random(500, 600));
                        
            break;

Hopefully that makes sense. Careful where you put the ';'s!

Apa

I followed your guide and started the tea stall script but it just stands there and does nothing. I changed RS2Object to entity maybe cuz of this? But if i write RS2Object it does underline in red..?

  • Author
2 hours ago, b4k4l1m said:

I followed your guide and started the tea stall script but it just stands there and does nothing. I changed RS2Object to entity maybe cuz of this? But if i write RS2Object it does underline in red..?

 

1 hour ago, sonda said:

Post your code, so we can see.

^

 

3 hours ago, Apaec said:

 

^

 


import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

    @Override
    public void onStart() {
        log("Welcome to Simple Tea Thiever by Apaec.");
        log("If you experience any issues while running this script please report them to me on the forums.");
        log("Enjoy the script, gain some thieving levels!.");
    }

    private enum State {
        STEAL, DROP, WAIT
    };

    private State getState() {
        Entity stall = getObjects().closest("Tea stall");
        if (!inventory.isEmpty())
            return State.DROP;
        if (stall != null)
            return State.STEAL;
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case STEAL:
            Entity stall = getObjects().closest("Tea stall");
            if (stall != null) {
                stall.interact("Steal-from");
            }
            break;
        case DROP:
            inventory.dropAll();
            break;
        case WAIT:
            sleep(random(500, 700));
            break;
        }
        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("Thanks for running my Tea Thiever!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

What was the quick fix for rs2object when the redline last we’re under it?  May just need to right click it and create a field.

Edit, did you import  -  import org.osbot.rs07.api.model.RS2Object; ?, judging by what you posted - you did not.

If not, change it back to rs2Object and right click it, select the import option.  I am also learning and apa has helped me immensely, i will try to do my best to pay it forward when i can!

Edited by sonda

  • Author
8 hours ago, b4k4l1m said:


import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

    @Override
    public void onStart() {
        log("Welcome to Simple Tea Thiever by Apaec.");
        log("If you experience any issues while running this script please report them to me on the forums.");
        log("Enjoy the script, gain some thieving levels!.");
    }

    private enum State {
        STEAL, DROP, WAIT
    };

    private State getState() {
        Entity stall = getObjects().closest("Tea stall");
        if (!inventory.isEmpty())
            return State.DROP;
        if (stall != null)
            return State.STEAL;
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case STEAL:
            Entity stall = getObjects().closest("Tea stall");
            if (stall != null) {
                stall.interact("Steal-from");
            }
            break;
        case DROP:
            inventory.dropAll();
            break;
        case WAIT:
            sleep(random(500, 700));
            break;
        }
        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("Thanks for running my Tea Thiever!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

As Sonda said, You need the RS2Object import!

13 hours ago, sonda said:

What was the quick fix for rs2object when the redline last we’re under it?  May just need to right click it and create a field.

Edit, did you import  -  import org.osbot.rs07.api.model.RS2Object; ?, judging by what you posted - you did not.

If not, change it back to rs2Object and right click it, select the import option.  I am also learning and apa has helped me immensely, i will try to do my best to pay it forward when i can!

Thanks, this worked for me. Now i have to figure out how to let the bot fill the inv and then drop all items, now its dropping immediately when 1 tea is in inv.

  • Author
25 minutes ago, b4k4l1m said:

Thanks, this worked for me. Now i have to figure out how to let the bot fill the inv and then drop all items, now its dropping immediately when 1 tea is in inv.

Great! It's awesome that you're trying to expand the code. I will give you a hint. At the moment, we are moving to the drop state when '!inventory.isEmpty()'.

You can do a similar check for whether the inventory is full, as follows:

getInventory().isFull(); // Returns whether the inventory is currently full

Good luck!

Apa

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.