Jump to content

SimpleCombat by Foulwerp


Foulwerp

Recommended Posts

SIMPLE COMBAT

by Foulwerp

 

 

What it does:

  • Kills any monsters added to the list by name
  • Eats anything with the action of "Eat" meaning almost all foods
  • Will now stop if you are out of food and reach the low health
  • Loots items put on list by name

I made this due to the lack of decent combat scripts on this site. Most are broken or very poorly written. I'm releasing this open source so hopefully people can use it, learn from it, and add to it. If you use any part of it in your own script all I ask is that you give credit where credit is due.

 

Change Log

1.1

    Updated GUI. You can now press enter to after typing name in text box
    to add it to the list, or click the add button. If you click a name in 
    the list it will remove it.

    Added Eating it will eat almost any food. As well as logging out when out of food. 
    Not an optional feature.

    Added a simple paint to just show how much EXP was earned, and how much you are getting 
    an hour.

1.2
    
    Added Item Pickup by name only. 

    Made it so that it shouldn't attack mobs if they are unreachable, 
    such as outside a closed gate/door, or other side of a wall.

    You can keep GUIs open, allowing you to edit mobs and pickup items while the
    script is running.

Download SimpleCombat.jar

 

 

Source

 

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.canvas.paint.Painter;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;

@ScriptManifest(name = "SimpleCombat", author = "Foulwerp", version = 1.2, info = "Combat", logo = "")
public class SimpleCombat extends Script implements Painter {

    private ArrayList alist = new ArrayList<String>();
    private ArrayList plist = new ArrayList<String>();
    private static final DecimalFormat k = new DecimalFormat("#.#");
    private static final int[] skill = {0, 1, 2, 3, 4, 6};
    private static final String[] skillNames = {"Attack", "Defence", "Strength", "HitPoints", "Range", "Magic"};
    private static final Color[] skillColors = {new Color(145, 25, 25).brighter(), new Color(95, 115, 185),
            Color.GREEN.darker(), Color.WHITE.darker(), new Color(70, 95, 20).brighter(), new Color(95, 115, 230)};

    private long start;
    private int[] startXP;

    public void onStart() {
        new PickUp();
        new Attack();
        start = System.currentTimeMillis();
        startXP = new int[6];
        for (int i = 0; i < skill.length; i++) {
            startXP[i] = skills.getExperience(Skill.forId(skill[i]));
        }
    }

    public int onLoop() {
        Item food = inventory.getItem(new Filter<Item>() {
            public boolean match(Item item) {
                return item != null && Arrays.asList(item.getActions()).contains("Eat");
            }
        });
        if (skills.getDynamic(Skill.HITPOINTS) < (skills.getStatic(Skill.HITPOINTS) / 2)) {
            if (food != null) {
                food.interact("Eat");
                return random(500, 1000);
            }
            stop();
        }
        if (myPlayer().getInteracting() != null) {
            return random(750, 1000);
        }
        if (!inventory.isFull()) {
            if (myPlayer().isMoving()) {
                return random(500, 1000);
            }
            GroundItem pickup = groundItems.closest(new Filter<GroundItem>() {
                public boolean match(GroundItem groundItem) {
                    return plist.contains(groundItem.getName().toLowerCase()) && map.canReach(groundItem);
                }
            });
            if (pickup != null) {
                if (!pickup.isOnScreen()) {
                    camera.toEntity(pickup);
                    if (!pickup.isOnScreen()) {
                        getLocalWalker().walk(pickup);
                        return random(500, 1000);
                    }
                }
                pickup.interact("Take");
                return random(750, 1000);
            }
        }
        NPC interacting = npcs.closest(new Filter<NPC>() {
            public boolean match(NPC npc) {
                return npc.getInteracting() == myPlayer() && Arrays.asList(npc.getActions()).contains("Attack");
            }
        });
        NPC npc = interacting != null ? interacting : npcs.closest(new Filter<NPC>() {
            public boolean match(NPC npc) {
                return alist.contains(npc.getName().toLowerCase()) && npc.getHealth() > 0 && npc.isAttackable() && map.canReach(npc);
            }
        });
        if (npc == null) {
            return random(500, 1000);
        }
        if (!npc.isOnScreen()) {
            camera.toEntity(npc);
            if (!npc.isOnScreen()) {
                getLocalWalker().walk(npc);
                return random(500, 1000);
            }
        }
        npc.interact("Attack");
        camera.toTop();
        return random(750, 1000);
    }

    public void onPaint(Graphics2D g) {
        int y = 25, z = 16, w = 3, x = 5;
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Point m = mouse.getPosition();
        g.drawLine((int) m.getX() - 3, (int) m.getY(), (int) m.getX() + 3, (int) m.getY());
        g.drawLine((int) m.getX(), (int) m.getY() - 3, (int) m.getX(), (int) m.getY() + 3);
        g.setFont(new Font("Comic Sans MS", Font.PLAIN, 10));
        g.setColor(Color.BLACK);
        g.drawRect(w, 4, 200, 11);
        g.setColor(new Color(0, 0, 0, 220));
        g.fillRect(w, 4, 200, 11);
        g.setColor(Color.WHITE);
        g.drawString("SimpleCombat - Version 1.2", x, 12);
        double eph;
        int exp;
        for (int i = 0; i < 6; i++) {
            exp = (skills.getExperience(Skill.forId(skill[i])) - startXP[i]);
            if (exp > 0) {
                eph = (exp * 3600000D / (System.currentTimeMillis() - start));
                g.setColor(Color.BLACK);
                g.drawRect(w, z, 200, 11);
                g.setColor(new Color(0, 0, 0, 220));
                g.fillRect(w, z, 200, 11);
                g.setColor(skillColors[i]);
                g.drawString(skillNames[i] + ": " + k.format(exp / 1000D) + " K Earned - " + k.format(eph / 1000) + " K P/H", x, y);
                y += 11;
                z += 11;
            }
        }
    }

    class PickUp extends JFrame implements ActionListener, ListSelectionListener, KeyListener {

        JButton added = new JButton("Add");
        JButton start = new JButton("Done");
        JTextField input = new JTextField("");
        DefaultListModel model = new DefaultListModel();
        JList list = new JList(model);
        JScrollPane scroll = new JScrollPane(list);

        public PickUp() {
            setTitle("PickUp");
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setBounds(50, 50, 300, 210);
            setLayout(new BorderLayout());
            add(scroll, BorderLayout.PAGE_START);
            add(input, BorderLayout.CENTER);
            add(added, BorderLayout.LINE_END);
            add(start, BorderLayout.PAGE_END);
            added.addActionListener(this);
            start.addActionListener(this);
            input.addKeyListener(this);
            list.addListSelectionListener(this);
            setVisible(true);
            setResizable(false);
        }

        public void actionPerformed(ActionEvent e) {
            Object event = e.getSource();
            if (event == added) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    if (!alist.contains(s)) {
                        alist.add(s);
                    }
                }
                input.setText("");
            }
            if (event == start) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    plist.add(s);
                }
                setVisible(false);
            }
        }

        public void valueChanged(final ListSelectionEvent v) {
            if (v.getSource() == list) {
                String s = (String) list.getSelectedValue();
                if (s == null || s.isEmpty()) {
                    return;
                }
                model.removeElement(s);
            }
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    if (!alist.contains(s)) {
                        alist.add(s);
                    }
                }
                input.setText("");
            }
        }

        public void keyReleased(KeyEvent e) {
        }
    }

    class Attack extends JFrame implements ActionListener, ListSelectionListener, KeyListener {

        JButton added = new JButton("Add");
        JButton start = new JButton("Done");
        JTextField input = new JTextField("");
        DefaultListModel model = new DefaultListModel();
        JList list = new JList(model);
        JScrollPane scroll = new JScrollPane(list);

        public Attack() {
            setTitle("Attack");
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setBounds(100, 100, 300, 210);
            setLayout(new BorderLayout());
            add(scroll, BorderLayout.PAGE_START);
            add(input, BorderLayout.CENTER);
            add(added, BorderLayout.LINE_END);
            add(start, BorderLayout.PAGE_END);
            added.addActionListener(this);
            start.addActionListener(this);
            input.addKeyListener(this);
            list.addListSelectionListener(this);
            setVisible(true);
            setResizable(false);
        }

        public void actionPerformed(ActionEvent e) {
            Object event = e.getSource();
            if (event == added) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    if (!alist.contains(s)) {
                        alist.add(s);
                    }
                }
                input.setText("");
            }
            if (event == start) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    if (!alist.contains(s)) {
                        alist.add(s);
                    }
                }
                setVisible(false);
            }
        }

        public void valueChanged(final ListSelectionEvent v) {
            if (v.getSource() == list) {
                String s = (String) list.getSelectedValue();
                if (s == null || s.isEmpty()) {
                    return;
                }
                model.removeElement(s);
            }
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                model.addElement(input.getText());
                for (int i = 0; i < model.getSize(); i++) {
                    String s = model.get(i).toString().toLowerCase();
                    if (!alist.contains(s)) {
                        alist.add(s);
                    }
                }
                input.setText("");
            }
        }

        public void keyReleased(KeyEvent e) {
        }
    }
}
Edited by Foulwerp
  • Like 1
Link to comment
Share on other sites

 for (int i = 0; i < alist.toArray().length; i++) {
            log(alist.toArray()[i]);
  }

951f554243c6ed7abcfbc25b3dfe3b05.png

 

30a7ee87404cb7e2be98e825918a4480.png

 

http://crunchify.com/how-to-iterate-through-java-list-4-way-to-iterate-through-loop/

 

 

I know very poor programming it was put in just so that I could see that the list was actually logging the names, wasn't meant to stay. I guess I could of used list.get(i). I'm a little rusty havn't written any code in about 4 years. Thanks for the info though..

 

Link to comment
Share on other sites

for (int i = 0; i < alist.toArray().length; i++) {
            log(alist.toArray()[i]);
  }
951f554243c6ed7abcfbc25b3dfe3b05.png

 

30a7ee87404cb7e2be98e825918a4480.png

 

http://crunchify.com/how-to-iterate-through-java-list-4-way-to-iterate-through-loop/

  

I know very poor programming it was put in just so that I could see that the list was actually logging the names, wasn't meant to stay. I guess I could of used list.get(i). I'm a little rusty havn't written any code in about 4 years. Thanks for the info though..

wow botre way to be a dick :doge:
  • Like 1
Link to comment
Share on other sites

How do you move scripts into the current list of scripts to run? I'm not sure how to run anything but the ones on the mini screening where you choose scripts to run tongue.png

 

I would look in the tutorial section...

 

You would find the OSBot folder on your computer, in there will be a folder named Scripts. You then put the jar file in there and it will appear on the list of scripts you can run.

Made quite few updates let me know if there are any bugs or issues with the new stuff that was implemented.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 2 weeks later...

Since OP hasn't updated the download link for this script, i've recompiled it.

http://www.filedropper.com/showdownload.php/simplecombat

 

Did this because all other free combat bots were shit and i needed a working one, and it would be unfair to anyone that needs a bot that can actually loot items without paying for a premium one...   -    Looting, paint, eating and attacking work on this.

Scan or decompile the .jar if you must.

Enjoy.

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...