Jump to content

My script mines 1 rock and then stops?


PshYouLost

Recommended Posts

This is the script

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.util.Utilities;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.awt.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Date;


@ScriptManifest(author = "PshYouLost", name = "labelCollector", info = "Get Runescape Info", version = 0.1, logo = "")
public final class dataCollector extends Script {

    private Path screenshotFile = Paths.get("C:\\Users\\PshYouLost\\OSBot\\Data\\screenshots\\screenshot_1.png");

    private void labelImages(String folderName) {
        Utilities.takeScreenshot();
        java.util.Date date = new Date();
        Path destinationFile = Paths.get("C:\\Users\\PshYouLost\\OSBot\\Data\\screenshots\\varrockEastIronPowerMiner\\" + folderName + "\\" + date.getTime() + ".png");
        try {
            Files.move(screenshotFile, destinationFile, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
            log(e);
        }

    }


    private RS2Object ironRocks = null;

    @Override
    public final int onLoop() throws InterruptedException {
        switch (getState()) {
            case MINE:
                labelImages("mineIronOre");
                ironRocks.interact("Mine");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return myPlayer().isAnimating();
                    }
                }.sleep();
                break;
            case DROP:
                labelImages("dropIronOre");
                inventory.dropAll("Iron ore");
                break;
            case 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.hasAction("Mine")) {
            return State.MINE;
        } else {
            return State.WAIT;
        }
    }

    @Override
    public final void onStart() throws InterruptedException {
        log("Script Started");
        if (getObjects().closest(7488) != null) {
            ironRocks = getObjects().closest(7488);
        } else if (ironRocks == null) {
            log("There are no iron rocks in this area!");
            stop();
        }
        camera.toTop();
    }

    @Override
    public void onPaint(Graphics2D g) {
    }

}

 

The goal is to only power mine iron from these two specific rocks

efg5Dxc.png

 

I don't want it to look for any other rocks at the moment.

 

The ID for those 2 specific iron rocks is `7488` There are two issues.

At the moment, the issue is that when I click run, the bot clicks an iron ore, and then stops and doesnt do anything else.

 

Any ideas?

  • Like 1
Link to comment
Share on other sites

 @Override
    public final void onStart() throws InterruptedException {
        log("Script Started");
        if (getObjects().closest(7488) != null) {
            ironRocks = getObjects().closest(7488);
        } else if (ironRocks == null) {
            log("There are no iron rocks in this area!");
            stop();
        }
        camera.toTop();
    }

Why is this even in your onStart() ?

 

  • Like 1
Link to comment
Share on other sites

1 minute ago, Charlotte said:

 @Override
    public final void onStart() throws InterruptedException {
        log("Script Started");
        if (getObjects().closest(7488) != null) {
            ironRocks = getObjects().closest(7488);
        } else if (ironRocks == null) {
            log("There are no iron rocks in this area!");
            stop();
        }
        camera.toTop();
    }

Why is this even in your onStart() ?

 

Because if I set the ironRocks = getObjects().closest(7488); 

in the onLoop area, then the bot will run around to other rocks and I don't want that. I only want it to wait for the rock north and west of me

Link to comment
Share on other sites

Just now, PshYouLost said:

Because if I set the ironRocks = getObjects().closest(7488); 

in the onLoop area, then the bot will run around to other rocks and I don't want that. I only want it to wait for the rock north and west of me

You could store the position/tile of that rock and use that with a filter to find only that rock. 

Link to comment
Share on other sites

4 minutes ago, bugsinmycode said:

You could store the position/tile of that rock and use that with a filter to find only that rock. 

Uhh. I'll look into it!

 

10 minutes ago, bugsinmycode said:

I'm not 100% sure, but it looks like the problem may be that you need to re-cache the iron rocks each time after you mine it. Try printing something like `ironRocks == null` or maybe `ironRocks.hasAction("Mine")`  in your getstate function. 

private State getState() {
        log(ironRocks.hasAction("Mine"));
        log(!myPlayer().isAnimating());
        log(!myPlayer().isMoving());
        if (inventory.isFull()) {
            return State.DROP;
        } else if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {
            return State.MINE;
        } else {
            return State.WAIT;
        }
    }

After my bot mines the initial rock, it just keeps printing 

Quote

[INFO][Bot #1][07/27 02:56:33 AM]: true
[INFO][Bot #1][07/27 02:56:33 AM]: true
[INFO][Bot #1][07/27 02:56:33 AM]: true

Every 5 seconds. Which I think means it's stuck at

 

case MINE:
                labelImages("mineIronOre");
                ironRocks.interact("Mine");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return myPlayer().isAnimating();
                    }
                }.sleep();
                break;
Link to comment
Share on other sites

3 minutes ago, PshYouLost said:

Uhh. I'll look into it!

 


private State getState() {
        log(ironRocks.hasAction("Mine"));
        log(!myPlayer().isAnimating());
        log(!myPlayer().isMoving());
        if (inventory.isFull()) {
            return State.DROP;
        } else if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {
            return State.MINE;
        } else {
            return State.WAIT;
        }
    }

After my bot mines the initial rock, it just keeps printing 

Every 5 seconds. Which I think means it's stuck at

 


case MINE:
                labelImages("mineIronOre");
                ironRocks.interact("Mine");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return myPlayer().isAnimating();
                    }
                }.sleep();
                break;

I think you need to put `ironRocks = getObjects().closest(7488); ` in your `onLoop` above your switch. You mentioned that doing that causes it to look for other rocks, but if you use the filter like I mentioned you can fix that. The way you are currently trying to do it is almost surely failing because you aren't recaching the ironRocks variable after mining it. You could test this easily enough by just moving what you currently have in the onstart (where you set iron rocks) to your on loop above the switch. If the script continues mining past 1 ore, then you know thats the issue. At that point you should attempt to implement the filter using the tile/position of the rocks you want to get. It will do you a lot of good in the future to understand how to use filters anyway, so it will be time well spent if you have to spend some time figuring them out. 

Link to comment
Share on other sites

7 minutes ago, bugsinmycode said:

I think you need to put `ironRocks = getObjects().closest(7488); ` in your `onLoop` above your switch. You mentioned that doing that causes it to look for other rocks, but if you use the filter like I mentioned you can fix that. The way you are currently trying to do it is almost surely failing because you aren't recaching the ironRocks variable after mining it. You could test this easily enough by just moving what you currently have in the onstart (where you set iron rocks) to your on loop above the switch. If the script continues mining past 1 ore, then you know thats the issue. At that point you should attempt to implement the filter using the tile/position of the rocks you want to get. It will do you a lot of good in the future to understand how to use filters anyway, so it will be time well spent if you have to spend some time figuring them out. 

I'm almost certain I'm doing this wrong.. =/

 

But this is what I attempted to do

 

List<RS2Object> availableIronRock = getObjects().filter(t -> t.getPosition() == ironRocks.getPosition() && t.getId() == 7488);
availableIronRock.get(0).interact("Mine");

But that obviously doesn't work lol.

And I couldn't figure out how to use a filter after the `.closest` part

Link to comment
Share on other sites

Holy shit. Okay, I'm definitely getting closer

 

public final int onLoop() throws InterruptedException {
    ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 1234 && n.getY() == 1234) || (n.getX() == 1234 && n.getY() == 1234)));
    switch (getState()) {
        case MINE:
            labelImages("mineIronOre");
            ironRocks.interact("Mine");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return myPlayer().isAnimating();
                }
            }.sleep();
            break;
        case DROP:
            labelImages("dropIronOre");
            inventory.dropAll("Iron ore");
            break;
        case WAIT:
            labelImages("doNothing");
            break;
    }
    return 100;
}

 

Link to comment
Share on other sites

Only do 

ironRocks = getObjects().closest(n -> n.getId() == 7488 && ((n.getX() == 1234 && n.getY() == 1234) || (n.getX() == 1234 && n.getY() == 1234)));

In the actual mining state, no need to do that in a state where you won't need to know any information about that object.
Please do null-checking aswell :)

Edited by Eagle Scripts
  • 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...