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
  • Scripting for DreamBot - Part 2 - Still a pretty simple Chicken Killer


    Ericthecmh
     Share

    Recommended Posts

    Another simple script, added some stuff to the previous one.

     

    Added in this tutorial:

     

    1. Accessing Skills
    2. Interacting with tabs
    3. WIdgets (also known as interfaces in other bots)
    4. Dialogues (clickToContinue)

    Code:

    import java.awt.*;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.event.EventHandler;
    import org.dreambot.api.methods.event.PaintEvent;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.tabs.Tab;
    import org.dreambot.api.methods.widget.Widget;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.utilities.impl.Condition;
    import org.dreambot.api.utilities.impl.Filter;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.widgets.WidgetChild;
    
    @ScriptManifest(author="Ericthecmh", category= Category.COMBAT, name="Chicken Killer", version=0.1, description="Simple tutorial script showing how to kill chickens")
    public class ChickenKiller extends AbstractScript{
    
        public void onStart(){
            log("Welcome to a boring Chicken Killer script!"); //Use log to print to the console
        }
    
        @Override
        public int onLoop() throws InterruptedException {
            getClient().disableIdleMouse();
            // Click away level up messages
            getDialogues().clickContinue();
            // Get my defence level
            if(getSkills().getRealLevel(Skill.DEFENCE) > 15){
                // If I've reached my goal, stop
                this.stop();
            }else if(getSkills().getRealLevel(Skill.STRENGTH) > 15 && getPlayerSettings().getConfig(43) != 3){ // 3 is defensive style
                // Switch to defensive
                // Open combat tab
                if(getTabs().getOpen() == Tab.COMBAT || getCombat().openTab()){
                    Widget combatTab = getWidgets().getWidget(593);
                    if(combatTab.isVisible()) {
                        // 15 is the child widget for the fourth (defensive) option
                        combatTab.getChild(15).interact();
                    }
                }
            }else if(getSkills().getRealLevel(Skill.ATTACK) > 15 && getPlayerSettings().getConfig(43) != 1){ // 1 is my aggressive style
                // Switch to aggressive
                if(getTabs().getOpen() == Tab.COMBAT || getCombat().openTab()){
                    WidgetChild child = getWidgets().getChildWidget(593, 7);
                    if(child != null && child.isVisible())
                        child.interact();
                }
            }
            return doAttack();
        }
    
        private int doAttack(){
            if (!getPlayers().myPlayer().isInCombat()) {
                NPC chicken = getNpcs().getClosest(new Filter<NPC>() {
                    @Override
                    public boolean match(NPC npc) {
                        // Note the use of .equals at the end. You cannot do == like in many other bots.
                        return npc != null && npc.getName().equals("Chicken") && npc.getActions().length > 0 && (!npc.isInCombat() || (npc.getInteractingCharacter() != null && npc.getInteractingCharacter().equals(getLocalPlayer())));
                    }
                });
    
                if(chicken == null)
                    return Calculations.random(300,600);
                try {
                    if (chicken.interact("Attack")) {
                        sleepUntil(new Condition() {
                            @Override
                            public boolean verify() {
                                return getPlayers().myPlayer().isInCombat();
                            }
                        },1000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return Calculations.random(300, 600); // Calculations.random to get random numbers
        }
    
        public void onPaint(Graphics g){
            g.setColor(new Color(247, 148, 230));
            g.drawString("DreamBot is awesome!", 100, 100);
            g.drawString("IsInCombat: " + getLocalPlayer().isInCombat(), 100, 120);
        }
    }
    
    
    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.