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!