una_maquina 36 Posted May 13, 2021 This helped me indirectly, but very profoundly, I was having problems with f.getModelColors() filter throwing nulls, after adding a null check in the filter, it has solved the issue; thanks!
Katana5lice 0 Posted June 29, 2021 Hey, this guide is helping me so much! Maybe a noob question but, in the execute() inside of the MiningTask class, I can only see rock.interact("Mine") inside of an if statement. How does the execute() know to click the rock without first doing the rock.interact("Mine") action?
Bonfire 334 Posted June 29, 2021 19 minutes ago, Katana5lice said: Hey, this guide is helping me so much! Maybe a noob question but, in the execute() inside of the MiningTask class, I can only see rock.interact("Mine") inside of an if statement. How does the execute() know to click the rock without first doing the rock.interact("Mine") action? Hey @Katana5lice. While it may look a little odd at first, a lot of the DreamBot interact methods return a boolean that essentially lets you know if an actions was performed successfully. So when you see the following: if (rock.interact("Mine")) { // If we successfully click on the rock sleepUntil(this::isMining, 2500); // Wait until we're mining, with a max wait time of 2,500ms (2.5 seconds) } The code is essentially saying the following: "Perform the 'Mine' interaction with the rock and IF it is successful, then sleep...". Structuring your code in this way allows you to follow-up with actions (in this case, sleep) only when an action (in this case, the mine interact) is successful. That being said, if for some reason the client was not able to successfully click "Mine" on the rock, it would not perform the sleep. Hope that helps
Dyno 12 Posted May 24, 2023 I have no errors in my IDE, yet when I open the script and run it in dreambot it does nothing, and doesn't attempt to mine any rocks. I tried to add Logger.log outputs to see what was working and didn't get any of those either, any ideas? Edit: The paint does in fact show up, though.
Dyno 12 Posted May 24, 2023 So i've made edits to the MiningTask in order to try and debugg, this is what I now have: The log is spamming "No available rocks found. Waiting...", meaning getClosestRock is returning Null even though I'm standing right near Copper rocks. Any ideas? package main.tasks; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.interactive.GameObjects; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.script.TaskNode; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.wrappers.interactive.GameObject; public class MiningTask extends TaskNode { @Override public boolean accept() { boolean accept = !Inventory.isFull() && !isMining(); log("MiningTask accept called, returned: " + accept); return accept; } @Override public int execute() { log("MiningTask execute called"); GameObject rock = getClosestRock(); // If there aren't any available rocks near us, we should just wait until one's available if (rock == null) { log("No available rocks found. Waiting..."); return Calculations.random(500, 1000); } if (rock.interact("Mine")) { // If we successfully click on the rock log("Started mining a rock."); Sleep.sleepUntil(this::isMining, 2500); // Wait until we're mining, with a max wait time of 2,500ms (2.5 seconds) } else { log("Failed to interact with the rock."); } return Calculations.random(500, 1000); } /** * Finds the closest acceptable rock that we can mine * * @return The closest GameObject that has the name 'Rocks', with the action 'Mine', and non-null model colors */ private GameObject getClosestRock() { GameObject rock = GameObjects.closest(object -> object.getName().equalsIgnoreCase("Rocks") && object.hasAction("Mine") && object.getModelColors() != null); log("getClosestRock called, returned: " + (rock != null ? rock.getName() : "null")); return rock; } /** * For part 1, we'll consider our player doing any animation as mining * This will be improved/changed in a future part * * @return true if the player is mining, otherwise false */ private boolean isMining() { return Players.getLocal().isAnimating(); } }
Tweeboy 21 Posted May 24, 2023 7 hours ago, blackbandan said: So i've made edits to the MiningTask in order to try and debugg, this is what I now have: The log is spamming "No available rocks found. Waiting...", meaning getClosestRock is returning Null even though I'm standing right near Copper rocks. Any ideas? package main.tasks; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.interactive.GameObjects; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.script.TaskNode; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.wrappers.interactive.GameObject; public class MiningTask extends TaskNode { @Override public boolean accept() { boolean accept = !Inventory.isFull() && !isMining(); log("MiningTask accept called, returned: " + accept); return accept; } @Override public int execute() { log("MiningTask execute called"); GameObject rock = getClosestRock(); // If there aren't any available rocks near us, we should just wait until one's available if (rock == null) { log("No available rocks found. Waiting..."); return Calculations.random(500, 1000); } if (rock.interact("Mine")) { // If we successfully click on the rock log("Started mining a rock."); Sleep.sleepUntil(this::isMining, 2500); // Wait until we're mining, with a max wait time of 2,500ms (2.5 seconds) } else { log("Failed to interact with the rock."); } return Calculations.random(500, 1000); } /** * Finds the closest acceptable rock that we can mine * * @return The closest GameObject that has the name 'Rocks', with the action 'Mine', and non-null model colors */ private GameObject getClosestRock() { GameObject rock = GameObjects.closest(object -> object.getName().equalsIgnoreCase("Rocks") && object.hasAction("Mine") && object.getModelColors() != null); log("getClosestRock called, returned: " + (rock != null ? rock.getName() : "null")); return rock; } /** * For part 1, we'll consider our player doing any animation as mining * This will be improved/changed in a future part * * @return true if the player is mining, otherwise false */ private boolean isMining() { return Players.getLocal().isAnimating(); } } Mining rocks were renamed since this guide was written - you're code is looking for an object named "Rocks", but all that's nearby are "Copper rocks"
Recommended Posts
Archived
This topic is now archived and is closed to further replies.