Jump to content

Half ass working Oak-doors


Imthabawse
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

@HunterRS Thanks for the feedback! I'm always trying to improve my scripts a little at a time with trial and error messing around with the API. Still learning Java as I go these are just fun projects for me that I like to share with the community to maybe learn something from them and also learn from you the community.

  • Like 1
Link to comment
Share on other sites

Update on Oak doors: Tweaked code a bit seems to be working fairly well. Still dicking around with Conditional Sleeps and a few other things but going to edit above code so be sure to check it out and tell me how bad it still is ?

None the less many levels have been gained and been a fun project thus far.

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.

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.

 Share

  • Recently Browsing   0 members

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