Advertisement
Guest User

Combat

a guest
Jun 27th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | None | 0 0
  1. import org.osbot.script.Script;
  2. import org.osbot.script.ScriptManifest;
  3. import org.osbot.script.rs2.model.NPC;
  4. import org.osbot.script.rs2.model.Player;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. import javax.swing.*;
  9.  
  10. @ScriptManifest(name = "Combat bot", author = "Merccy", version = 1D, info = "Kill some low level monsters")
  11. public class CombatBotStream extends Script {
  12.  
  13.     // Option
  14.     public boolean guiWait;
  15.     public String monsterToKillName;
  16.  
  17.     private NPC monster;
  18.  
  19.     public void onStart() {
  20.     log("Combot bot has started");
  21.     CombatBotStreamGUI g = new CombatBotStreamGUI();
  22.     guiWait = true;
  23.     g.setVisible(true);
  24.     while(guiWait){
  25.        
  26.     }
  27.     g.dispose();
  28.     }
  29.  
  30.     public int onLoop() {
  31.     try {
  32.         BotStates state = getState();
  33.         handleState(state);
  34.     } catch (InterruptedException ex) {
  35.     }
  36.     return 50;
  37.     }
  38.  
  39.     public void searchForEnemy() throws InterruptedException {
  40.     NPC m = closestAttackableNPCForName(this.monsterToKillName);
  41.     if (m != null && !m.isUnderAttack()) {
  42.         log("Got monster");
  43.         this.monster = m;
  44.         if(!m.isVisible()){
  45.         this.client.moveCameraToEntity(m);
  46.         sleep(random(250,500));
  47.         }
  48.     }
  49.     }
  50.  
  51.     public void attackEnemy() throws InterruptedException {
  52.     log("Attacking");
  53.     this.monster.interact("Attack");
  54.     }
  55.  
  56.     public void handleState(BotStates state) throws InterruptedException {
  57.     switch (state) {
  58.     case Waiting:
  59.         this.searchForEnemy();
  60.         this.attackEnemy();
  61.         break;
  62.     }
  63.     }
  64.  
  65.     public BotStates getState() {
  66.     Player player = this.client.getMyPlayer();
  67.     if(player.isMoving() || player.isAnimating() || (this.monster != null && player.isFacing(this.monster))){
  68.         return BotStates.Attacking;
  69.     }
  70.     return BotStates.Waiting;
  71.     }
  72.  
  73.     public enum BotStates {
  74.     Waiting, Attacking, Eating
  75.     }
  76.    
  77.     public class CombatBotStreamGUI extends JFrame {
  78.         public CombatBotStreamGUI() {
  79.         initComponents();
  80.         }
  81.  
  82.         private void button1ActionPerformed(ActionEvent e) {
  83.         String s = textField1.getText();
  84.         if(s != null){
  85.             monsterToKillName = s;
  86.         }else{
  87.             monsterToKillName = "Goblin";
  88.         }
  89.         guiWait = false;
  90.         }
  91.  
  92.         private void initComponents() {
  93.         // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
  94.         // Generated using JFormDesigner Evaluation license - Henk Tenk
  95.         label1 = new JLabel();
  96.         label2 = new JLabel();
  97.         textField1 = new JTextField();
  98.         button1 = new JButton();
  99.  
  100.         //======== this ========
  101.         setTitle("CombatBotStream Settings");
  102.         Container contentPane = getContentPane();
  103.         contentPane.setLayout(null);
  104.  
  105.         //---- label1 ----
  106.         label1.setText("CombatBotStream Settings");
  107.         label1.setFont(new Font("Segoe UI", Font.PLAIN, 24));
  108.         contentPane.add(label1);
  109.         label1.setBounds(new Rectangle(new Point(135, 15), label1.getPreferredSize()));
  110.  
  111.         //---- label2 ----
  112.         label2.setText("Monster to kill (name): ");
  113.         contentPane.add(label2);
  114.         label2.setBounds(25, 60, 130, label2.getPreferredSize().height);
  115.         contentPane.add(textField1);
  116.         textField1.setBounds(155, 55, 350, textField1.getPreferredSize().height);
  117.  
  118.         //---- button1 ----
  119.         button1.setText("Start");
  120.         button1.addActionListener(new ActionListener() {
  121.             @Override
  122.             public void actionPerformed(ActionEvent e) {
  123.             button1ActionPerformed(e);
  124.             }
  125.         });
  126.         contentPane.add(button1);
  127.         button1.setBounds(new Rectangle(new Point(230, 95), button1.getPreferredSize()));
  128.  
  129.         { // compute preferred size
  130.             Dimension preferredSize = new Dimension();
  131.             for(int i = 0; i < contentPane.getComponentCount(); i++) {
  132.             Rectangle bounds = contentPane.getComponent(i).getBounds();
  133.             preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  134.             preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  135.             }
  136.             Insets insets = contentPane.getInsets();
  137.             preferredSize.width += insets.right;
  138.             preferredSize.height += insets.bottom;
  139.             contentPane.setMinimumSize(preferredSize);
  140.             contentPane.setPreferredSize(preferredSize);
  141.         }
  142.         pack();
  143.         setLocationRelativeTo(getOwner());
  144.         // JFormDesigner - End of component initialization  //GEN-END:initComponents
  145.         }
  146.  
  147.         // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
  148.         // Generated using JFormDesigner Evaluation license - Henk Tenk
  149.         private JLabel label1;
  150.         private JLabel label2;
  151.         private JTextField textField1;
  152.         private JButton button1;
  153.         // JFormDesigner - End of variables declaration  //GEN-END:variables
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement