Jump to content

Noob trying to learn


mrzoro35

Recommended Posts

First of all: I have no background in coding at all, I have pretty much have the bare bones basic knowledge of java. I am trying to teach my self the basics of java in my spare time (which is not a lot of time), and decided I wanted to try to apply my (non-existent) skills to making my first script: an essence miner. I needed something a little more challenging than a powerminer/powerthiever, but obviously I don't have the knowledge to do anything too crazy either. So I am going to try to be as detailed as possible because I actually would like to LEARN and to be told what I am doing wrong and why it is wrong. Also I am not expecting to be spoonfed code, would just like to pointed in the right direction and get tips/advice from people much more knowledgeable than I :D

 

Okay so...........

 

What it does do:

  • Opens bank when in the area & inventory is full
  • Deposits all
  • Walks to Aubury
  • Teleports to Essence

What it doesn't do:

  • Mine (doesn't seem to be recognizing the essence to mine at all; I've tried using its string and its ID as an RS2Object and an Entity and even an NPC)
  • Use the portal when the inventory is full
  • Move the camera to the portal when the inventory is full
  • Walk to bank when in Aubury area and inventory is full

What I have questions about/need help understanding:

  • Make it walk to a specified area/entity
  • How to recognize it is in the essence mine without using an Area because the area changes every time you log in and out (I tried this at first and ended up having like 3 or 4 areas and it was still changing)
  • And anything relating to the "what it doesn't do" section

Here is my code so far:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "MrZoro", info = "Essence Miner", name = "ZoroEssMiner", version = 1.0, logo = "")
public class ZoroEssMiner extends Script {

    private String[] pickaxes = { "Bronze pickaxe", "Iron pickaxe", "Steel pickaxe", "Black axe", "Mithril pickaxe",
            "Adamant pickaxe", "Rune pickaxe", "Dragon pickaxe" };

    Area BANK_AREA = new Area(3250, 3422, 3257, 3419);
    Area AUBURY_AREA = new Area(3249, 3404, 3257, 3398);
    /*
     * Area ESSENCE_AREA1 = new Area(12000, 8000, 13000, 5000); Area
     * ESSENCE_AREA2 = new Area(7500, 6500, 7400, 6200); Area ESSENCE_AREA3 =
     * new Area(6800, 11900, 8000, 12600);
     */

    private final Position[] walkToAubury = { new Position(3259, 3408, 0), new Position(3253, 3403, 0) };
    private final Position[] walkToBank = { new Position(3263, 3417, 0), new Position(3254, 3420, 0) };

    @Override
    public void onStart() {
        log("Welcome to ZoroEssMiner!");
        camera.toTop();
    }

    private enum State {
        BANK, MINE
    };

    private State getState() {
        if (inventory.isFull()) {
            return State.BANK;
        } else {
            return State.MINE;
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case BANK:
            Entity portal = getObjects().closest("Portal");
            /*
             * if (ESSENCE_AREA1.contains(myPlayer()) ||
             * ESSENCE_AREA2.contains(myPlayer()) ||
             * ESSENCE_AREA3.contains(myPlayer())) {
             */
            if (portal != null && portal.interact("Exit")) {
                if (portal.isVisible()) {
                    log("Heading to the bank");
                    portal.interact("Exit");
                    sleep(random(2000, 2400));
                } else {
                    camera.toEntity(portal);
                }
            }
            // }
            if (AUBURY_AREA.contains(myPlayer()) && inventory.isFull()) {
                walkPath(walkToBank);
            }
            if (BANK_AREA.contains(myPlayer())) {
                Entity bankBooth = getObjects().closest("Bank booth");
                if (bank.isOpen()) {
                    log("Banking Essence!");
                    bank.depositAllExcept(pickaxes);
                    sleep(random(800, 1000));
                } else {
                    if (bankBooth != null && bankBooth.interact("Bank")) {
                        if (bankBooth.isVisible()) {
                            log("Opening Bank");
                            bankBooth.interact("Bank");
                            sleep(random(1500, 2000));
                        } else {
                            camera.toEntity(bankBooth);
                        }
                    }
                }
            }
            break;
        case MINE:
            if (camera.getPitchAngle() < 67) {
                camera.toTop();
            }
            if (!inventory.isFull() && !AUBURY_AREA.contains(myPlayer())) {
                log("Walking to Aubury");
                walkPath(walkToAubury);
            }
            if (AUBURY_AREA.contains(myPlayer()) && !inventory.isFull()) {
                NPC Aubury = getNpcs().closest("Aubury");
                if (Aubury != null && Aubury.interact("Teleport")) {
                    log("Teleporting to the essence");
                    Aubury.interact("Teleport");
                    sleep(random(2000, 2400));
                }
            }
            /*
             * if (ESSENCE_AREA1.contains(myPlayer()) ||
             * ESSENCE_AREA2.contains(myPlayer()) ||
             * ESSENCE_AREA3.contains(myPlayer())) {
             */
            int essenceID = 14192;
            Entity essence = getObjects().closest(essenceID);
            if (essence != null && essence.interact("Mine")) {
                if (essence.isVisible()) {
                    essence.interact("Mine");
                    log("Mining some essence");
                }
            }
            if (myPlayer().isMoving() || myPlayer().isAnimating()) {
                sleep(random(200, 300));
            }
            //}
            break;
        }
        return random(200, 300);
    }

    // Path walking method by Pug
    public void walkPath(Position[] path) throws InterruptedException {
        for (Position p : path) {
            if (myPosition().distance(p) > 16 || myPosition().distance(p) < 3)
                continue;
            boolean success;
            do {
                success = walkTile(p);
            } while (!success);
        }
    }

    public boolean walkTile(Position p) throws InterruptedException {
        if (myPosition().distance(p) > 13) {
            Position pos = new Position(((p.getX() + myPosition().getX()) / 2) + random(-4, 4),
                    ((p.getY() + myPosition().getY()) / 2) + random(-4, 4), myPosition().getZ());
            walkTile(pos);
        }
        mouse.click(new MiniMapTileDestination(bot, p), false);
        int fail = 0;
        while (myPosition().distance(p) > 2 && fail < 10) {
            sleep(500);
            if (!myPlayer().isMoving())
                fail++;
        }
        return fail != 10;
    }

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

    @Override
    public void onPaint(Graphics2D g) {

    }

}

Also, when I stop the script after it gets stuck, I get this error in the logger:

[ERROR][11/09 05:23:57 PM]: Uncaught exception!
java.lang.IllegalArgumentException: Cannot change state of non-idle timeline [Model transitions:org.pushingpixels.substance.internal.animation.StateTransitionTracker READY:0.0]
    at org.pushingpixels.trident.Timeline.addCallback(Timeline.java:333)
    at org.pushingpixels.substance.internal.animation.StateTransitionTracker.onModelStateChanged(StateTransitionTracker.java:480)
    at org.pushingpixels.substance.internal.utils.RolloverButtonListener.focusLost(RolloverButtonListener.java:201)
    at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
    at java.awt.Component.processFocusEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

 

So obviously I am doing something terribly wrong lol. Don't flame me too hard, obviously still very new and learning and just trying to challenge myself a bit so I can apply and learn at the same time :P

Link to comment
Share on other sites

First of all: I have no background in coding at all, I have pretty much have the bare bones basic knowledge of java. I am trying to teach my self the basics of java in my spare time (which is not a lot of time), and decided I wanted to try to apply my (non-existent) skills to making my first script: an essence miner. I needed something a little more challenging than a powerminer/powerthiever, but obviously I don't have the knowledge to do anything too crazy either. So I am going to try to be as detailed as possible because I actually would like to LEARN and to be told what I am doing wrong and why it is wrong. Also I am not expecting to be spoonfed code, would just like to pointed in the right direction and get tips/advice from people much more knowledgeable than I biggrin.png

 

Okay so...........

 

What it does do:

  • Opens bank when in the area & inventory is full
  • Deposits all
  • Walks to Aubury
  • Teleports to Essence

What it doesn't do:

  • Mine (doesn't seem to be recognizing the essence to mine at all; I've tried using its string and its ID as an RS2Object and an Entity and even an NPC)
  • Use the portal when the inventory is full
  • Move the camera to the portal when the inventory is full
  • Walk to bank when in Aubury area and inventory is full

What I have questions about/need help understanding:

  • Make it walk to a specified area/entity
  • How to recognize it is in the essence mine without using an Area because the area changes every time you log in and out (I tried this at first and ended up having like 3 or 4 areas and it was still changing)
  • And anything relating to the "what it doesn't do" section

Here is my code so far:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "MrZoro", info = "Essence Miner", name = "ZoroEssMiner", version = 1.0, logo = "")
public class ZoroEssMiner extends Script {

    private String[] pickaxes = { "Bronze pickaxe", "Iron pickaxe", "Steel pickaxe", "Black axe", "Mithril pickaxe",
            "Adamant pickaxe", "Rune pickaxe", "Dragon pickaxe" };

    Area BANK_AREA = new Area(3250, 3422, 3257, 3419);
    Area AUBURY_AREA = new Area(3249, 3404, 3257, 3398);
    /*
     * Area ESSENCE_AREA1 = new Area(12000, 8000, 13000, 5000); Area
     * ESSENCE_AREA2 = new Area(7500, 6500, 7400, 6200); Area ESSENCE_AREA3 =
     * new Area(6800, 11900, 8000, 12600);
     */

    private final Position[] walkToAubury = { new Position(3259, 3408, 0), new Position(3253, 3403, 0) };
    private final Position[] walkToBank = { new Position(3263, 3417, 0), new Position(3254, 3420, 0) };

    @Override
    public void onStart() {
        log("Welcome to ZoroEssMiner!");
        camera.toTop();
    }

    private enum State {
        BANK, MINE
    };

    private State getState() {
        if (inventory.isFull()) {
            return State.BANK;
        } else {
            return State.MINE;
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case BANK:
            Entity portal = getObjects().closest("Portal");
            /*
             * if (ESSENCE_AREA1.contains(myPlayer()) ||
             * ESSENCE_AREA2.contains(myPlayer()) ||
             * ESSENCE_AREA3.contains(myPlayer())) {
             */
            if (portal != null && portal.interact("Exit")) {
                if (portal.isVisible()) {
                    log("Heading to the bank");
                    portal.interact("Exit");
                    sleep(random(2000, 2400));
                } else {
                    camera.toEntity(portal);
                }
            }
            // }
            if (AUBURY_AREA.contains(myPlayer()) && inventory.isFull()) {
                walkPath(walkToBank);
            }
            if (BANK_AREA.contains(myPlayer())) {
                Entity bankBooth = getObjects().closest("Bank booth");
                if (bank.isOpen()) {
                    log("Banking Essence!");
                    bank.depositAllExcept(pickaxes);
                    sleep(random(800, 1000));
                } else {
                    if (bankBooth != null && bankBooth.interact("Bank")) {
                        if (bankBooth.isVisible()) {
                            log("Opening Bank");
                            bankBooth.interact("Bank");
                            sleep(random(1500, 2000));
                        } else {
                            camera.toEntity(bankBooth);
                        }
                    }
                }
            }
            break;
        case MINE:
            if (camera.getPitchAngle() < 67) {
                camera.toTop();
            }
            if (!inventory.isFull() && !AUBURY_AREA.contains(myPlayer())) {
                log("Walking to Aubury");
                walkPath(walkToAubury);
            }
            if (AUBURY_AREA.contains(myPlayer()) && !inventory.isFull()) {
                NPC Aubury = getNpcs().closest("Aubury");
                if (Aubury != null && Aubury.interact("Teleport")) {
                    log("Teleporting to the essence");
                    Aubury.interact("Teleport");
                    sleep(random(2000, 2400));
                }
            }
            /*
             * if (ESSENCE_AREA1.contains(myPlayer()) ||
             * ESSENCE_AREA2.contains(myPlayer()) ||
             * ESSENCE_AREA3.contains(myPlayer())) {
             */
            int essenceID = 14192;
            Entity essence = getObjects().closest(essenceID);
            if (essence != null && essence.interact("Mine")) {
                if (essence.isVisible()) {
                    essence.interact("Mine");
                    log("Mining some essence");
                }
            }
            if (myPlayer().isMoving() || myPlayer().isAnimating()) {
                sleep(random(200, 300));
            }
            //}
            break;
        }
        return random(200, 300);
    }

    // Path walking method by Pug
    public void walkPath(Position[] path) throws InterruptedException {
        for (Position p : path) {
            if (myPosition().distance(p) > 16 || myPosition().distance(p) < 3)
                continue;
            boolean success;
            do {
                success = walkTile(p);
            } while (!success);
        }
    }

    public boolean walkTile(Position p) throws InterruptedException {
        if (myPosition().distance(p) > 13) {
            Position pos = new Position(((p.getX() + myPosition().getX()) / 2) + random(-4, 4),
                    ((p.getY() + myPosition().getY()) / 2) + random(-4, 4), myPosition().getZ());
            walkTile(pos);
        }
        mouse.click(new MiniMapTileDestination(bot, p), false);
        int fail = 0;
        while (myPosition().distance(p) > 2 && fail < 10) {
            sleep(500);
            if (!myPlayer().isMoving())
                fail++;
        }
        return fail != 10;
    }

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

    @Override
    public void onPaint(Graphics2D g) {

    }

}

Also, when I stop the script after it gets stuck, I get this error in the logger:

[ERROR][11/09 05:23:57 PM]: Uncaught exception!
java.lang.IllegalArgumentException: Cannot change state of non-idle timeline [Model transitions:org.pushingpixels.substance.internal.animation.StateTransitionTracker READY:0.0]
    at org.pushingpixels.trident.Timeline.addCallback(Timeline.java:333)
    at org.pushingpixels.substance.internal.animation.StateTransitionTracker.onModelStateChanged(StateTransitionTracker.java:480)
    at org.pushingpixels.substance.internal.utils.RolloverButtonListener.focusLost(RolloverButtonListener.java:201)
    at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
    at java.awt.Component.processFocusEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

So obviously I am doing something terribly wrong lol. Don't flame me too hard, obviously still very new and learning and just trying to challenge myself a bit so I can apply and learn at the same time tongue.png

 

For walking just use

getLocalWalker().walk()  and getLocalWalker().walkPath()

This:

Entity essence = getObjects().closest(essenceID);
if (essence != null && essence.interact("Mine")) {
    if (essence.isVisible()) {
        essence.interact("Mine");
        log("Mining some essence");
    }
}

Is also wrong you are calling essence.interact("Mine") in your if statement???

 

Should be more like:

RS2Object essence = getObjects().closest(essenceId);
if(essence != null) essence.interact("Mine");

I also suggest you add more states to your script. For example, WALK_TO_BANK and WALK_TO_ESSENCE

and update your getState method to something like:

private State getState() {
    if (getInventory().isFull()) {
        
        if(BANK_AREA.contains(myPosition())) return State.BANK;
        else return State.WALK_TO_BANK;
    } else {

        if(MINE_AREA.contains(myPosition()) return State.MINE:
        else return State.WALK_TO_ESSENCE;
    }
}

For banking you are doing:

if (bankBooth != null && bankBooth.interact("Bank")) {
    if (bankBooth.isVisible()) {
        log("Opening Bank");
        bankBooth.interact("Bank");
        sleep(random(1500, 2000));
    } else {
        camera.toEntity(bankBooth);
    }
}

But there are methods that already do this in the API:

getBank()
getBank().open()
getBank().isOpen()
getBank().close()

etc.

For walking to an entity or area you can use:

getLocalWalker().walk(entity.getPosition());

and

getLocalWalker().walk(area.getRandomPosition());

For moving camera to the portal:

getCamera().toEntity(getObjects().closest("Portal"));

For interacting with the portal why not make a path to the portal, then click on the portal, then follow another path to the essence.

 

For detecting when you are at the Essence you could potentially use a nearby object e.g.

if(getObjects().closest("Essence") != null) return State.MINING;  
Edited by Explv
  • Like 3
Link to comment
Share on other sites

 

For walking just use

getLocalWalker().walk()  and getLocalWalker().walkPath()

This:

Entity essence = getObjects().closest(essenceID);
if (essence != null && essence.interact("Mine")) {
    if (essence.isVisible()) {
        essence.interact("Mine");
        log("Mining some essence");
    }
}

Is also wrong you are calling essence.interact("Mine") in your if statement???

 

Should be more like:

RS2Object essence = getObjects().closest(essenceId);
if(essence != null) essence.interact("Mine");

I also suggest you add more states to your script. For example, WALK_TO_BANK and WALK_TO_ESSENCE

and update your getState method to something like:

private State getState() {
    if (getInventory().isFull()) {
        
        if(BANK_AREA.contains(myPosition())) return State.BANK;
        else return State.WALK_TO_BANK;
    } else {

        if(MINE_AREA.contains(myPosition()) return State.MINE:
        else return State.WALK_TO_ESSENCE;
    }
}

For banking you are doing:

if (bankBooth != null && bankBooth.interact("Bank")) {
    if (bankBooth.isVisible()) {
        log("Opening Bank");
        bankBooth.interact("Bank");
        sleep(random(1500, 2000));
    } else {
        camera.toEntity(bankBooth);
    }
}

But there are methods that already do this in the API:

getBank()
getBank().open()
getBank().isOpen()
getBank().close()

etc.

For walking to an entity or area you can use:

getLocalWalker().walk(entity.getPosition());

and

getLocalWalker().walk(area.getRandomPosition());

For moving camera to the portal:

getCamera().toEntity(getObjects().closest("Portal"));

For interacting with the portal why not make a path to the portal, then click on the portal, then follow another path to the essence.

 

For detecting when you are at the Essence you could potentially use a nearby object e.g.

if(getObjects().closest("Essence") != null) return State.MINING;  

 

 

//Example for banking

if (!getBank().isOpen()) {
       getBank().open();
          new ConditionalSleep(3000) {
              @Override
              public boolean condition() {
                 return getBank().isOpen();
              }
          }.sleep();
}

Wow I seriously was over complicating everything. unsure.png  Thank you both so much, this helped A LOT. laugh.png

  • Like 2
Link to comment
Share on other sites

The immediate problem is here I would say:

            if (!inventory.isFull() && !AUBURY_AREA.contains(myPlayer())) {
                log("Walking to Aubury");
                walkPath(walkToAubury);
            }

If you're not at aubury (In the mines is not at aubury) you'll try walking to aubury. But you cannot do that while you're in the mines.

Also, there's no need to ever check if your inventory is full in the MINE case, since you would never be in the MINE case in the first place if it was.

 

___
EDIT:

It also seems that you don't have any code that walks to the actual mining area. When trying to grab the essence rock objects, are you certain they are not out of range?

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

The immediate problem is here I would say:

            if (!inventory.isFull() && !AUBURY_AREA.contains(myPlayer())) {
                log("Walking to Aubury");
                walkPath(walkToAubury);
            }

If you're not at aubury (In the mines is not at aubury) you'll try walking to aubury. But you cannot do that while you're in the mines.

I did actually figure this one out by doing the simplest thing: looking at the log lol unsure.png I simply just made an area portion of Varrock (slightly larger than the bank all the way to Aubury: "NONESS_AREA") and replaced "!AUBURY_AREA.contains(myPlayer())" with "(NONESS_AREA.contains(myPlayer())".

 

 

It also seems that you don't have any code that walks to the actual mining area. When trying to grab the essence rock objects, are you certain they are not out of range?

 

I was having trouble with this, but Explv's advice helped me out a lot.

 

The only problems I'm having right now is walking to and using the portal. Sometimes it works, sometimes it doesnt (mostly doesn't). Sometimes it will walk to the nearest portal, then go walk all the way across the mine to another portal, but then it will never interact with the portal. I get this error upon script stopping:

[ERROR][11/10 11:52:46 PM]: Uncaught exception!
java.lang.IllegalArgumentException: Cannot change state of non-idle timeline [Model transitions:org.pushingpixels.substance.internal.animation.StateTransitionTracker READY:0.0]
    at org.pushingpixels.trident.Timeline.addCallback(Timeline.java:333)
    at org.pushingpixels.substance.internal.animation.StateTransitionTracker.onModelStateChanged(StateTransitionTracker.java:480)
    at org.pushingpixels.substance.internal.utils.RolloverButtonListener.focusLost(RolloverButtonListener.java:201)
    at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
    at java.awt.Component.processFocusEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

This is the code pertaining to the portal:

			RS2Object portal = getObjects().closest("Portal");
			if (!NONESS_AREA.contains(myPlayer())) {
				if (portal != null) {
					if (!portal.isVisible()) {
						getLocalWalker().walk(portal);
					} else if (portal.hasAction("Use")) {
						portal.interact("Use");
					} else
						portal.interact("Exit");
					sleep(random(300, 400));
					log("Heading to the bank");
				}
			}

So what am I doing wrong?

Edited by mrzoro35
Link to comment
Share on other sites

I did actually figure this one out by doing the simplest thing: looking at the log lol unsure.png I simply just made an area portion of Varrock (slightly larger than the bank all the way to Aubury: "NONESS_AREA") and replaced "!AUBURY_AREA.contains(myPlayer())" with "(NONESS_AREA.contains(myPlayer())".

 

 

I was having trouble with this, but Explv's advice helped me out a lot.

 

The only problems I'm having right now is walking to and using the portal. Sometimes it works, sometimes it doesnt (mostly doesn't). Sometimes it will walk to the nearest portal, then go walk all the way across the mine to another portal, but then it will never interact with the portal. I get this error upon script stopping:

[ERROR][11/10 11:52:46 PM]: Uncaught exception!
java.lang.IllegalArgumentException: Cannot change state of non-idle timeline [Model transitions:org.pushingpixels.substance.internal.animation.StateTransitionTracker READY:0.0]
    at org.pushingpixels.trident.Timeline.addCallback(Timeline.java:333)
    at org.pushingpixels.substance.internal.animation.StateTransitionTracker.onModelStateChanged(StateTransitionTracker.java:480)
    at org.pushingpixels.substance.internal.utils.RolloverButtonListener.focusLost(RolloverButtonListener.java:201)
    at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
    at java.awt.Component.processFocusEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

This is the code pertaining to the portal:

			RS2Object portal = getObjects().closest("Portal");
			if (!NONESS_AREA.contains(myPlayer())) {
				if (portal != null) {
					if (!portal.isVisible()) {
						getLocalWalker().walk(portal);
					} else if (portal.hasAction("Use")) {
						portal.interact("Use");
					} else
						portal.interact("Exit");
					sleep(random(300, 400));
					log("Heading to the bank");
				}
			}

So what am I doing wrong?

 

Looks like an AWT error. Do you have any graphical user interface of your own?

 

Link to comment
Share on other sites

No, I haven't made any yet. I wanted to make sure I could actually get it to run before I did that.

 

I even took out the onPaint and unimported java.awt.*

 

Hmm.. well, in any case. That error isn't of any help then, since it's thrown on the EDT (Won't have any references to your code)

 

Try using log() to track what the executing thread is doing (this writes to the client console)

Or post your updated source so we can take a look again

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

I encountered the same exception using the following code:

package scripts;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

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

	@Override
	public int onLoop() throws InterruptedException {
		return 600;
	}
}

After pressing the client's stop button:


[INFO][Bot #1][11/11 10:59:10 AM]: Started script : TestScript
[INFO][Bot #1][11/11 10:59:13 AM]: Terminating script TestScript...
[INFO][Bot #1][11/11 10:59:13 AM]: Script TestScript has exited!
[ERROR][11/11 10:59:13 AM]: Uncaught exception!
java.lang.IllegalArgumentException: Cannot change state of non-idle timeline [Model transitions:org.pushingpixels.substance.internal.animation.StateTransitionTracker READY:0.0]
	at org.pushingpixels.trident.Timeline.addCallback(Timeline.java:333)
	at org.pushingpixels.substance.internal.animation.StateTransitionTracker.onModelStateChanged(StateTransitionTracker.java:480)
	at org.pushingpixels.substance.internal.utils.RolloverButtonListener.focusLost(RolloverButtonListener.java:201)
	at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
	at java.awt.Component.processFocusEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

It appears the exception encountered is client-side.

Link to comment
Share on other sites

Hmm.. well, in any case. That error isn't of any help then, since it's thrown on the EDT (Won't have any references to your code)

 

Try using log() to track what the executing thread is doing (this writes to the client console)

Or post your updated source so we can take a look again

 

Okay so I added a log after every action:

 

			RS2Object portal = getObjects().closest("Portal");
			if (!NONESS_AREA.contains(myPlayer())) {
				log("I need to bank!");
				if (portal != null) {
					log("Null Check");
					if (!portal.isVisible()) {
						log("The portal is not visible");
						getLocalWalker().walk(portal);
						log("Walking to the portal");
					} else if (portal.hasAction("Use")) {
						portal.interact("Use");
						log("Using portal");
					} else
						portal.interact("Exit");
					log("Using portal");
					sleep(random(300, 400));
				}
			}

It will repeatedly log "I need to bank!" so I guess it is skipping over the rest of the code...

 

Here is the rest of the source code just in case it matters (and I'm sure I've made other mistakes throughout anyway).

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.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "MrZoro", info = "Essence Miner", name = "ZoroEssMiner", version = 1.0, logo = "")
public class ZoroEssMiner extends Script {

	private String[] pickaxes = { "Bronze pickaxe", "Iron pickaxe", "Steel pickaxe", "Black axe", "Mithril pickaxe",
			"Adamant pickaxe", "Rune pickaxe", "Dragon pickaxe" };

	Area BANK_AREA = new Area(3250, 3422, 3257, 3419);
	Area AUBURY_AREA = new Area(3249, 3404, 3257, 3398);
	Area NONESS_AREA = new Area(3242, 3427, 3266, 3397);

	@Override
	public void onStart() {
		log("Welcome to ZoroEssMiner!");
		camera.toTop();
	}

	private enum State {
		BANK, MINE
	};

	private State getState() {
		if (inventory.isFull()) {
			return State.BANK;
		} else {
			return State.MINE;
		}
	}

	@Override
	public int onLoop() throws InterruptedException {
		mouse.setSpeed(2);
		switch (getState()) {
		case BANK:
			RS2Object portal = getObjects().closest("Portal");
			if (!NONESS_AREA.contains(myPlayer())) {
				log("I need to bank!");
				if (portal != null) {
					log("Null Check");
					if (!portal.isVisible()) {
						log("The portal is not visible");
						getLocalWalker().walk(portal);
						log("Walking to the portal");
					} else if (portal.hasAction("Use")) {
						portal.interact("Use");
						log("Using portal");
					} else
						portal.interact("Exit");
					log("Using portal");
					sleep(random(300, 400));
				}
			}
			RS2Object bankBooth = getObjects().closest("Bank booth");
			if (!BANK_AREA.contains(myPlayer()) && bankBooth != null) {
				getLocalWalker().walk(bankBooth);
			}
			if (BANK_AREA.contains(myPlayer())) {
				if (getBank().isOpen()) {
					log("Banking Essence!");
					deposit();
				} else {
					if (bankBooth != null) {
						if (!getBank().isOpen()) {
							getBank().open();
							new ConditionalSleep(3000) {
								@Override
								public boolean condition() {
									return getBank().isOpen();
								}
							}.sleep();
						} else {
							getCamera().toEntity(bankBooth);
						}
					}
				}
			}
			break;
		case MINE:
			if (NONESS_AREA.contains(myPlayer())) {
				log("Walking to Aubury");
				getLocalWalker().walk(AUBURY_AREA.getRandomPosition());
			}
			if (AUBURY_AREA.contains(myPlayer())) {
				NPC Aubury = getNpcs().closest("Aubury");
				if (Aubury != null) {
					log("Teleporting to the essence");
					Aubury.interact("Teleport");
					sleep(random(300, 400));
				}
			}
			RS2Object essence = getObjects().closest("Rune Essence");
			if (!myPlayer().isAnimating()) {
				if (!NONESS_AREA.contains(myPlayer()) && essence != null) {
					if (!essence.isVisible()) {
						getLocalWalker().walk(essence);
					} else {
						essence.interact("Mine");
						sleep(random(800, 1000));
						log("Mining some essence");
					}
				}
			}
			if (myPlayer().isAnimating()) {
				getCamera().toTop();
				getCamera().moveYaw(random(348, 356));
				new ConditionalSleep(3000) {

					@Override
					public boolean condition() {
						return myPlayer().isAnimating();
					}

				}.sleep();
			}
			break;
		}
		return random(200, 300);
	}

	public void deposit() throws InterruptedException {
		int[] essID = { 1436, 7936 };
		if (!getInventory().contains(pickaxes)) {
			getWidgets().get(12, 27).interact("Deposit inventory");
			sleep(random(200, 300));
		} else {
			getInventory().getItem(essID).interact("Deposit-All");
			sleep(random(200, 300));
		}
	}

	@Override
	public void onExit() {
		log("Thanks for running ZoroEssMiner!");
	}
}
Link to comment
Share on other sites

If it's spamming one message and then not continuing to another, then you've found your problem.

In your case, simply, portal == null.

 

Yeah I see that now, but now my entire script isn't working and it keeps freezing my client. I'm too frustrated to even work with it right now so I guess I will just have to continue learning java and attempt at it again when I have a much better understanding of the language. unsure.png I'd rather do that anyway so I can focus on quality.

 

Thank you so much for your help though. It has been very much appreciated and I learned A LOT from everyone who commented on this thread. biggrin.png

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