Jump to content

Powerminer doesn't detect when someone stole the ore


PshYouLost

Recommended Posts

This is the code

    private RS2Object ironRocks = null;
    private Filter<Item> nameFilter = new NameFilter<Item>("Iron ore");
    int[] dropOrderVertical = {0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27};
    int[] dropOrderHorizontal = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
    private long startedAt;
    private int currentYaw = 0;

    @Override
    public final int onLoop() throws InterruptedException {
        if (size(screenshotFolder) >= Double.valueOf("5e+10").longValue()) {
            stop(true);
        } else if ((System.currentTimeMillis() - startedAt) > 600000) {
            int randomDegree = random(1, 15);
            if (currentYaw + randomDegree > 270) {
                currentYaw = 0;
            }
            getCamera().moveYaw(currentYaw + randomDegree);
            currentYaw = getCamera().getYawAngle();
            startedAt = System.currentTimeMillis();
        } else {
            switch (getState()) {
                case MINE:
                    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 3286 && n.getY() == 3369) || (n.getX() == 3285 && n.getY() == 3368)));
                    if (ironRocks != null) {
                        log("Mine");
                        labelImages("mineIronOre");
                        ironRocks.interact("Mine");
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return (myPlayer().isAnimating());
                            }
                        }.sleep();
                    } else {
                        log("Wait");
                        labelImages("doNothing");
                    }
                    break;
                case DROP:
                    log("Drop");
                    getKeyboard().pressKey(VK_SHIFT);
                    for (int slot = 0; slot < 28; slot++) {
                        //for (int slot : dropOrderVertical) {
                        Item itemInSlot = getInventory().getItemInSlot(slot);
                        if (itemInSlot != null && nameFilter.match(itemInSlot)) {
                            labelImages("dropIronOre");
                            getInventory().interact(slot);
                            sleep(random(25, 100));
                        }
                    }
                    getKeyboard().releaseKey(VK_SHIFT);

                    break;
                case WAIT:
                    log("Wait");
                    labelImages("doNothing");
                    break;
            }

        }
        return 100;
    }

    private enum State {
        MINE, DROP, WAIT;
    }


    private State getState() {
        if (inventory.isFull()) {
            return State.DROP;
        } else if ((!myPlayer().isAnimating() && !myPlayer().isMoving()) || (ironRocks == null)) {
            return State.MINE;
        } else {
            return State.WAIT;
        }
    }

    @Override
    public final void onStart() throws InterruptedException {
        log("Script Started");
        startedAt = System.currentTimeMillis();
        camera.toTop();
    }
}

I've tried a solid amount of different things butI'm still just not able to make my bot realize the rock it's mining is currently empty.

} else if ((!myPlayer().isAnimating() && !myPlayer().isMoving()) || (ironRocks == null)) {

This line makes so much sense to me but it's obviously not working.

Either check to see if the player is NOT animating and is NOT moving. meaning i'm just standing there then mine

OR check to see if the current rock that we're mining is no longer an iron rock.

 

But for some reason it doesn't seem to work. Any ideas?

Link to comment
Share on other sites

@Tom taught me trick to use !exists() to complement ==null, so all credits to him for teaching me this trick. 

So in my super simple powerminer i wrote something like this, 

 if (skills.getStatic(Skill.MINING)>=15 && iron != null && !inventory.isFull()) {
            if (!myPlayer().isAnimating()) {
                if (iron.interact("Mine")) {
                    Sleep.sleepUntil(() -> iron == null || !iron.exists(), 5000);
                }
            }
        }

And that solved the problem for me with the bot not recognizing if the rock was depleted. 

 

edit, Also you should be looking to use the Sleep class that @Explv made available in his tutorial post, it's really dope!, And make conditional sleeps much easier to write. 
You can find it in, 

 

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

4 hours ago, slazter said:

@Tom taught me trick to use !exists() to complement ==null, so all credits to him for teaching me this trick. 

So in my super simple powerminer i wrote something like this, 


 if (skills.getStatic(Skill.MINING)>=15 && iron != null && !inventory.isFull()) {
            if (!myPlayer().isAnimating()) {
                if (iron.interact("Mine")) {
                    Sleep.sleepUntil(() -> iron == null || !iron.exists(), 5000);
                }
            }
        }

And that solved the problem for me with the bot not recognizing if the rock was depleted. 

 

edit, Also you should be looking to use the Sleep class that @Explv made available in his tutorial post, it's really dope!, And make conditional sleeps much easier to write. 
You can find it in, 

 

I changed it up but I still can't get it to work for some reason!

 

case MINE:
    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 3286 && n.getY() == 3369) || (n.getX() == 3285 && n.getY() == 3368)));
    if (ironRocks != null) {
        log("Mine");
        labelImages("mineIronOre");
        ironRocks.interact("Mine");
        Sleep.sleepUntil(() -> myPlayer().isAnimating() || !ironRocks.exists(), 5000);
    } else {
        log("Wait");
        labelImages("doNothing");
    }
    break;
19 hours ago, Chris said:

modifiedcolor will be null if its mined

What's the difference between what I'm doing at using modifiedcolor?

Link to comment
Share on other sites

3 minutes ago, Chris said:

 

if its nulll then its mined ( or has grey color)

Sorry, I don't think I'm following.

What's wrong with the code I'm currently using? It's checking to see if it's null, which is the same thing as checking to see if it has a modified color?

 

Anyway, this is code I currently have but it's still causing some problems

 

case MINE:
                    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 3286 && n.getY() == 3369) || (n.getX() == 3285 && n.getY() == 3368)));
                    if (ironRocks != null) {
                        log("Mine");
                        labelImages("mineIronOre");
                        ironRocks.interact("Mine");
                        RS2Object currentIronRock = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == ironRocks.getX() && n.getY() == ironRocks.getY())));
                        Sleep.sleepUntil(() -> myPlayer().isAnimating() || currentIronRock == null, 5000);
                    } else {
                        log("Wait");
                        labelImages("doNothing");
                    }
                    break;

 

Link to comment
Share on other sites

So I realized that the currentIronRock never updated to check so it was always not null.

 

So this is what I came up with

 

 case MINE:
                    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 3286 && n.getY() == 3369) || (n.getX() == 3285 && n.getY() == 3368)));
                    if (ironRocks != null) {
                        //log(ironRocks.getX() + "  " + ironRocks.getY());
                        log("Mine");
                        labelImages("mineIronOre");
                        ironRocks.interact("Mine");
                        Sleep.sleepUntil(() -> myPlayer().isAnimating() || getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == ironRocks.getX() && n.getY() == ironRocks.getY()))) == null, 5000);
                    } else {
                        log("Wait");
                        labelImages("doNothing");
                    }
                    break;

But now I occasionally get an error

 

Quote

[INFO][Bot #1][07/28 09:20:30 AM]: 3285  3368
[INFO][Bot #1][07/28 09:20:30 AM]: Mine
[ERROR][Bot #1][07/28 09:20:30 AM]: Error in script executor!
java.lang.NullPointerException

After someone stole my rock

Link to comment
Share on other sites

I finally got it to work!!

 

 private RS2Object ironRocks = null;
    private RS2Object currentIronRock = null;

    private Filter<Item> nameFilter = new NameFilter<Item>("Iron ore");
    int[] dropOrderVertical = {0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27};
    int[] dropOrderHorizontal = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
    private long startedAt;
    private int currentYaw = 0;

    @Override
    public final int onLoop() throws InterruptedException {
        if (size(screenshotFolder) >= Double.valueOf("5e+10").longValue()) {
            stop(true);
        } else if ((System.currentTimeMillis() - startedAt) > 600000) {
            int randomDegree = random(1, 15);
            if (currentYaw + randomDegree > 270) {
                currentYaw = 0;
            }
            getCamera().moveYaw(currentYaw + randomDegree);
            currentYaw = getCamera().getYawAngle();
            startedAt = System.currentTimeMillis();
        } else {
            switch (getState()) {
                case MINE:
                    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 3286 && n.getY() == 3369) || (n.getX() == 3285 && n.getY() == 3368)));
                    if (ironRocks != null) {
                        //log(ironRocks.getX() + "  " + ironRocks.getY());
                        log("Mine");
                        labelImages("mineIronOre");
                        ironRocks.interact("Mine");
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() {
                                currentIronRock = getObjects().get(ironRocks.getX(), ironRocks.getY()).get(0);
                                return myPlayer().isAnimating() || currentIronRock.getId() != 7488;
                            }
                        }.sleep();
                    } else {
                        log("Wait");
                        labelImages("doNothing");
                    }
                    break;
                case DROP:
                    log("Drop");
                    getKeyboard().pressKey(VK_SHIFT);
                    for (int slot = 0; slot < 28; slot++) {
                        //for (int slot : dropOrderVertical) {
                        Item itemInSlot = getInventory().getItemInSlot(slot);
                        if (itemInSlot != null && nameFilter.match(itemInSlot)) {
                            labelImages("dropIronOre");
                            getInventory().interact(slot);
                            sleep(random(25, 100));
                        }
                    }
                    getKeyboard().releaseKey(VK_SHIFT);

                    break;
                case WAIT:
                    log("Wait");
                    labelImages("doNothing");
                    break;
            }

        }
        return 100;
    }

    private enum State {
        MINE, DROP, WAIT;
    }


    private State getState() {
        if (ironRocks != null) {
            currentIronRock = getObjects().get(ironRocks.getX(), ironRocks.getY()).get(0);
        }
        if (inventory.isFull()) {
            return State.DROP;
        } else if ((!myPlayer().isAnimating() && !myPlayer().isMoving()) || currentIronRock.getId() != 7488) {
            log("TRY TO MINE");
            return State.MINE;
        } else {
            return State.WAIT;
        }
    }

Thanks everyone!

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