ggdre 0 Share Posted January 25, 2023 I'm relatively new to scripting in DreamBot and Java and have been working on a simple Firemaking script, but seem to be getting a lot of false negatives for Players.getLocal().isAnimating(), leading to lots of dropped logs and missed XP. To counteract this I'm trying to implement the ExperienceListener, so that after using the tinderbox on the logs the script sleeps until the player receives and XP drop. However, I can't for the life of me figure out how to properly implement this in my script and know I'm making some silly mistakes but can't find a proper tutorial anywhere at my level. Here is what I have so far: // Start ExperienceListener.java // import org.dreambot.api.script.event.impl.ExperienceEvent; interface ExperienceListener extends java.util.EventListener { public boolean onGained(ExperienceEvent event); } // End ExperienceListener.java // // Start XpDrop.java // import org.dreambot.api.script.event.impl.ExperienceEvent; public class XpDrop implements ExperienceListener { @Override public boolean onGained(ExperienceEvent event) { return true; } } // End XpDrop.java // The part of the script I'm trying to implement this into: public int execute() { // Construct FireMaker to access getLogs method FireMaker fireMaker = new FireMaker(); // Get logs String logs = fireMaker.getLogs(); // Use tinderbox Inventory.interact("Tinderbox"); sleep(Calculations.random(250, 500)); // On logs Inventory.interact(logs); // Construct XpDrop Class XpDrop xpDrop = new XpDrop(); // Sleep until XP drop while (!xpDrop.onGained(ExperienceEvent event)) { // This is where I'm having problems - I don't know what to pass into onGained() sleep(Calculations.random(300,700) } return 300; } Very grateful for any help or links to resources! Link to comment Share on other sites More sharing options...
pharaoh 130 Share Posted January 25, 2023 i think you are looking for the SkillTracker - SkillTracker (DreamBot Javadocs) i would also wait until the item (tinderbox) is selected before trying to interact with the logs ImLife 1 Link to comment Share on other sites More sharing options...
ggdre 0 Author Share Posted January 25, 2023 52 minutes ago, pharaoh said: i think you are looking for the SkillTracker - SkillTracker (DreamBot Javadocs) As in starting an instance of the SkillTracker on each loop? That could work, thank you! 54 minutes ago, pharaoh said: i would also wait until the item (tinderbox) is selected before trying to interact with the logs It's not that the player doesn't successfully initiate the firemaking animation, rather the firemaking animation doesn't return true for Players.getLocal().isAnimating(). Thanks! Would still love to find a tutorial for the ExperienceListener or other Listeners built into the API, if anyone can help! Link to comment Share on other sites More sharing options...
pharaoh 130 Share Posted January 25, 2023 47 minutes ago, ggdre said: As in starting an instance of the SkillTracker on each loop? That could work, thank you! It's not that the player doesn't successfully initiate the firemaking animation, rather the firemaking animation doesn't return true for Players.getLocal().isAnimating(). Thanks! Would still love to find a tutorial for the ExperienceListener or other Listeners built into the API, if anyone can help! you add a new SkillTracker in your onStart method @Override public void onStart() { if (Client.isLoggedIn()) { SkillTracker.start(Skill.CRAFTING); } } but i see what you mean now. Link to comment Share on other sites More sharing options...
Genius 49 Share Posted January 27, 2023 On 1/25/2023 at 9:18 AM, ggdre said: I'm relatively new to scripting in DreamBot and Java and have been working on a simple Firemaking script, but seem to be getting a lot of false negatives for Players.getLocal().isAnimating(), leading to lots of dropped logs and missed XP. To counteract this I'm trying to implement the ExperienceListener, so that after using the tinderbox on the logs the script sleeps until the player receives and XP drop. However, I can't for the life of me figure out how to properly implement this in my script and know I'm making some silly mistakes but can't find a proper tutorial anywhere at my level. Here is what I have so far: // Start ExperienceListener.java // import org.dreambot.api.script.event.impl.ExperienceEvent; interface ExperienceListener extends java.util.EventListener { public boolean onGained(ExperienceEvent event); } // End ExperienceListener.java // // Start XpDrop.java // import org.dreambot.api.script.event.impl.ExperienceEvent; public class XpDrop implements ExperienceListener { @Override public boolean onGained(ExperienceEvent event) { return true; } } // End XpDrop.java // The part of the script I'm trying to implement this into: public int execute() { // Construct FireMaker to access getLogs method FireMaker fireMaker = new FireMaker(); // Get logs String logs = fireMaker.getLogs(); // Use tinderbox Inventory.interact("Tinderbox"); sleep(Calculations.random(250, 500)); // On logs Inventory.interact(logs); // Construct XpDrop Class XpDrop xpDrop = new XpDrop(); // Sleep until XP drop while (!xpDrop.onGained(ExperienceEvent event)) { // This is where I'm having problems - I don't know what to pass into onGained() sleep(Calculations.random(300,700) } return 300; } Very grateful for any help or links to resources! Hey, are you still having trouble with this? In your burn method, you could always do this: int temp = Skills.getExperience(Skill.FIREMAKING); //untested, but should be close if (use tinderbox on logs) { //pseudocode sleepUntil(() -> Skills.getExperience(Skill.FIREMAKING) > temp, 20000, 50); //sleeps until we gain FM exp, or 20 seconds max, sleepUntil will check exit condition every 50ms. //if you get here, we either gained exp, or it's been 20+ seconds. Also, consider adding a random sleep here so you're not always burning immediately after exp gained //sleep(0,250); } Hope this helps if it's still giving you trouble. ImLife 1 Link to comment Share on other sites More sharing options...
ggdre 0 Author Share Posted January 31, 2023 On 1/27/2023 at 3:41 AM, Genius said: Hey, are you still having trouble with this? In your burn method, you could always do this: int temp = Skills.getExperience(Skill.FIREMAKING); //untested, but should be close if (use tinderbox on logs) { //pseudocode sleepUntil(() -> Skills.getExperience(Skill.FIREMAKING) > temp, 20000, 50); //sleeps until we gain FM exp, or 20 seconds max, sleepUntil will check exit condition every 50ms. //if you get here, we either gained exp, or it's been 20+ seconds. Also, consider adding a random sleep here so you're not always burning immediately after exp gained //sleep(0,250); } Hope this helps if it's still giving you trouble. Thanks, this is great. Will give it a try! Link to comment Share on other sites More sharing options...
Genius 49 Share Posted January 31, 2023 3 minutes ago, ggdre said: Thanks, this is great. Will give it a try! No problem! Let me know if you are still having trouble Link to comment Share on other sites More sharing options...
hashbang 7 Share Posted April 10, 2023 Looks like using SkillTracker will be suitable for what you're trying to achieve, but for future reference, here is how to use the ExperienceListener directly public class Tester extends AbstractScript implements ExperienceListener { @Override public int onLoop() { return 10; } @Override public void onGained(ExperienceEvent event) { Logger.log(String.format("Gained %d xp in %s", event.getChange(), event.getSkill())); } } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now