Demauen 0 Share Posted September 23, 2017 So the script I have made for my Woodcutting bot doesen't fucntion properly, it runs to the woodcutting area finds the necesseray tree and clicks it. But after doing so once it no longer does it again and I cannot find what I'm doing wrong. Heres the script: package Main; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.Entity; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.interactive.NPC; import java.awt.*; @ScriptManifest(category = Category.WOODCUTTING, name = "Woodcutter", author = "Demauen", version = 1.0) public class WoodCutter extends AbstractScript { Area bankArea = new Area(3255, 3420, 3251, 3420, 0); Area logArea = new Area(3246, 3475, 3251, 3470, 0); @Override public void onStart() { } @Override public int onLoop() { if (logArea.contains(getLocalPlayer())) { cutWood(); } else if(!logArea.contains(getLocalPlayer())) { getWalking().walk(logArea.getRandomTile()); } if (getInventory().isFull()) { if (!bankArea.contains(getLocalPlayer())) { if (getWalking().walk(bankArea.getRandomTile())) { sleep(Calculations.random(3760, 6360)); } bank(); } } return (Calculations.random(1500, 3500)); } @Override public void onExit() { } @Override public void onPaint(Graphics graphics) { } private void cutWood() { GameObject yewTree = getGameObjects().closest("Yew"); yewTree.interact("Chop down"); while (logArea.contains(getLocalPlayer())) { sleepUntil(() -> !getLocalPlayer().isAnimating(), Calculations.random(750, 2500)); } } private void bank() { NPC banker = getNpcs().closest(npc -> npc != null && npc.hasAction("Bank")); if (banker.interact("Bank")) { if (sleepUntil(() -> getBank().isOpen(), Calculations.random(2854, 8294))) { getBank().depositAllExcept("Rune axe"); } } } } Link to comment Share on other sites More sharing options...
distraction 61 Share Posted September 23, 2017 Its because you never exit your while loop in the cutwood function. Try changing it to something like this. if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } } It would be best to use a sleepUntil without the while loop, but the above example should work if you really want to use a while. You could just replace the while loop with a sleepUntil using the opposite of the while condition "!yewTree.exists()". Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 23, 2017 Its because you never exit your while loop in the cutwood function. Try changing it to something like this. if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } } It would be best to use a sleepUntil without the while loop, but the above example should work if you really want to use a while. You could just replace the while loop with a sleepUntil using the opposite of the while condition "!yewTree.exists()". Oh okay! thanks for the help I appreciate it. Link to comment Share on other sites More sharing options...
distraction 61 Share Posted September 23, 2017 Oh okay! thanks for the help I appreciate it. No problem! Best of luck with your script. Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 23, 2017 No problem! Best of luck with your script. So I found another issue with my script (The previous issue is fixed, once again thanks!) but for some reason my character runs away a few tiles when the tree is cut down then runs back, I don't want my bot to behave like that and I don't know what's causing it. Link to comment Share on other sites More sharing options...
TheMcPker 74 Share Posted September 23, 2017 So I found another issue with my script (The previous issue is fixed, once again thanks!) but for some reason my character runs away a few tiles when the tree is cut down then runs back, I don't want my bot to behave like that and I don't know what's causing it. is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 23, 2017 is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut I'll try changing it, thanks for the tip! Link to comment Share on other sites More sharing options...
Koschei 147 Share Posted September 24, 2017 I'll try changing it, thanks for the tip! Also may want to add this too (More or less for future experiences if you plan to chop other trees too). GameObject yewTree = getGameObjects().closest(g-> g != null && g.getName().equals("Yew tree") && ChopArea.contains(g)); Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 24, 2017 is the tree area you have big enough? could be that due to it not being in the area anymore (from interacting with the tree you just cutted) and due to that tries to walk into you're tree area again before finding a tree to cut So I made the tree area big enough to contain me and the tree with certainty, But once the tree goes down my character still goes running aaway a few tiles and then back. Link to comment Share on other sites More sharing options...
Soldtodie 76 Share Posted September 24, 2017 So I made the tree area big enough to contain me and the tree with certainty, But once the tree goes down my character still goes running aaway a few tiles and then back. It could be because of this: GameObject yewTree = getGameObjects().closest("Yew"); Your script is searching for nearest Yew, it does't matter if this tree is outside of your area. Use filters to fix this. Look at Towlie's post. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.