Demauen 0 Author Share Posted September 26, 2017 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. Hey thanks for the tip, so I tried it with Towlie's code for finding the tree within the area but the same thing still happens. Once the tree is chopped down my character starts running back and forth a few tiles. Link to comment Share on other sites More sharing options...
Soldtodie 76 Share Posted September 26, 2017 Hey thanks for the tip, so I tried it with Towlie's code for finding the tree within the area but the same thing still happens. Once the tree is chopped down my character starts running back and forth a few tiles. Can you send your actual code please Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 26, 2017 Can you send your actual code please Yeah sure here it is: 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(3092, 3242, 3092, 3245, 0); Area logArea = new Area(3056, 3270, 3052, 3273, 0); @Override public void onStart() { } @Override public int onLoop() { getCamera().rotateTo(6603, 6385); 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(3200, 5500)); } @Override public void onExit() { } @Override public void onPaint(Graphics graphics) { } private void cutWood() { GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer())); yewTree.interact("Chop down"); if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } } } 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"); } } } } I usually have the camera rotation code commented out but just added it in for now. Link to comment Share on other sites More sharing options...
distraction 61 Share Posted September 26, 2017 Yeah sure here it is: 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(3092, 3242, 3092, 3245, 0); Area logArea = new Area(3056, 3270, 3052, 3273, 0); @Override public void onStart() { } @Override public int onLoop() { getCamera().rotateTo(6603, 6385); 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(3200, 5500)); } @Override public void onExit() { } @Override public void onPaint(Graphics graphics) { } private void cutWood() { GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer())); yewTree.interact("Chop down"); if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } } } 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"); } } } } I usually have the camera rotation code commented out but just added it in for now. One problem seems to be that you are checking if the player is within the logArea in your filter where you grab the tree rather than checking if the tree is within the log area. In other words, you have this GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer())); but what you should use is this GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(g)); Link to comment Share on other sites More sharing options...
Demauen 0 Author Share Posted September 26, 2017 One problem seems to be that you are checking if the player is within the logArea in your filter where you grab the tree rather than checking if the tree is within the log area. In other words, you have this GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(getLocalPlayer())); but what you should use is this GameObject yewTree = getGameObjects().closest(g -> g != null && g.getName().equals("Yew" ) && logArea.contains(g)); Oh okay thanks! I'll try changing it and see if it helps. EDIT: It worked thanks dude but now for some reason rather than running away once the bot has cut down the tree maybe like 5-10 times it just stops detecting the tree and just stands there I think it could be from these lines: if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } Link to comment Share on other sites More sharing options...
dQw4w9WgXcQ 184 Share Posted September 26, 2017 Oh okay thanks! I'll try changing it and see if it helps. EDIT: It worked thanks dude but now for some reason rather than running away once the bot has cut down the tree maybe like 5-10 times it just stops detecting the tree and just stands there I think it could be from these lines: if (yewTree != null && yewTree.interact()) { while (yewTree.exists()) { sleep(Calculations.random(500, 1250)); } Sometimes the interaction will fail even if it returns true, so the tree will never be cut down. You should use a sleepuntil with a timeout instead of a infinite while loop. Better yet, design your script so it doesn't rely on conditional sleeps. Conditional sleeps are resource intensive and should be avoided, it's not necessary here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.