Jump to content

Detecting that a rock has been mined?


Recommended Posts

Posted

I finished figuring out how to determine which of the same kind of rocks my bot is mining (eg. determine which of the two iron rocks I'm currently mining) but I currently can't get the bot to detect if the rock has been mined or not.

I'm using a check with the depleted rock ID, but its not picking up on it. I know its better to use color as a check for mining, but I'm wanting to use IDs for the meantime while I finish writing everything else and then deal with the color checks. 

Can I use IDs as a check? I've tried searching for source codes to see how other people have dealt with it, but couldn't find any.

Posted

 

1 hour ago, Dab in a Lab said:

I finished figuring out how to determine which of the same kind of rocks my bot is mining (eg. determine which of the two iron rocks I'm currently mining) but I currently can't get the bot to detect if the rock has been mined or not.

I'm using a check with the depleted rock ID, but its not picking up on it. I know its better to use color as a check for mining, but I'm wanting to use IDs for the meantime while I finish writing everything else and then deal with the color checks. 

Can I use IDs as a check? I've tried searching for source codes to see how other people have dealt with it, but couldn't find any.

Lend me a account and I can post an open source snippet for everyone

  • Heart 1
Posted
1 hour ago, Dab in a Lab said:

I finished figuring out how to determine which of the same kind of rocks my bot is mining (eg. determine which of the two iron rocks I'm currently mining) but I currently can't get the bot to detect if the rock has been mined or not.

I'm using a check with the depleted rock ID, but its not picking up on it. I know its better to use color as a check for mining, but I'm wanting to use IDs for the meantime while I finish writing everything else and then deal with the color checks. 

Can I use IDs as a check? I've tried searching for source codes to see how other people have dealt with it, but couldn't find any.

This is what I have come up with

two_ore_spawn area

ylEzWb8.png

    private Area two_ore_spawn = new Area(3175, 3366, 3175, 3368);
    private boolean newRock;
	//If we stopped animating OR newRock is TRUE
        if (!myPlayer().isAnimating() || newRock){
            //Object filter for: hasOre AND inside the specified area
            RS2Object rock = getObjects().closest(obj -> Rock.IRON.hasOre(obj) && two_ore_spawn.contains(obj.getPosition()));

            //If rock type exists && we clicked it
            if (rock != null && rock.interact("Mine")){
                //Set newRock to FALSE if we have just clicked it!
                newRock = false;
                log("Clicked on: " + rock.getName() + " " + rock.getPosition());
                //Sleep until condition evaluates to true for 5 seconds and looping the condition every 1.5 seconds
                if (new ConditionalSleep(5000, 1500) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !rock.exists();
                    }
                }.sleep()){
                    log("Conditional sleep evaluated to true!");
                    //If the conditional sleep evaluated true then we set newRock to TRUE
                    newRock = true;
                }
            }
        }

 

Explv's Snippet Data
 

import org.osbot.rs07.api.model.Entity;

public enum Rock {
    CLAY(new short[]{6705}),
    COPPER(new short[]{4645, 4510}),
    TIN(new short[]{53}),
    IRON(new short[]{2576}),
    SILVER(new short[]{74}),
    COAL(new short[]{10508}),
    GOLD(new short[]{8885}),
    MITHRIL(new short[]{-22239}),
    ADAMANTITE(new short[]{21662}),
    RUNITE(new short[]{-31437});

    private short[] colours;

    Rock(final short[] colours) {
        this.colours = colours;
    }

    public boolean hasOre(final Entity rockEntity) {
        if (rockEntity.getDefinition() == null) {
            return false;
        }

        short[] colours = rockEntity.getDefinition().getModifiedModelColors();

        if (colours == null) {
            return false;
        }

        for (short rockColour : this.colours) {
            for (short entityColour : colours) {
                if (rockColour == entityColour) {
                    return true;
                }
            }
        }
        return false;
    }
}

 

  • Like 1
  • Heart 1
Posted (edited)
5 hours ago, Dab in a Lab said:

I finished figuring out how to determine which of the same kind of rocks my bot is mining (eg. determine which of the two iron rocks I'm currently mining) but I currently can't get the bot to detect if the rock has been mined or not.

I'm using a check with the depleted rock ID, but its not picking up on it. I know its better to use color as a check for mining, but I'm wanting to use IDs for the meantime while I finish writing everything else and then deal with the color checks. 

Can I use IDs as a check? I've tried searching for source codes to see how other people have dealt with it, but couldn't find any.

From your explanation, it sounds like you're expecting your RS2Object instance (from before depletion) to change ID, which it never will. You will have to grab the new RS2Object instance, as the depleted rock is generally speaking a new different object.
As an alternative to checking the depletion ID, you could check if your non-depleted object instance has stopped existing with the exists() method.

Edited by FrostBug
  • Like 1
Posted
7 hours ago, FrostBug said:

From your explanation, it sounds like you're expecting your RS2Object instance (from before depletion) to change ID, which it never will. You will have to grab the new RS2Object instance, as the depleted rock is generally speaking a new different object.
As an alternative to checking the depletion ID, you could check if your non-depleted object instance has stopped existing with the exists() method.

Ya, that’s exactly what I was doing. I was relying on my script to pick up on the new rock ID from the one instance.

I’ve got everything working great now though with Chris’s help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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