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
  • LivestockSlayer - Kills chicken/cows and banks!


    Software

    Recommended Posts

    Free project source (there aren't too many here). I'd appreciate it if you gave me credit if you use this in any way.

     

    Thanks, enjoy:

     

    LivestockSlayer.java

    package LivestockSlayer;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.skills.Skill;
    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;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.wrappers.items.Item;
    
    import java.awt.*;
    
    @ScriptManifest(category = Category.COMBAT, name = "Livestock Slayer", author = "Software", version = 1.0)
    public class LivestockSlayer extends AbstractScript{
        private Area chickenPen = new Area(3186, 3288, 3169, 3307, 0);
        private Area cowField = new Area(3240, 3298, 3265, 3255, 0);
        private Area bank = new Area(3210, 3220, 3206, 3215, 2);
        private LivestockSlayerGUI gui;
        private boolean isStarted;
        private int killCount = 0;
        private int boneCount = 0;
    
    
        @Override
        public void onStart() {
            for(Skill s : Skill.values()){ //Start all skill trackers.
                getSkillTracker().start(s, !getClient().getInstance().getScriptManager().isRunning());
            }
            gui = new LivestockSlayerGUI(this); //This gets both classes to work together.
            gui.setVisible(true); //Makes the GUI visible
        }
    
        @Override
        public int onLoop() {
            if(isStarted){
                Item food = getInventory().get(item -> item != null && item.hasAction("Eat"));
                if(getSkills().getBoostedLevels(Skill.HITPOINTS) < getSkills().getRealLevel(Skill.HITPOINTS)/2){
                    if(food != null && food.interact("Eat"))
                        sleep(400, 800);
                    else
                        stop(); //No more food left
                }
                if(gui.isBanking() && getInventory().isFull() && (!gui.getBuryBones() || !getInventory().contains("Bones"))){
                    if(bank.contains(getLocalPlayer())){
                        if(getBank().isOpen()){
                            if(getBank().depositAllExcept(item -> item != null && item.hasAction("Eat")))
                                getBank().close();
                        }else {
                            if (getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().equals("Bank booth") && gameObject.hasAction("Bank")).interact("Bank")) {
                                sleepUntil(() -> getBank().isOpen(), 10000);
                                return 10;
                            }
                        }
                    }else{
                        walkToArea(bank);
                    }
                }
    
                if((gui.isBanking() && !getInventory().isFull()) || !gui.isBanking())
                    if (gui.getKillCows()) { //Killing cows
                        if (areaContainsDestOrPlayer(cowField)) { //We're in our area
                            if (attack(getNpcs().closest(npc -> (npc.getName().equals("Cow") || npc.getName().equals("Cow calf")) && npc.hasAction("Attack") && !npc.isInCombat() && cowField.contains(npc) && getMap().canReach(npc)))) {
                                loot();
                                killCount++;
                            }
                            buryBones();
                        } else {
                            walkToArea(cowField); //We're not in our area, time to walk to it
                        }
                    } else if (gui.getKillChickens()) { //Killing chickens
                        if (areaContainsDestOrPlayer(chickenPen)) { //We're in our area
                            if (attack(getNpcs().closest(npc -> npc.getName().equals("Chicken") && npc.hasAction("Attack") && !npc.isInCombat() && chickenPen.contains(npc) && getMap().canReach(npc)))) {
                                loot();
                                killCount++;
                            }
                            buryBones();
                        } else {
                            walkToArea(chickenPen); //We're not in our area, time to walk to it
                        }
                    } else {
                        stop(); //Neither cows nor chickens were selected
                    }
    
            }
            return 500;
        }
    
        @Override
        public void onExit() {
            gui.dispose();
        }
    
        @Override
        public void onPaint(Graphics g2) {
            Graphics2D g = (Graphics2D) g2;
            g.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
            g.setColor(new Color(2, 255, 255, 50));
            g.fillRect(3,4,170,250);
    
            g.setColor(new Color(255, 255, 255));
            g.setFont(new Font("Bitstream Vera Sans", Font.BOLD, 13));
            g.drawString("Attack XP: " + getSkillTracker().getGainedExperience(Skill.ATTACK) + "(" + getSkillTracker().getGainedExperiencePerHour(Skill.ATTACK) + ")", 5, 20);
            g.drawString("Strength XP: " + getSkillTracker().getGainedExperience(Skill.STRENGTH) + "(" + getSkillTracker().getGainedExperiencePerHour(Skill.STRENGTH) + ")", 5, 40);
            g.drawString("Defence XP: " + getSkillTracker().getGainedExperience(Skill.DEFENCE) + "(" + getSkillTracker().getGainedExperiencePerHour(Skill.DEFENCE) + ")", 5, 60);
            g.drawString("Hitpoints XP: " + getSkillTracker().getGainedExperience(Skill.HITPOINTS) + "(" + getSkillTracker().getGainedExperiencePerHour(Skill.HITPOINTS) + ")", 5, 80);
    
            g.drawString(String.format("Total XP: %d(%d)", getSkillTracker().getGainedExperience(Skill.ATTACK) + getSkillTracker().getGainedExperience(Skill.STRENGTH)
                    + getSkillTracker().getGainedExperience(Skill.DEFENCE) + getSkillTracker().getGainedExperience(Skill.HITPOINTS), getSkillTracker().getGainedExperiencePerHour(Skill.ATTACK)
                    + getSkillTracker().getGainedExperiencePerHour(Skill.STRENGTH) + getSkillTracker().getGainedExperiencePerHour(Skill.DEFENCE) + getSkillTracker().getGainedExperiencePerHour(Skill.HITPOINTS)), 5, 120);
            g.drawString("Kills: " + killCount, 5, 140);
    
            if(gui.getBuryBones()){
                g.drawString("Prayer XP: " + getSkillTracker().getGainedExperience(Skill.PRAYER) + "(" + getSkillTracker().getGainedExperiencePerHour(Skill.PRAYER) + ")", 5, 180);
                g.drawString("Bones Burried: " + boneCount, 5, 200);
            }
        }
    
        /**
         ************************************************
         * METHODS
         ************************************************
         */
    
    
        /**
         * Setter for the |isStarted| variable
         * @[member='paramo61'] started
         */
        public void setStarted(boolean started) {
            isStarted = started;
        }
    
    
        /**
         * Loots the items we want, based off of what the user selects in the GUI
         */
        private void loot(){
            if(gui.getLootChickenBones() || gui.getLootCowBones()){
                pickUp("Bones");
            }
            if(gui.getLootChickenFeather()){
                pickUp("Feather");
            }
            if(gui.getLootChickenRawChicken()){
                pickUp("Raw chicken");
            }
            if(gui.getLootCowCowhide()){
                pickUp("Cowhide");
            }
            if(gui.getLootCowRawBeef()){
                pickUp("Raw beef");
            }
        }
    
    
        /**
         * Picks up a certain item off the ground based off of the string param.
         * @[member='paramo61'] itemName The item we'll be picking up.
         */
        private void pickUp(String itemName){
            if(Calculations.random(0,3) == 1) {
                int inventoryCount = getInventory().fullSlotCount();
                int featherCount = getInventory().count("Feather");
                GroundItem item = getGroundItems().closest(groundItem -> groundItem != null && groundItem.getName().equals(itemName));
                if (!getInventory().isFull() && item != null && item.interact("Take")) {
                    sleepUntil(() -> getInventory().fullSlotCount() > inventoryCount || featherCount < getInventory().count("Feather"), 6000);
                }
            }
        }
    
    
        /**
         * Randomized method, which will bury all the bones in the inventory if our inventory is full. If
         * our inventory is not full, it will bury a random amount of bones.
         */
        private void buryBones(){
            if(gui.getBuryBones()) {
                if (getInventory().contains("Bones")) {
                    if (getInventory().isFull()) {
                        getInventory().all().stream().filter(this::clickOnBone).forEach(item -> boneCount++);
                    } else {
                        if (Calculations.random(0, 20) == 1) {
                            for (int i = 0; i < Calculations.random(0, getInventory().count("Bones")); i++) {
                                for (Item item : getInventory().all()) {
                                    if (clickOnBone(item)) {
                                        boneCount++;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    
    
        /**
         * Clicks on an item in the inventory if the item is a bone
         * @[member='paramo61'] item The item we're going to click on
         * @return True if we successfully click on the bone, and it's no longer in our inventory.
         */
        private boolean clickOnBone(Item item){
            if(item != null && item.getName().equals("Bones")){
                int boneCount = getInventory().count("Bones");
                if(item.interact("Bury")){
                    if(sleepUntil(() -> getInventory().count("Bones") < boneCount, 2000)) {
                        sleep(300, 400);
                        return true;
                    }
                }
            }
            return false;
        }
    
    
        /**
         * Checks whether or not the player, or the player's destination, is inside the specified area.
         * @[member='paramo61'] area The area we're checking.
         * @return True if inside the area, False if not inside.
         */
        public boolean areaContainsDestOrPlayer(Area area){
            return area.contains(getLocalPlayer()) || (getClient().getDestination() != null && (area.contains(getClient().getDestination())));
        }
    
    
        /**
         * Attacks the nearest NPC provided by the parameter. Sleeps until no longer in combat if
         * we successfully attack the given npc
         * @[member='paramo61'] npc NPC we're going to attack
         */
        private boolean attack(NPC npc){
            if(npc != null){
                if(npc.interact("Attack")){
                    if(sleepUntil(() -> getLocalPlayer().isInCombat() || npc.isInCombat(), 6000)){ //If true, we're now attacking an NPC
                        if(sleepUntil(() -> !getLocalPlayer().isInCombat(), 60000))
                            return true;
                    }
                }
            }
            return false;
        }
    
    
        /**
         * Walks to the given area, passed in through parameters, then sleeps.
         * @[member='paramo61'] area The area we wish to walk to
         */
        private void walkToArea(Area area){
            if(getWalking().walk(area.getRandomTile()))
                walkingSleepUntil(area);
        }
    
    
        /**
         * Sleeps until a certain distance has been reached, either going up or down
         * (useful for stairs) or moving N/S/E/W by 4 tiles. Stop sleeping after 3 - 7
         * seconds if player didn't move far enough.
         * @[member='paramo61'] area The area we're walking to
         */
        public void walkingSleepUntil(Area area){
            int currTileX = getLocalPlayer().getTile().getX();
            int currTileY = getLocalPlayer().getTile().getY();
            int currTileZ = getLocalPlayer().getTile().getZ();
            sleepUntil(() -> area.contains(getLocalPlayer()) || getLocalPlayer().getTile().getX() > currTileX + 4 || getLocalPlayer().getTile().getY() > currTileY + 4 ||
                    getLocalPlayer().getTile().getX() < currTileX - 4 || getLocalPlayer().getTile().getY() < currTileY - 4 ||
                    getLocalPlayer().getTile().getZ() > currTileZ + 1 || getLocalPlayer().getTile().getZ() < currTileZ - 1, Calculations.random(3000, 7200));
        }
    }
    

    LivestockSlayerGUI.java

    /*
     * Created by JFormDesigner on Sat Jan 30 15:54:39 CST 2016
     */
    
    package LivestockSlayer;
    
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.*;
    import javax.swing.border.*;
    
    public class LivestockSlayerGUI extends JFrame {
        private LivestockSlayer ctx; //ctx stands for "context"
    
        public LivestockSlayerGUI(LivestockSlayer ctx) {
            this.ctx = ctx;
            initComponents();
        }
    
    
        private void switchCheckBoxState(JCheckBox clicking, JCheckBox...otherBox){
            if(clicking.isSelected()){
                for(JCheckBox jCheckBox : otherBox){
                    jCheckBox.setSelected(false);
                    jCheckBox.setEnabled(false); //Greys out the option to check cbKillChickens
                }
            }else{
                for(JCheckBox jCheckBox : otherBox){
                    jCheckBox.setEnabled(true); //Un-greys out the option to check cbKillChickens
                }
            }
        }
    
        private void initComponents() {
            startButton = new JButton();
            cbKillCows = new JCheckBox();
            cbKillChickens = new JCheckBox();
            cbBank = new JCheckBox();
            cbBurryBones = new JCheckBox();
            panel1 = new JPanel();
            cbLootChickenBones = new JCheckBox();
            cbLootChickenFeather = new JCheckBox();
            cbLootChickenRawChicken = new JCheckBox();
            panel2 = new JPanel();
            cbLootCowBones = new JCheckBox();
            cbLootCowCowhide = new JCheckBox();
            cbLootCowRawBeef = new JCheckBox();
    
            //======== this ========
            setTitle("Joker's Livestock Slayer");
            Container contentPane = getContentPane();
            contentPane.setLayout(null);
            setResizable(false);
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    ctx.stop();
                }
            });
    
            //---- startButton ----
            startButton.setText("Start");
            startButton.addActionListener(e -> {
                ctx.setStarted(true); //Sets our script to start running
                dispose(); //Gets rid of the GUI (the user input panel)
            });
            contentPane.add(startButton);
            startButton.setBounds(122, 148, 155, 40);
    
            //---- cbKillCows ----
            cbKillCows.setText("Kill Cows");
            cbKillCows.addActionListener(e -> switchCheckBoxState(cbKillCows, cbKillChickens, cbLootChickenBones, cbLootChickenFeather, cbLootChickenRawChicken));
            contentPane.add(cbKillCows);
            cbKillCows.setBounds(new Rectangle(new Point(10, 5), cbKillCows.getPreferredSize()));
    
            //---- cbKillChickens ----
            cbKillChickens.setText("Kill Chickens");
            cbKillChickens.addActionListener(e -> switchCheckBoxState(cbKillChickens, cbKillCows, cbLootCowBones, cbLootCowCowhide, cbLootCowRawBeef));
            contentPane.add(cbKillChickens);
            cbKillChickens.setBounds(new Rectangle(new Point(10, 38), cbKillChickens.getPreferredSize()));
    
            //---- cbBank ----
            cbBank.setText("Bank");
            contentPane.add(cbBank);
            cbBank.setBounds(new Rectangle(new Point(10, 71), cbBank.getPreferredSize()));
    
            //---- cbBurryBones ----
            cbBurryBones.setText("Bury bones");
            contentPane.add(cbBurryBones);
            cbBurryBones.setBounds(new Rectangle(new Point(10, 104), cbBurryBones.getPreferredSize()));
    
            //======== panel1 ========
            {
                panel1.setBorder(new TitledBorder("Chicken Loot"));
    
                panel1.setLayout(null);
    
                //---- cbLootChickenBones ----
                cbLootChickenBones.setText("Bones");
                panel1.add(cbLootChickenBones);
                cbLootChickenBones.setBounds(new Rectangle(new Point(10, 25), cbLootChickenBones.getPreferredSize()));
    
                //---- cbLootChickenFeather ----
                cbLootChickenFeather.setText("Feather");
                panel1.add(cbLootChickenFeather);
                cbLootChickenFeather.setBounds(new Rectangle(new Point(10, 57), cbLootChickenFeather.getPreferredSize()));
    
                //---- cbLootChickenRawChicken ----
                cbLootChickenRawChicken.setText("Raw chicken");
                panel1.add(cbLootChickenRawChicken);
                cbLootChickenRawChicken.setBounds(new Rectangle(new Point(10, 89), cbLootChickenRawChicken.getPreferredSize()));
            }
            contentPane.add(panel1);
            panel1.setBounds(135, 10, 125, 120);
    
            //======== panel2 ========
            {
                panel2.setBorder(new TitledBorder("Cow Loot"));
                panel2.setLayout(null);
    
                //---- cbLootCowBones ----
                cbLootCowBones.setText("Bones");
                panel2.add(cbLootCowBones);
                cbLootCowBones.setBounds(new Rectangle(new Point(10, 25), cbLootCowBones.getPreferredSize()));
    
                //---- cbLootCowCowhide ----
                cbLootCowCowhide.setText("Cowhide");
                panel2.add(cbLootCowCowhide);
                cbLootCowCowhide.setBounds(new Rectangle(new Point(10, 57), cbLootCowCowhide.getPreferredSize()));
    
                //---- cbLootCowRawBeef ----
                cbLootCowRawBeef.setText("Raw beef");
                panel2.add(cbLootCowRawBeef);
                cbLootCowRawBeef.setBounds(new Rectangle(new Point(10, 89), cbLootCowRawBeef.getPreferredSize()));
            }
            contentPane.add(panel2);
            panel2.setBounds(275, 10, 125, 120);
    
            contentPane.setPreferredSize(new Dimension(405, 205));
            pack();
            setLocationRelativeTo(getOwner());
        }
    
        /**
         *************************************
         * Getters
         *************************************
         */
        public boolean getKillCows() {
            return cbKillCows.isSelected();
        }
    
        public boolean getKillChickens() {
            return cbKillChickens.isSelected();
        }
    
        public boolean isBanking() {
            return cbBank.isSelected();
        }
    
        public boolean getBuryBones() {
            return cbBurryBones.isSelected();
        }
    
        public boolean getLootChickenBones() {
            return cbLootChickenBones.isSelected();
        }
    
        public boolean getLootChickenFeather() {
            return cbLootChickenFeather.isSelected();
        }
    
        public boolean getLootChickenRawChicken() {
            return cbLootChickenRawChicken.isSelected();
        }
    
        public boolean getLootCowBones() {
            return cbLootCowBones.isSelected();
        }
    
        public boolean getLootCowCowhide() {
            return cbLootCowCowhide.isSelected();
        }
    
        public boolean getLootCowRawBeef() {
            return cbLootCowRawBeef.isSelected();
        }
    
        private JButton startButton;
        private JCheckBox cbKillCows, cbKillChickens, cbBank, cbBurryBones, cbLootChickenBones,cbLootChickenFeather,cbLootChickenRawChicken;
        private JCheckBox cbLootCowBones, cbLootCowCowhide, cbLootCowRawBeef;
        private JPanel panel1, panel2;
    }
    
    
    Link to comment
    Share on other sites

    • 2 weeks 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.