supadupap00p 0 Posted May 12, 2021 Hi, So I wrote my first script and it does function as intended (to an extent) there is some weird behaviour, well namely one weird behaviour in that when it is killing cows sometimes it will just choose to run to the other end of the field. I have a sneaky suspicion why that is however I can't exactly work out the logical flaw. Was hoping someone here could maybe give me a few pointers? I have included the code below, its pretty self explanatory I think. public class CowKilla extends AbstractScript { private final String target = "Cow"; private final String loot = "Cowhide"; private final Area killArea = new Area(3254, 3256, 3264, 3297); private final Area bankArea = new Area(3207, 3222, 3210, 3215, 2); @Override public int onLoop() { if(!Inventory.isFull()) { if (!getLocalPlayer().isInCombat() && killArea.contains(getLocalPlayer())) { NPC cow = NPCs.closest(c -> c != null && c.getName().contains(target) && !c.isHealthBarVisible()); cow.interact("Attack"); sleepUntil(() -> !cow.exists(), 60000); GroundItem cowHide = GroundItems.closest(i -> i != null && i.getName().equals(loot) && !getLocalPlayer().isAnimating()); if (cowHide.distance(getLocalPlayer()) < 3) { if (cowHide.interact("Take")) { sleepUntil(() -> !cowHide.exists(), 25000); } } } else if (!killArea.contains(getLocalPlayer())) { Walking.walk(killArea.getRandomTile()); sleep(Calculations.random(350, 700)); } } else if (Inventory.isFull() && !bankArea.contains(getLocalPlayer())) { Walking.walk(bankArea.getRandomTile()); sleep(Calculations.random(350, 700)); } else if (bankArea.contains(getLocalPlayer())) { if(Bank.openClosest()) { Bank.depositAll(loot); sleepUntil(() -> !Inventory.contains(loot), 5000); } } return 1342; } }
quant 9 Posted May 12, 2021 You might want to try some explicit diagnostics, for example printing to console for each of your else if conditions. Then you would know for sure. Off the cuff, I suspect what's happening is you're attacking the closest cow to the player, and one way or another this is pulling the player outside of the killArea. When this happens and you leave combat, you walk to a random location in the kill area. Notably, you have no selection weight on that walk, so you might be outside of the area on the left, and walk to the far right of the area. Three solutions to mitigate this would be: Selecting from cows that are already in the kill area, or even close to the centre of it, to minimise player location drift. Revising your kill area to include everywhere cows can be selected. Revising the way you return to the area to walk to a closer location, rather than a random one. Good luck, Q
una_maquina 35 Posted May 12, 2021 It's most likely an area issue, you might want to redefine your area a bit and see if that helps. Try expanding it over the edges, etc. Like Quant said above me, it might be that you're getting outside the cow area while attacking a cow, and then you need to get back to that area by using a random tile. Also instead of a random tile, do Walking.walk(killArea.getCenter().getTile()); that'll solve any issues you might have by expanding the area over the edges.
una_maquina 35 Posted May 12, 2021 P.S. You don't actually have to worry about bank area, calling the method Bank.openClosest() will automatically go to the nearest bank, and will open it. You don't need to define any special areas is what I'm saying. Less code = better.
supadupap00p 0 Author Posted May 12, 2021 Thanks so much to the both of you. Very helpful! I resolved the main issue by yeah adjusting the area as you guys said and great tip on the banking!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.