Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.osbot.script.Script;
- import org.osbot.script.ScriptManifest;
- import org.osbot.script.rs2.model.NPC;
- import org.osbot.script.rs2.model.Player;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- @ScriptManifest(name = "Combat bot", author = "Merccy", version = 1D, info = "Kill some low level monsters")
- public class CombatBotStream extends Script {
- // Option
- public boolean guiWait;
- public String monsterToKillName;
- private NPC monster;
- public void onStart() {
- log("Combot bot has started");
- CombatBotStreamGUI g = new CombatBotStreamGUI();
- guiWait = true;
- g.setVisible(true);
- while(guiWait){
- }
- g.dispose();
- }
- public int onLoop() {
- try {
- BotStates state = getState();
- handleState(state);
- } catch (InterruptedException ex) {
- }
- return 50;
- }
- public void searchForEnemy() throws InterruptedException {
- NPC m = closestAttackableNPCForName(this.monsterToKillName);
- if (m != null && !m.isUnderAttack()) {
- log("Got monster");
- this.monster = m;
- if(!m.isVisible()){
- this.client.moveCameraToEntity(m);
- sleep(random(250,500));
- }
- }
- }
- public void attackEnemy() throws InterruptedException {
- log("Attacking");
- this.monster.interact("Attack");
- }
- public void handleState(BotStates state) throws InterruptedException {
- switch (state) {
- case Waiting:
- this.searchForEnemy();
- this.attackEnemy();
- break;
- }
- }
- public BotStates getState() {
- Player player = this.client.getMyPlayer();
- if(player.isMoving() || player.isAnimating() || (this.monster != null && player.isFacing(this.monster))){
- return BotStates.Attacking;
- }
- return BotStates.Waiting;
- }
- public enum BotStates {
- Waiting, Attacking, Eating
- }
- public class CombatBotStreamGUI extends JFrame {
- public CombatBotStreamGUI() {
- initComponents();
- }
- private void button1ActionPerformed(ActionEvent e) {
- String s = textField1.getText();
- if(s != null){
- monsterToKillName = s;
- }else{
- monsterToKillName = "Goblin";
- }
- guiWait = false;
- }
- private void initComponents() {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- // Generated using JFormDesigner Evaluation license - Henk Tenk
- label1 = new JLabel();
- label2 = new JLabel();
- textField1 = new JTextField();
- button1 = new JButton();
- //======== this ========
- setTitle("CombatBotStream Settings");
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("CombatBotStream Settings");
- label1.setFont(new Font("Segoe UI", Font.PLAIN, 24));
- contentPane.add(label1);
- label1.setBounds(new Rectangle(new Point(135, 15), label1.getPreferredSize()));
- //---- label2 ----
- label2.setText("Monster to kill (name): ");
- contentPane.add(label2);
- label2.setBounds(25, 60, 130, label2.getPreferredSize().height);
- contentPane.add(textField1);
- textField1.setBounds(155, 55, 350, textField1.getPreferredSize().height);
- //---- button1 ----
- button1.setText("Start");
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(new Rectangle(new Point(230, 95), button1.getPreferredSize()));
- { // compute preferred size
- Dimension preferredSize = new Dimension();
- for(int i = 0; i < contentPane.getComponentCount(); i++) {
- Rectangle bounds = contentPane.getComponent(i).getBounds();
- preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
- preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
- }
- Insets insets = contentPane.getInsets();
- preferredSize.width += insets.right;
- preferredSize.height += insets.bottom;
- contentPane.setMinimumSize(preferredSize);
- contentPane.setPreferredSize(preferredSize);
- }
- pack();
- setLocationRelativeTo(getOwner());
- // JFormDesigner - End of component initialization //GEN-END:initComponents
- }
- // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
- // Generated using JFormDesigner Evaluation license - Henk Tenk
- private JLabel label1;
- private JLabel label2;
- private JTextField textField1;
- private JButton button1;
- // JFormDesigner - End of variables declaration //GEN-END:variables
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement