anfib 1 Share Posted September 9, 2022 Ok so i tried making a woodcutting script, it takes an axe from varrock east bank and it starts chopping trees and banks once its inventory is full but for some reason it never walks to the right place, i have no idea what's going on here is the code: import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.container.impl.equipment.Equipment; import org.dreambot.api.methods.interactive.GameObjects; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.skills.Skills; import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.methods.container.impl.Inventory; import java.awt.*; @ScriptManifest(category = Category.WOODCUTTING, name = "WoodCutter", author = "anfib", version = 1.0) public class WoodCutter extends AbstractScript{ public static final Area BANK_AREA = new Area(3251, 3420, 3255, 3240, 0); public static final Area TREE_AREA = new Area(new Tile(3280, 3454), new Tile(3272, 3443)); public boolean firstTime = true; public void pathToBank(){ log("Walking to bank"); Walking.walk(BANK_AREA.getCenter()); log("Arrived to bank"); } public void pathToTree(){ log("Walking to tree"); Walking.walk(TREE_AREA.getCenter()); log("Arrived to tree"); } public void deposit(){ Bank.open(); sleepUntil(() -> Bank.isOpen(), 5000); Bank.depositAllItems(); sleepUntil(() -> Inventory.isEmpty(), 5000); Bank.close(); sleepUntil(() -> !Bank.isOpen(), 5000); } public void lookForAxe(){ int atk = Skills.getRealLevel(Skill.ATTACK); int wc = Skills.getRealLevel(Skill.WOODCUTTING); if (!Bank.isOpen() && !BANK_AREA.contains(getLocalPlayer())){ Bank.open(); sleepUntil(() -> Bank.isOpen(), 5000); Bank.depositAllItems(); sleepUntil(() -> Inventory.isEmpty(), 5000); Bank.depositAllEquipment(); sleepUntil(() -> Equipment.isEmpty(), 5000); } if (atk >= 40 && wc >= 41 && Bank.contains("Rune axe")){ Bank.withdraw("Rune axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Rune axe", "Wield"); } else if (atk >= 30 && wc >= 31 && Bank.contains("Adamant axe")){ Bank.withdraw("Adamant axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Adamant axe", "Wield"); } else if (atk >= 20 && wc >= 21 && Bank.contains("Mithril axe")){ Bank.withdraw("Mithril axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Mithril axe", "Wield"); } else if (atk >= 10 && wc >= 11 && Bank.contains("Black axe")){ Bank.withdraw("Black axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Black axe", "Wield"); } else if (atk >= 5 && wc >= 6 && Bank.contains("Steel axe")){ Bank.withdraw("Steel axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Steel axe", "Wield"); } else if (atk >= 5 && wc >= 6 && Bank.contains("Steel axe")){ Bank.withdraw("Steel axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Steel axe", "Wield"); } else if (atk >= 1 && wc >= 1 && Bank.contains("Iron axe")){ Bank.withdraw("Iron axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Iron axe", "Wield"); } else if (atk >= 1 && wc >= 1 && Bank.contains("Bronze axe")){ Bank.withdraw("Bronze axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Bronze axe", "Wield"); } } public void chopWood(){ GameObject tree = GameObjects.closest("Tree"); if (tree!= null) { tree.interact("Chop Down"); sleepUntil(() -> !getLocalPlayer().isAnimating(), 13000); } } @Override public void onStart(){ log("Hi"); } @Override public int onLoop() { if (firstTime){ if (!BANK_AREA.contains(getLocalPlayer())){ pathToBank(); } else if (BANK_AREA.contains(getLocalPlayer())){ deposit(); lookForAxe(); firstTime = false; } } if (Inventory.isFull() && !BANK_AREA.contains(getLocalPlayer())){ pathToBank(); } if (Inventory.isFull() && BANK_AREA.contains(getLocalPlayer())){ deposit(); } if (Inventory.isEmpty() && !TREE_AREA.contains(getLocalPlayer())){ pathToTree(); } if (!Inventory.isFull() && TREE_AREA.contains(getLocalPlayer())){ chopWood(); } return 600; } @Override public void onExit() { log("Bye"); } @Override public void onPaint(Graphics graphics) { } } Link to comment Share on other sites More sharing options...
camelCase 271 Share Posted September 9, 2022 10 minutes ago, anfib said: public void lookForAxe(){ int atk = Skills.getRealLevel(Skill.ATTACK); int wc = Skills.getRealLevel(Skill.WOODCUTTING); if (!Bank.isOpen() && !BANK_AREA.contains(getLocalPlayer())){ Bank.open(); sleepUntil(() -> Bank.isOpen(), 5000); Bank.depositAllItems(); sleepUntil(() -> Inventory.isEmpty(), 5000); Bank.depositAllEquipment(); sleepUntil(() -> Equipment.isEmpty(), 5000); } if (atk >= 40 && wc >= 41 && Bank.contains("Rune axe")){ Bank.withdraw("Rune axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Rune axe", "Wield"); } else if (atk >= 30 && wc >= 31 && Bank.contains("Adamant axe")){ Bank.withdraw("Adamant axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Adamant axe", "Wield"); } else if (atk >= 20 && wc >= 21 && Bank.contains("Mithril axe")){ Bank.withdraw("Mithril axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Mithril axe", "Wield"); } else if (atk >= 10 && wc >= 11 && Bank.contains("Black axe")){ Bank.withdraw("Black axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Black axe", "Wield"); } else if (atk >= 5 && wc >= 6 && Bank.contains("Steel axe")){ Bank.withdraw("Steel axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Steel axe", "Wield"); } else if (atk >= 5 && wc >= 6 && Bank.contains("Steel axe")){ Bank.withdraw("Steel axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Steel axe", "Wield"); } else if (atk >= 1 && wc >= 1 && Bank.contains("Iron axe")){ Bank.withdraw("Iron axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Iron axe", "Wield"); } else if (atk >= 1 && wc >= 1 && Bank.contains("Bronze axe")){ Bank.withdraw("Bronze axe"); sleepUntil(() -> !Inventory.isEmpty(), 5000); Bank.close(); Inventory.interact("Bronze axe", "Wield"); } } all of this could be replaced with something like private String getAppropriateAxe() { int lvl = Skills.getRealLevel(Skill.WOODCUTTING); if (lvl > 41) return "Rune axe"; if (lvl > 31) return "Mithril axe"; // etc... } and then you can just check if you have the axe that method returns 15 minutes ago, anfib said: but for some reason it never walks to the right place, i have no idea what's going on you will have to be more descriptive, what area does it not go to, under what conditions? Link to comment Share on other sites More sharing options...
anfib 1 Author Share Posted September 9, 2022 12 minutes ago, camalCase said: all of this could be replaced with something like private String getAppropriateAxe() { int lvl = Skills.getRealLevel(Skill.WOODCUTTING); if (lvl > 41) return "Rune axe"; if (lvl > 31) return "Mithril axe"; // etc... } and then you can just check if you have the axe that method returns you will have to be more descriptive, what area does it not go to, under what conditions? Thanks for the suggestions, I'm still kinda new to this and coding in general so any advice is appreciated. But I think there's something wrong about how I make areas, like when it's banking it's always a few tiles away from the actual area, i tried checking if the coordinates were right a bunch of times but they always were. How I'm doing it is i'm taking the x and y of a the SW and NE tiles ingame Link to comment Share on other sites More sharing options...
420x69x420 72 Share Posted September 9, 2022 What exactly is the script doing wrong? Link to comment Share on other sites More sharing options...
anfib 1 Author Share Posted September 9, 2022 19 minutes ago, 420x69x420 said: What exactly is the script doing wrong? It's supposed to cut wood near the bank in east varrock and bank there, instead when it needs to bank it heads south out of varrock near the wheat farm and it just stand there and moves a bit every 5-10 seconds Link to comment Share on other sites More sharing options...
420x69x420 72 Share Posted September 9, 2022 new Area(3251, 3420, 3255, 3240, 0); typo woops! Change to: new Area(3251, 3420, 3255, 3420, 0); Happens to best of us sometimes, in fact so much that someone made a tool to solve these typos (10/10 can vouch): Link to comment Share on other sites More sharing options...
anfib 1 Author Share Posted September 9, 2022 5 minutes ago, 420x69x420 said: new Area(3251, 3420, 3255, 3240, 0); typo woops! Change to: new Area(3251, 3420, 3255, 3420, 0); Happens to best of us sometimes, in fact so much that someone made a tool to solve these typos (10/10 can vouch): Am I just extremely stupid or is that literally the same text Anyways thanks for the tool it looks VERY promising! Link to comment Share on other sites More sharing options...
420x69x420 72 Share Posted September 9, 2022 15 minutes ago, anfib said: Am I just extremely stupid or is that literally the same text the y2 coordinate you put as 3240, but really it should be 3420, this made the corner for your bank area in Lumbridge goblins, and so the center was located in varrock wheat fields. Link to comment Share on other sites More sharing options...
anfib 1 Author Share Posted September 9, 2022 8 minutes ago, 420x69x420 said: the y2 coordinate you put as 3240, but really it should be 3420, this made the corner for your bank area in Lumbridge goblins, and so the center was located in varrock wheat fields. OMG I'M SO STUPID i can't believe i actually lost 3 hours because of this.......Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.