Jump to content

Half ass working Oak-doors


Recommended Posts

Posted (edited)

Started off with a simple Oak larder project that gained me quite a few levels. Now I've moved onto the next step for quicker exp.. Oak doors. Here's the code I have thus far, it's about as broken as my Oak larders code.. but gets the job done. If you're looking for some easy levels C&P the code below and use at your own free will.

 

Code: Edited *

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;


@ScriptManifest(name = "Xpert Doors", logo = "", version = 1, author = "Imthabawse", info = "Build and remove oak doors, call butler when out of planks, repeat.")


public class xpertdoors extends Script {

    private Area BUILDAREA = new Area(10139, 462, 10140, 462);

    private void BUILDDOOR() throws InterruptedException {
        RS2Object doorSpace = getObjects().closest("Door space");
        if (doorSpace != null) {
            if (getInventory().getAmount("Oak plank") >= 10) {
                if (BUILDAREA.contains(doorSpace)) {
                    doorSpace.interact("Build");
                    log("Interacting with Door space..");
                    sleep(random(1200, 1400));
                    RS2Widget oakDoor = getWidgets().get(458, 4, 4);
                    if (oakDoor != null) {
                        oakDoor.interact("Build");
                        log("Building Door..");
                        new ConditionalSleep(2000) {
                            @Override
                            public boolean condition() {
                                return doorSpace.exists() && !myPlayer().isAnimating();
                            }
                        }.sleep();
                    }
                }
            }
        }
    }
    private void REMOVEDOOR() throws InterruptedException {
        RS2Object oakDoor = getObjects().closest("Door");
        if (oakDoor != null) {
            if (BUILDAREA.contains(oakDoor)) {
                oakDoor.interact("Remove");
                log("Interacting with Door..");
                sleep(random(1200, 1400));
                RS2Widget reallyRemove = getWidgets().get(219, 1, 1);
                if (reallyRemove != null) {
                    reallyRemove.interact();
                   log("Removing Door..");
                    new ConditionalSleep(2000) {
                        @Override
                        public boolean condition() {
                            return oakDoor.exists() && !myPlayer().isAnimating();
                        }
                    }.sleep();
                }
            }
        }
    }
    private void DEMONBUTLER() throws InterruptedException {
        NPC demonButler = getNpcs().closest("Demon butler");
        if (demonButler != null) {
            if (getInventory().getAmount("Oak plank") < 10) {
                demonButler.interact("Talk-to");
                log("Interacting with Demon butler..");
                sleep(random(1200, 1400));
                RS2Widget fetchPlanks = getWidgets().get(219, 1, 1);
                if (fetchPlanks != null) {
                    fetchPlanks.interact();
                    log("Waiting on planks.. Please wait.");
                    sleep(random(600, 900));
                    getMouse().moveOutsideScreen();
                    new ConditionalSleep(7000) {
                        @Override
                        public boolean condition() {
                            return getInventory().getAmount("Oak plank") > 10;
                        }
                    }.sleep();
                }
            }
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        sleep(random(300,600));
        if (!BUILDAREA.contains(myPlayer())) {
            getCamera().toPosition(BUILDAREA.getRandomPosition());
            log("Not in build area.. moving there.");
            getWalking().walk(BUILDAREA);
        } else if(BUILDAREA.contains(myPlayer())) {
           log("We are in Build area.. ");
            BUILDDOOR();
            REMOVEDOOR();
            DEMONBUTLER();
        }

        return 1500;
    }
}

I would love to hear feedback on how I can improve the script!

Edited by Imthabawse
Posted

Some things I can see immediately are:

  • Any API interact() call will return a boolean. This will be true when the interaction successfully occurred and false if it failed, combine this with if statements to make sure you're not sleeping when the interaction call failed.
  • Don't use random sleeps, you can definitely use a conditional sleep when waiting for a widget to appear.
  • You don't want to use static IDs to grab widgets as these can change a lot, instead use the widget debugger to find something to filter the widget on, for example the text the widget contains.
  • Like 2
Posted (edited)

Just some little quick advice on top of what dozza wrote,

Reusing code is a great thing, my advice though when rewriting a script is to maximazie your learning by only using your old code as a guide line for areas, method etc.

Have your code open on one side and on the other start the rewrite, we have all done this at one point when we said "who is the fucking dumbass who wrote this, ohh wait me", in my opinion this is the goal of rewriting a script because you can improve a lot when learning from your old mistakes. Just my opinion.

Great improvement on the script though, keep it up.

(Also it does a apply a bit less if your goal isn't to improve but to get a working product as fast as possible)

Edited by HunterRS
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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