Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ore vein RS2Object .exists() returning false when it does exist

Featured Replies

Hi, I started learning bot scripting yesterday, I have a programming background but no experience in Java. So I've been working on a simple Motherlode script and I'm getting stuck at the very start already, it is clicking the same Ore vein multiple times. I can figure out part of the reason, is because I do a myPlayer().isAnimating() check and when the mining animation is done, the bot thinks that it needs to check for the closest vein again, so I've added a contidionalsleep to my script to help wait until the vein.exists() is false, but that does not work for me as the condition (vein.exists()) is returning false even when I can see that the last clicked vein is still there and my char is mining it. so heres my code:

 

package core;

import java.awt.Graphics2D;

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 = "elbojoloco",
		info = "Mines in motherlode.",
		name = "Modderload Ultra",
		version = 1,
		logo = ""
)

public class Main extends Script {
	
	private RS2Object lastClickedVein;

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		
		log("Getting closest vein...");
		
		RS2Object vein = getObjects().closest("Ore vein");
	
		if (vein != null && 
			!getInventory().isFull() && 
			!myPlayer().isAnimating() && 
			!myPlayer().isMoving() &&
			getMap().canReach(vein) &&
			!vein.equals(this.lastClickedVein)) {
			
			log("Checks passed, intracting with vein..");
			
			if (vein.interact("Mine")) {
				log("Interacted with vein, going to sleep until vein no longer exists..");
				
				this.lastClickedVein = vein;
				
				new ConditionalSleep(random(50000, 60000), random(500, 1500)) {
					@Override
					public boolean condition() throws InterruptedException {
						log("Checking vein existence: " + vein.exists());
						
						return !vein.exists(); // I've tried with and without exclamation, no results.
					}
				}.sleep();
				
				log("Vein no longer exists, looping");
			}
		} else {
			log("Vein checks not passed");
		}
		
		return random(500, 1000);
	}

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

	@Override
	public void onPaint(Graphics2D g) {
		g.drawString("Hello World", 50, 50);
	}

}

EDIT: So my question being, why is vein.exists() returning false when the Ore vein is still there, why is my additional security of checking !vein.equals(this.lastClickedVein) also not working? I am getting suspisions that after gathering pay-dirt from the Ore vein, it changes the object Ore vein in some way that makes me think the old Ore vein is no longer there, or the same as it used to be? Just a shot in the dark.. Any help would be appreciated!

Edited by elbojoloco

Actually my original answer was incorrect on reading the code. 

Try 

new ConditionalSleep(random(50_000, 60_000), random(500, 1500)) {
  @Override
  public boolean condition() throws InterruptedException {
    log("Can mine? " + vein.hasAction("Mine")); 

    return !vein.hasAction("Mine"); // I've tried with and without exclamation, no results.
  }
}.sleep();

 

Edited by jca

  • Author
32 minutes ago, jca said:

Actually my original answer was incorrect on reading the code. 

Try 


new ConditionalSleep(random(50_000, 60_000), random(500, 1500)) {
  @Override
  public boolean condition() throws InterruptedException {
    log("Can mine? " + vein.hasAction("Mine")); 

    return !vein.hasAction("Mine"); // I've tried with and without exclamation, no results.
  }
}.sleep();

 

Nope, it just instantly quits the conditionalsleep and starts new loop.... I've discovered on the forums that apperantly an Ore vein has multiple states but I dont know how to take that vein and listen to any state changes for example, if there was a callback for a state change thatd be amazing.. or something along those lines..

11 minutes ago, elbojoloco said:

Nope, it just instantly quits the conditionalsleep and starts new loop.... I've discovered on the forums that apperantly an Ore vein has multiple states but I dont know how to take that vein and listen to any state changes for example, if there was a callback for a state change thatd be amazing.. or something along those lines..

Use the entity hover debug to look at what you need to listen for 

  • Author
3 minutes ago, jca said:

Use the entity hover debug to look at what you need to listen for 

I fixed it by checking wether the object located at the clicked vein's coordinates name equals "Depleted vein". Another issue i am walking into: the getObjects().closest() is not looking further than 3-4 tiles it seems, I want it to look on the whole screen, how can i do that?

21 hours ago, elbojoloco said:

I fixed it by checking wether the object located at the clicked vein's coordinates name equals "Depleted vein". Another issue i am walking into: the getObjects().closest() is not looking further than 3-4 tiles it seems, I want it to look on the whole screen, how can i do that?

Coordinates are not the best way to do it. Look at the debug.   

getObjects().getAll() returns all objects in the loaded region, if closest() is within 3-4 tiles it’ll return that. 

Edited by jca

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.