You are not connected. Please login or register

Adding Scripts to RSBot 2

Go down  Message [Page 1 of 1]

1Adding Scripts to RSBot 2  Empty Adding Scripts to RSBot 2 Wed Nov 03, 2010 4:59 pm

Jimmy 9222

Jimmy 9222
Admin

1) Make sure you have downloaded and installed the latest JDK SE from http://java.sun.com/javase/downloads/index.jsp (JDK 6 Update 20). If you are running a relatively new computer, it might be running 64-bit windows rather than the typical 32-bit version. In this case you must select "Windows x64" rather than "Windows" when downloading the JDK. If you are not sure which version of Windows you have, you can easily find out using the following guide: http://support.microsoft.com/kb/827218.

2) Open up RSBot (the .jar file that you have downloaded from powerbot.org) if you have not done so before. If you have opened it before, then you do not have to open it up again (although you can if you want to), simply make sure that you have opened it AT LEAST ONCE since you downloaded it.

3) RSBot will have created some folders for you in your Documents folder. Open up "Documents" ("My Documents" on Windows XP) and open up the folder "RSBot". Within here you will see a folder called "Scripts".

4) Download the script you want and as save it into the "Sources" folder inside "Scripts". Here is how to do so:

Some scripters will give you a link to the script, which you can click on to download it. In this case, as long as you download the ".java" file, you simply have to move it into the "Sources" folder in your "Scripts" folder in your "RSBot" folder. Otherwise, if the code itself is posted on the forums, you need to copy it all and paste it into a new Notepad document (Start > All Programs > Accessories > Notepad). Near the top of all that code (below all the lines that start with 'import') you will see the words 'public class xxxxx extends Script'. The xxxxx will be the name of the script. Save the file as xxxxx.java (this is case sensitive!).

Example:

Code:

Code:
import java.awt.Graphics;

import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Players;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.util.Filter;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSObject.Type;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors = { "Speed" }, name = "SpeedIvy", version = 1.01, keywords = { "Woodcutting", "Ivy" }, description = "Cuts ivy in any location.")
public class SpeedIvy extends Script implements PaintListener, ServerMessageListener {

   private RSTile currentIvy;
   private int ivyChopped;
   private char direction = 'f';
   private long startTime, minutes, hours, seconds, runTime;
   private int startXP;
   private static final int[] NESTS = { 5070, 5071, 5072, 5073, 5074, 5075, 5076, 7413, 11966 };
   private static final int[] IVY_ID = { 46318, 46320, 46322, 46324 };

   public boolean onStart() {
      mouse.setSpeed(random(3, 6));
      return true;
   }

   private boolean isBusy() {
      int timesBusy = 0;
      int timesNotBusy = 0;
      for (int i = 0; i < 10; i++) {
         if (players.getMyPlayer().getAnimation() != -1 || getMyPlayer().isInCombat() || getMyPlayer().isMoving()
               || !getMyPlayer().isIdle())
            timesBusy++;
         else
            timesNotBusy++;
         sleep(random(150, 200));
      }
      return timesBusy >= timesNotBusy;
   }

   private int canChop() {
      while (getMyPlayer().isMoving())
         sleep(random(300, 500));
      return random(300, 500);
   }

   public int loop() {
      if (startTime == 0 && skills.getRealLevel(Skills.CONSTITUTION) > 1) {
         startTime = System.currentTimeMillis();
         startXP = skills.getCurrentExp(Skills.WOODCUTTING);
      }
      if (groundItems.getNearest(NESTS) != null) {
         groundItems.getNearest(NESTS).doAction("Take");
         return canChop();
      }

      if (isBusy()) {
         if (random(0, 5) > 3) {
            switch (random(1, 9)) {
            case 1:
               camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
               break;
            case 2:
               mouse.move((int) ((mouse.getLocation().x * 3.5) / 2.5) + random(10, 30),
                     ((int) ((mouse.getLocation().y * 3.5) / 2.5) + random(10, 30)));
               break;
            case 3:
               mouse.move((int) ((mouse.getLocation().x * 3.5) / 2.5) + random(10, 30),
                     ((int) ((mouse.getLocation().y * 3.5) / 2.5) + random(10, 30)));
               camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
               break;

            case 5:
               camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
               break;
            case 6:
               final RSObject[] obj = objects.getAll(new Filter<RSObject>() {
                  public boolean accept(RSObject t) {
                     return t.isOnScreen();
                  }
               });
               if (obj.length == 0) {
                  break;
               }
               final RSObject ran = obj[random(0, obj.length - 1)];
               if (ran.getType().equals(RSObject.Type.INTERACTABLE)) {
                  ran.doAction("Examine");
               }
               break;
            case 7:
               RSPlayer play = players.getNearest(Players.ALL_FILTER);

               if (play.isOnScreen()) {
                  mouse.move(play.getScreenLocation());
                  sleep(random(300, 800));

               }
               break;
            case 8:
               final RSObject ivy = objects.getNearest(new Filter<RSObject>() {
                  public boolean accept(final RSObject t) {
                     for (final int i : IVY_ID) {
                        if (t.getType().equals(Type.WALL_DECORATION) && !t.getLocation().equals(currentIvy)
                              && t.getID() == i) {
                           return true;
                        }
                     }
                     return false;
                  }
               });
               ivy.doHover();
               sleep(random(900, 1800));
               break;
            default:
               break;
            }
         }

      } else {
         final RSObject ivy = objects.getNearest(new Filter<RSObject>() {
            public boolean accept(final RSObject t) {
               for (final int i : IVY_ID) {
                  if (t.getType().equals(Type.WALL_DECORATION) && t.getID() == i) {
                     return true;
                  }
               }
               return false;
            }
         });
         if (ivy != null) {
            final RSTile ivyTile = ivy.getLocation();
            currentIvy = ivyTile;
            if (direction == 'f') {
               ivyFail(ivy, 0);
            } else {
               camera.setCompass(direction);
               if (!ivy.doAction("Chop"))
                  ivyFail(ivy, 0);
            }
            return canChop();
         }
      }
      return random(500, 700);
   }

   private boolean ivyFail(final RSObject ivy, int i) {
      if (i > 3) {
         return ivy.doAction("Chop");
      }
      switch (i) {
      case 0:
         direction = 'n';
         camera.setCompass('n');
         break;
      case 1:
         direction = 'e';
         camera.setCompass('e');
         break;
      case 2:
         direction = 's';
         camera.setCompass('s');
         break;
      case 3:
         direction = 'w';
         camera.setCompass('w');
         break;
      }
      ivy.doAction("Chop");
      canChop();
      return isBusy() ? true : ivyFail(ivy, ++i);

   }

   public void serverMessageRecieved(final ServerMessageEvent e) {
      if (e.getMessage().contains("some")) {
         ivyChopped++;
      }

   }

   public void onRepaint(final Graphics g) {
      runTime = System.currentTimeMillis() - startTime;
      seconds = runTime / 1000;
      if (seconds >= 60) {
         minutes = seconds / 60;
         seconds -= (minutes * 60);
      }
      if (minutes >= 60) {
         hours = minutes / 60;
         minutes -= (hours * 60);
      }
      final int xpGained = skills.getCurrentExp(Skills.WOODCUTTING) - startXP;
      g.drawString("SpeedIvy by Speed.", 15, 30);
      g.drawString("Run time: " + hours + ":" + minutes + ":" + seconds + ".", 15, 45);
      g.drawString("Ivy Chopped: " + ivyChopped + ".", 15, 60);
      g.drawString("XP Gained: " + xpGained + ".", 15, 75);
   }
}

You would save the script above as SpeedIvy.java

5) Go back to your "RSBot" folder and click "Compile-Scripts". This will convert all your scripts into .class files (which RSBot will be able to load in). If you pasted the script correctly, you will now see that the script has been added when you go to File > Run Script. There is no need to restart RSBot, as the scripts will be loaded in every time you do File > Run Script.

If you paste a script in incorrectly, then RSBot will not load in some of your other scripts. If this happens delete the .java file and try again or contact the author of the script.

You should be good to go now, and able to add any script you want. However, if you are having problems, perhaps the following section of answers to frequently asked questions will help you out.

FAQs:

1) When I compile I get the following:

Code:

Code:
Note: scripts\SpeedIvy.java uses or overides a deprecated API.
Note: Recompile with -Xlint:deprecation for details

Answer: You can ignore any lines with 'Note:' at the beginning. This is just a note to scripters. This file has compiled fine. Some scripts will give these notes, most will not.

2) When I compile I get the following:

Code:

Code:
Scripts\SpeedIvy.java:284: reached end of file while parsing
}
^
1 error

Answer: You have not copied the script correctly. Make sure you copy everything. You have probably missed out a '}' at the end of the script.

3) When I compile I get the following:

Code:

Code:
Path file does not exist. Please run RSBot and try again.

Answer: Open up RSBot (the .jar) and compile again.

Original post by: Jacmob.
At: http://www.powerbot.org/vb/showthread.php?t=115466

https://theelitegamers.darkbb.com

Back to top  Message [Page 1 of 1]

Similar topics

-

» rs bot adding scripts

Permissions in this forum:
You cannot reply to topics in this forum

 

How to make a forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com