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
  • Try asking for help in the chatbox
  • How to make a combat method that doesn't suck


    RealEngine
     Share

    Recommended Posts

    We all use combat methods that get the player in combat and player interacting !=null

     

    The problem with these is that they are awful. When in combat they will frequently return false because of the few tick delay between attacking and getting attacked and then run off trying to attack something else.

    I don't know how you get around this over at dreambot, but here is how I did it.

    (basically adds a delay after after not in combat to avoid the bot returning false for incombat method, thus not running around clicking shit)

     

     

     

    make a bool for incombat and isrunning

     public boolean isruning;
        public boolean inCombatBool = false; 

    next in your onstart method, make a new thread that does the following

    isruning = true;
    
    
    Thread t = new Thread(() -> {
                int x = 0;
                while (isruning) {
                    if ((getLocalPlayer().isInCombat() && getLocalPlayer().getInteractingCharacter() != null) || getLocalPlayer().getAnimation() != -1) {
                        inCombatBool = true;
                        x=0;
                    } else if (x > 8) {
                        inCombatBool = false;
                        x = 0;
                    }
                    x++;
                    log(String.valueOf(inCombatBool));
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start(); 

    now in your loop 

    if (!inCombatBool) {
                attack();
                sleep(Calculations.random(3000, 4000));
            }
    

    and the method being called 

     public void attack() {
            NPC slayerTask = getNpcs().closest(npc -> npc != null && npc.getName() != null && !npc.isInCombat());
            if (slayerTask != null) {
                if (slayerTask.interact("Attack")) {
                    changeStatus("Attacking");
                    sleepUntil(() -> getLocalPlayer().isInCombat() || getLocalPlayer().getInteractingCharacter() != null, Calculations.random(5000, 7000));
                }
            }
    
    
        }

    lastly on your onExit

    @Override
        public void onExit() {
            super.onExit();
            isruning = false;
        }
    

     

     

    Edited by RealEngine
    Link to comment
    Share on other sites

    • 4 months later...
    • 6 months later...

    Hey, I just finished trying this out and it's unfortunately not waiting long enough before attacking the next NPC. I have tried increasing the delay but it doesn't seem to be working.

     

    Also, the part of the code 

     

    changeStatus("Attacking"):

     

    Had to make a 

     

    private void changeStatus(String attacking) {

    }

     

    to function properly.

     

     

    I am pretty sure nothing is incorrect from yours. I did not copy and paste it so I could get a better understanding of it and for the most part I get it.

     

    I little bit of help on the matter would be awesome?

     

    Edit: I fixed it! :]

    Edited by PancakePunche
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.