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
  • Cow killer && Cowhide banker (First script)


    klongrich

    Recommended Posts

    package Tester.main;
    
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    @ScriptManifest(category = Category.MISC, name="HelloWorldTest", author="klongrich", version=1)
    public class main extends AbstractScript {
    
        private Area lumbridgeBank = new Area(3210, 3218, 3207, 3220, 2);
        private Area lumbridgeCows = new Area(3243, 3294, 3263, 3283);
    
        private static final Filter<NPC> CowFilter = new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                if (npc == null) {
                    return false;
                }
                return npc.getName().equals("Cow") && !npc.isHealthBarVisible();
            }
        };
    
        private void bank() {
           getDepositBox().open();
           getDepositBox().depositAllItems();
        }
    
        @Override
        public int onLoop() {
            GroundItem Cowhide = getGroundItems().closest("Cowhide");
    
            if (getLocalPlayer().isInCombat()) {
                //Do nothing
            }
            else if (getInventory().isFull()) {
                    getWalking().walk(lumbridgeBank.getRandomTile());
                    bank();
                    log("Seeing full Inventory");
            }
            else if (Cowhide != null && Cowhide.distance(getLocalPlayer()) < 3) {
                if (!getLocalPlayer().isAnimating()) {
                    if (Cowhide.interact("Take")) {
                        sleepUntil(() -> !Cowhide.exists(), 15000);
                    }
                }
            } else if (lumbridgeCows.contains(getLocalPlayer())) {
                NPC cow = getNpcs().closest(CowFilter);
                if (cow != null) {
                    cow.interact("Attack");
                }
            } else {
                getWalking().walk(lumbridgeCows.getRandomTile());
            }
            log("Running");
            return 1000;
        }
    }
    Link to comment
    Share on other sites

    I see this is your first script, so I'd like to give some pointers for a beginner. 

    First, I highly recommend dividing your process into states. For example, you might have an enum called State which contains Bank, Collect, Attack, and maybe Walk.

    Then have a function simply called GetState() which returns the state you want to be in based on the logic you have above. So GetState would run the conditionals like:

    State playerState;

    if (getInventory().isFull()) { playerState = State::Bank; } //(I mainly code in C++ so forgive me if im mixing languages, but the idea is here)

    elseif (!lumbridgeCows.contains(getLocalPlayer().getTile()) { playerState = State::Walk; }

    and so on.

     

    Then have functions that are run based on which state you are in using a switch or conditional chain:

    switch(GetState())

         case State::Bank:

                   Bank();

     

     

    Another tip would be to (personal preference) log your states/functions (that you find necessary) at the beginning of the function, rather than the end. The reason I say this is because in your code:

    getWalking().walk(lumbridgeBank.getRandomTile());

    bank();

    log("Seeing full Inventory");

    You are going to see "Seeing full inventory" after you watch your bot walk to the bank, which may be confusing (and useless) to know afterwards.

     

     

    Last tip (for beginners):

    rather than setting hard sleep times (return 1000;//or

    sleep(1000);

    Use Calculations.random(int a, int b) where a is the minimum sleep time desired, and b is the max. This helps to ensure that your bot isn't always acting exactly at the same times on the clock, helping lower ban rate.

    Link to comment
    Share on other sites

    Oh, also, while this isn't always required, I sometimes like verifying that my bot didn't do something crazy somehow before trying to do things like your function bank();

    I would have written:

    Bank()

    {

         if (lumbridgeBank.contains(getLocalPlayer.getTile())

         {

          //NOW banking is done

         }

        else

       {

        WalkToBank(); //or something of the sort

       }

    }

    Link to comment
    Share on other sites

    Ahh I see if you could see States it might be a little easier to see what's going on and Error checking here and there probably wouldn't be the worst idea. Thanks for the feedback! 

    Link to comment
    Share on other sites

    • 2 years later...

    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.