elbojoloco Posted November 27, 2018 Share Posted November 27, 2018 (edited) 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 November 27, 2018 by elbojoloco Quote Link to comment Share on other sites More sharing options...
jca Posted November 27, 2018 Share Posted November 27, 2018 (edited) 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 November 27, 2018 by jca Quote Link to comment Share on other sites More sharing options...
elbojoloco Posted November 27, 2018 Author Share Posted November 27, 2018 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.. Quote Link to comment Share on other sites More sharing options...
jca Posted November 27, 2018 Share Posted November 27, 2018 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 Quote Link to comment Share on other sites More sharing options...
elbojoloco Posted November 27, 2018 Author Share Posted November 27, 2018 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? Quote Link to comment Share on other sites More sharing options...
jca Posted November 28, 2018 Share Posted November 28, 2018 (edited) 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 November 28, 2018 by jca Quote Link to comment Share on other sites More sharing options...