Jump to content

Al-Kharid MoltenGlassMaker & IronSmelter


Acinate

Recommended Posts

Version = 0.2

-Now supports Iron

 

-Start in Al Kharid Bank

 

Sources::

 

MoltenGlassMaker:

package org.acinate.scripts.Smelter;


import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;


@ScriptManifest(
        name="MoltenGlasser",
        author="Acinate",
        version=0.1,
        info="",
        logo=""
)
public class MoltenGlasser extends Script{

    Area BANK = new Area(3266,3171,3272,3164);
    Area FURNACE = new Area(3279,3188,3272,3184);

    private State state = State.IDLE;
    private final String sand = "Bucket of sand";
    private final String ash = "Soda ash";
    private final String bank = "Bank";
    private final String bbooth = "Bank booth";


    public void onStart() {this.log("Script has begun!");}

    public int onLoop() throws InterruptedException {
        switch (state = getState())
        {
            case CONTINUE:
                continueDia();
                break;
            case IDLE:
                this.log("case IDLE:");
                offTrack();
                break;
            case SMELT:
                this.log("case SMELT:");
                cameraFix();
                Entity furnace = this.objects.closest(FURNACE,24009);
                Item bucket = this.inventory.getItem(sand);
                RS2Widget smeltSelect = widgets.get(309,2);
                if (!getInventory().contains(sand)) {
                    getLocalWalker().walk(BANK, true);
                } else
                if (!myPlayer().isAnimating()) {


                    if (smeltSelect != null){
                        smeltSelect.interact("Make All");
                        sleep(random.nextInt(100) * 100);
                    }

                    if (smeltSelect == null) {
                        this.log("Bucket of sand > Use");
                        bucket.interact("Use");
                        sleep(random.nextInt(100) * 20);
                        furnace.interact("Use");
                        sleep(random.nextInt(100) * 50);
                        this.log("Crafting Glass");
                    }

                } else sleep(random.nextInt(1000) * 10);

                break;
            case BANK:
                this.log("case BANK:");
                continueDia();
                Entity booth = getObjects().closest(11744);

                if (!getInventory().contains(sand) || !getInventory().contains(ash)) {
                    if (getBank().isOpen()) {
                        if (getInventory().isFull()) {
                            getBank().depositAll();
                        }
                        if (!getInventory().contains(sand)) {
                            getBank().withdraw(sand, 14);
                            sleep(random.nextInt(50) + 500);
                        }
                        if (!getInventory().contains(ash)) {
                            getBank().withdraw(ash,14);
                            sleep(random.nextInt(50) + 500);
                        }
                        if (getInventory().isFull() && getInventory().contains("Bucket of Sand","Soda ash")) {
                            getBank().close();
                        }
                    } else booth.interact(bank); sleep(random.nextInt(50) + 500);
                } else getLocalWalker().walk(FURNACE, true);
                break;
        }
        return 500;
    }

    private void cameraFix() {
        this.log("cameraFix()");
        if (FURNACE.contains(myPlayer())) {
            if (getCamera().getYawAngle() != 45) {
                getCamera().moveYaw(45);
            }

            if (getCamera().getPitchAngle() != 50) {
                getCamera().movePitch(50);
            }
        }

        if (BANK.contains(myPlayer())) {
            if (getCamera().getYawAngle() != 90) {
                getCamera().moveYaw(90);
            }
            if (getCamera().getPitchAngle() != 67) {
                getCamera().movePitch(67);
            }
        }
    }

    private void offTrack() {
        this.log("offTrack()");
        if (getInventory().contains(ash,sand) && !FURNACE.contains(myPlayer())) {
            getLocalWalker().walk(FURNACE,true);
        }

        if (getInventory().onlyContains("Molten Glass")) {
            getLocalWalker().walk(BANK,true);
        }
    }

    private void continueDia() {
        if (getDialogues().isPendingContinuation()) {
            getDialogues().clickContinue();
        }
    }

    private State getState()
    {
        if (FURNACE.contains(myPlayer()))
            return State.SMELT;
        if (BANK.contains(myPlayer()))
            return State.BANK;
        if (getDialogues().isPendingContinuation())
            return State.CONTINUE;
        return State.IDLE;
    }

    public enum State{IDLE,SMELT,BANK,CONTINUE}

    public void onExit() {

    }
}

 

Iron Smelter:

package org.acinate.scripts.Smelter;


import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;


@ScriptManifest(
        name="IronSmelter",
        author="Acinate",
        version=0.1,
        info="",
        logo=""
)
public class IronSmelter extends Script{

    Area BANK = new Area(3266,3171,3272,3164);
    Area FURNACE = new Area(3279,3188,3272,3184);

    private State state = State.IDLE;
    private final String ironOre = "Iron ore";
    private final String ironBar = "Iron bar";
    private final String bank = "Bank";
    private final String bbooth = "Bank booth";


    public void onStart() {this.log("Script has begun!");}

    public int onLoop() throws InterruptedException {
        switch (state = getState())
        {
            case CONTINUE:
                continueDia();
                break;
            case IDLE:
                this.log("case IDLE:");
                offTrack();
                break;
            case SMELT:
                this.log("case SMELT:");
                Entity furnace = this.objects.closest(FURNACE, 24009);
                RS2Widget smeltSelect = widgets.get(311, 6);
                RS2Widget enterAmount = widgets.get(548,120);

                if (getInventory().contains(ironOre)) {
                    if (!myPlayer().isAnimating()) {

                        if (smeltSelect != null) {
                            smeltSelect.interact("Smelt X Iron");
                        } else furnace.interact("Smelt");

                        if (enterAmount.isVisible()) {
                            getKeyboard().typeString("28");
                        }
                    } else sleep(random.nextInt(10000) + 10000); log("ZZz...");
                } else getLocalWalker().walk(BANK, true);

                break;
            case BANK:
                this.log("case BANK:");
                continueDia();
                Entity booth = getObjects().closest(11744);

                if (!getInventory().onlyContains(ironOre) || getInventory().isEmpty()) {
                    if (getBank().isOpen()) {
                        getBank().depositAll();
                        sleep(random.nextInt(500) + -250);
                        getBank().withdrawAllButOne(ironOre);
                        sleep(random.nextInt(500) + -250);
                        getBank().close();
                    } else booth.interact("Bank");
                } else getLocalWalker().walk(FURNACE,true);


        }
        return 500;
    }

    private void cameraFix() {
        this.log("cameraFix()");
        if (FURNACE.contains(myPlayer())) {
            if (getCamera().getYawAngle() != 45) {
                getCamera().moveYaw(45);
            }

            if (getCamera().getPitchAngle() != 50) {
                getCamera().movePitch(50);
            }
        }

        if (BANK.contains(myPlayer())) {
            if (getCamera().getYawAngle() != 90) {
                getCamera().moveYaw(90);
            }
            if (getCamera().getPitchAngle() != 67) {
                getCamera().movePitch(67);
            }
        }
    }

    private void offTrack() {
        this.log("offTrack()");
        if (getInventory().contains(ironOre) && !FURNACE.contains(myPlayer())) {
            getLocalWalker().walk(FURNACE,true);
        }

        if (getInventory().onlyContains(ironBar)) {
            getLocalWalker().walk(BANK,true);
        }
    }

    private void continueDia() {
        if (getDialogues().isPendingContinuation()) {
            getDialogues().clickContinue();
        }
    }

    private State getState()
    {
        if (FURNACE.contains(myPlayer()))
            return State.SMELT;
        if (BANK.contains(myPlayer()))
            return State.BANK;
        if (getDialogues().isPendingContinuation())
            return State.CONTINUE;
        return State.IDLE;
    }

    public enum State{IDLE,SMELT,BANK,CONTINUE}

    public void onExit() {

    }
}

Edited by Acinate
  • Like 2
Link to comment
Share on other sites

Curious as to why you didn't use an else statement rather than

if(smeltSelect != null) {

}

if(smeltSelect == null) {

}

Something you could do is encapsulate each state behavior within the actual state:

class MoltenGlasser extends Script {
    private State state;

    public int onLoop() throws InterruptedException {
        getState().process(this);
        return 500;
    }

    private State getState() {
        //...
    }
}
enum State {
    SMELT {
        @Override
        public void performTask(MoltenGlasser script) {
             script.log("Smelting");
             script.cameraFix();

             Entity furnace = script.objects.closest(...);
             //...
        }
    },
    BANK {
        //...
    };

    public void performTask(MoltenGlasser script) {}
}

This will keep your onLoop method nice and clean, and separate the logic of each state into it's own method. Also, no need to switch between cases anymore! smile.png

 

Thanks for posting this! Every script snippit helps familiarize me with the API; much appreciated man!

Edited by fixthissite
  • Like 2
Link to comment
Share on other sites

 

Curious as to why you didn't use an else statement rather than

if(smeltSelect != null) {

}

if(smeltSelect == null) {

}

Something you could do is encapsulate each state behavior within the actual state:

class MoltenGlasser extends Script {
    private State state;

    public int onLoop() throws InterruptedException {
        getState().process(this);
        return 500;
    }

    private State getState() {
        //...
    }
}
enum State {
    SMELT {
        @Override
        public void performTask(MoltenGlasser script) {
             script.log("Smelting");
             script.cameraFix();

             Entity furnace = script.objects.closest(...);
             //...
        }
    },
    BANK {
        //...
    };

    public void performTask(MoltenGlasser script) {}
}

This will keep your onLoop method nice and clean, and separate the logic of each state into it's own method. Also, no need to switch between cases anymore! smile.png

 

Thanks for posting this! Every script snippit helps familiarize me with the API; much appreciated man!

Awesome feedback! Will incorporate ASAP! biggrin.png

Edited by Acinate
Link to comment
Share on other sites

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