Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Odd behaviour on my first script


    supadupap00p

    Recommended Posts

    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;
        }
    }

     

    Link to comment
    Share on other sites

    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

    Link to comment
    Share on other sites

    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.

    Link to comment
    Share on other sites

    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.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.