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
  • How to make a combat script


    qbots

    Recommended Posts

    Making a combat script is kind of trivial if you know what you are doing, but for those of you who are new to scripting this may help you.

     

    Step 1: Finding the proper NPC to kill

     

    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    @ScriptManifest(name = "TutCombat",author = "qbots", version = 1.0, category = Category.COMBAT)
    public class Combat extends AbstractScript {
    
        @Override
        public int onLoop() {
            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
            if(currentNpc != null) {
                log("We have found a " + currentNpc.getName() + " to kill!");
            }
            return 100;
        }
        private NPC currentNpc; //Let's make this a global variable so we dont have to create a new one each loop 
        public String npcName = "Giant rat"; //This will be changed with our GUI later on
    }
    
    

     

     

     

    Step 2: Killing our target

     

    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    @ScriptManifest(name = "TutCombat",author = "qbots", version = 1.0, category = Category.COMBAT)
    public class Combat extends AbstractScript {
    
        @Override
        public int onLoop() {
            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
            if(currentNpc != null) { //does the npc exist?
                if(!getLocalPlayer().isInCombat() && getLocalPlayer().getInteractingCharacter() == null) { //Make sure we aren't in combat or interacting with something
                    if(currentNpc.interact("Attack")) { //currentNpc will return true if we succesfully attacked the rat, if that happens we want to wait a bit to make sure we are in combat
                        sleepUntil(() -> getLocalPlayer().isInCombat() || getLocalPlayer().getInteractingCharacter() != null, 2000); //Wait a max of 2 seconds or until we are in combat
                    }
                    return 100;
                } else {
                    return 100;
                }
            }
            return 100;
        }
        private NPC currentNpc; //Let's make this a global variable so we dont have to create a new one each loop 
        public String npcName = "Giant rat"; //This will be changed with our GUI later on
    }
    
    

     

     

    More will come soon. Next will be eating!

    Link to comment
    Share on other sites

    Hey man thanks for the tutorial

    i have a question on this line

            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
    

    so if i wanted to find rats for example it would be like this?

            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(Rat) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
    
    Link to comment
    Share on other sites

     

    Hey man thanks for the tutorial

    i have a question on this line

            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
    

    so if i wanted to find rats for example it would be like this?

            currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(Rat) && !npc.isInCombat() && npc.getInteractingCharacter() == null);
    

    No, you would simple change the variable at the bottom of the script.

    For example: public string npcName = "Rat";

    Link to comment
    Share on other sites

    I dont think having beginners do lambada expressions is a very good idea. Never the less, good job on the tutorial :D

    This is moreso a "Show people how combat works"

     

    Lambdas r better so might as well show them how to use them :P

    Link to comment
    Share on other sites

    This is moreso a "Show people how combat works"

     

    Lambdas r better so might as well show them how to use them :P

    Yeah i agree that Lambdas are better, but so is using the Task system for doing various things. My point is that if your target audience doesn't know how to make a combat script, they probably wont understand lambda expressions.

    Sorry if i sound like a dick. I just read this in a sassy tone and it makes me sound like a dick xD

    Link to comment
    Share on other sites

    Yeah i agree that Lambdas are better, but so is using the Task system for doing various things. My point is that if your target audience doesn't know how to make a combat script, they probably wont understand lambda expressions.

    Sorry if i sound like a dick. I just read this in a sassy tone and it makes me sound like a dick xD

    wasnt being sassy lol. just saying :)

     

    i guess i can add in how to do it without lambdas

    Link to comment
    Share on other sites

    wasnt being sassy lol. just saying :)

     

    i guess i can add in how to do it without lambdas

    yeah just like a regular filter would be dope

    Link to comment
    Share on other sites

    This is moreso a "Show people how combat works"

     

    Lambdas r better so might as well show them how to use them :P

     

    IMO you should know what it looks like and how it works and before applying lambdas and then start learning and applying them. :3

    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.