Share Pastebin
Guest
Public paste!

Skeleton Script by mw2player2009

By: a guest | Mar 20th, 2010 | Syntax: Java | Size: 6.97 KB | Hits: 168 | Expires: Never
Copy text to clipboard
  1. package scripts;
  2.  
  3. import com.sun.corba.se.spi.orbutil.fsm.State;
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6. import java.awt.Point;
  7. import java.io.BufferedReader;
  8. import java.io.FileReader;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.Map;
  15.  
  16. import org.rsbot.bot.Bot;
  17. import org.rsbot.event.listeners.PaintListener;
  18. import org.rsbot.script.Calculations;
  19. import org.rsbot.script.Constants;
  20. import org.rsbot.script.Methods;
  21. import org.rsbot.script.Script;
  22. import org.rsbot.script.ScriptManifest;
  23. import org.rsbot.script.Skills;
  24. import org.rsbot.script.wrappers.RSInterface;
  25. import org.rsbot.script.wrappers.RSItem;
  26. import org.rsbot.script.wrappers.RSNPC;
  27. import org.rsbot.script.wrappers.RSObject;
  28. import org.rsbot.script.wrappers.RSPlayer;
  29. import org.rsbot.script.wrappers.RSTile;
  30.  
  31.  
  32. @ScriptManifest(authors = { "Author" }, category = "Tutorial",
  33.                 name = "Skeleton Script", version = 1.0,
  34.                 description = "Description Box.")
  35.                
  36. public class skeleton extends Script implements PaintListener {
  37.        
  38.        
  39.         // Type values here...
  40.         public State state;
  41.        
  42.        
  43.        
  44.         //Runs at beginning of script.
  45.           public boolean onStart(final Map<String, String> args) {
  46.                
  47.         return true;
  48.        
  49.         }
  50.    
  51.  
  52.         // States of Script
  53.         public enum State {
  54.                 WALKING, POOPING, FARTING, SELLING;
  55.         }
  56.        
  57.        
  58.         // The actually function.
  59.         public int loop() {
  60.  
  61.                 return 0;
  62.         }
  63.        
  64.        
  65.          // Finish
  66.         public void onFinish() {
  67.                
  68.         }
  69.  
  70.         // Paint
  71.         public void onRepaint(final Graphics g) {
  72.                
  73.         }
  74.  
  75.        
  76.  
  77.         // Old functions.
  78.        
  79.         // Asking for four variables, lowest possible place you could be,
  80.         // highest, most left, and most right.
  81.         public boolean amIThere(int lowX, int highX, int lowY, int highY){
  82.                
  83.                 // Checks if I am between or on the most left place and the most right
  84.                 // place.
  85.                 if(getLocation().getX() < highX + 1 && getLocation().getX() > lowX - 1){
  86.                        
  87.                         // Checks if I am between or on the highest place and the lowest
  88.                         // place.
  89.                         if(getLocation().getY() < highY + 1 && getLocation().getY() > lowY - 1){
  90.                                        
  91.                                 return true;
  92.                                        
  93.                         }
  94.                
  95.                 }
  96.                
  97.         // If I am not within the plane of the four points, then
  98.                 // return false and say I am not there!
  99.                 return false;
  100.                
  101.         }
  102.        
  103.         public boolean walkGoodPath(final RSTile[] tilearray, final boolean forward) {
  104.                 int i;
  105.                 final int arrl = tilearray.length - 1;
  106.                 if (forward) {
  107.                         for (i = 0; i <= arrl; i++) {
  108.                                 if (distanceTo(tilearray[i]) < random(6, 8)) {
  109.                                         i++;
  110.                                         break;
  111.                                 }
  112.                         }
  113.                         if (i > arrl) {
  114.                                 i = arrl;
  115.                         }
  116.                         if (distanceTo(tilearray[arrl]) < random(8, 10)) {
  117.                                 walkTileMM(tilearray[arrl]);
  118.                                 return true;
  119.                         }
  120.                         if (distanceTo(getDestination()) < random(6, 8)) {
  121.                                 walkTileMM(tilearray[i]);
  122.                         }
  123.                 } else {
  124.                         for (i = arrl; i >= 0; i--) {
  125.                                 if (distanceTo(tilearray[i]) < random(6, 8)) {
  126.                                         i--;
  127.                                         break;
  128.                                 }
  129.                         }
  130.                         if (i < 0) {
  131.                                 i = 0;
  132.                         }
  133.                         if (distanceTo(tilearray[0]) < random(8, 10)) {
  134.                                 walkTileMM(tilearray[0]);
  135.                                 return true;
  136.                         }
  137.                         if (distanceTo(getDestination()) < random(6, 8)) {
  138.                                 walkTileMM(tilearray[i]);
  139.                         }
  140.                 }
  141.                 return false;
  142.         }
  143.  
  144.        
  145.         public boolean atBankItem(final int itemID, final String txt) {
  146.                 if (!isLoggedIn() || !bank.isOpen()) {
  147.                         return false;
  148.                 }
  149.                 final int[] itemArray = bank.getItemArray();
  150.                 for (int off = 0; off < itemArray.length; off++) {
  151.                         if (itemArray[off] == itemID) {
  152.                                 final Point p = bank.getItemPoint(off);
  153.                                 if (p.y < 87 || p.y > 291) {
  154.                                         while (bank.isOpen()) {
  155.                                                 bank.close();
  156.                                         }
  157.                                         while (isLoggedIn()) {
  158.                                                 logout();
  159.                                         }
  160.                                         log("Item not on bank screen. Logging out!");
  161.                                         stopScript();
  162.                                         return false;
  163.                                 }
  164.                                 moveMouse(p, 5, 5);
  165.                                 final long waitTime = System.currentTimeMillis()
  166.                                                 + random(50, 250);
  167.                                 boolean found = false;
  168.                                 while (!found && System.currentTimeMillis() < waitTime) {
  169.                                         wait(15);
  170.                                         if (getMenuItems().get(0).toLowerCase().contains(
  171.                                                         txt.toLowerCase())) {
  172.                                                 found = true;
  173.                                         }
  174.                                 }
  175.                                 if (found) {
  176.                                         clickMouse(true);
  177.                                         wait(random(150, 250));
  178.                                         return true;
  179.                                 }
  180.                                 clickMouse(false);
  181.                                 wait(random(150, 250));
  182.                                 return atMenu(txt);
  183.                         }
  184.                 }
  185.                 return false;
  186.         }
  187.  
  188.         public boolean atInventoryItem(final int itemID, final String option) {
  189.                 if (getCurrentTab() != Constants.TAB_INVENTORY
  190.                                 && !RSInterface.getInterface(Constants.INTERFACE_BANK)
  191.                                                 .isValid()
  192.                                 && !RSInterface.getInterface(Constants.INTERFACE_STORE)
  193.                                                 .isValid()) {
  194.                         openTab(Constants.TAB_INVENTORY);
  195.                 }
  196.                 final int[] items = getInventoryArray();
  197.                 final java.util.List<Integer> possible = new ArrayList<Integer>();
  198.                 for (int i = 0; i < items.length; i++) {
  199.                         if (items[i] == itemID) {
  200.                                 possible.add(i);
  201.                         }
  202.                 }
  203.                 if (possible.size() == 0) {
  204.                         return false;
  205.                 }
  206.                 final int idx = possible.get(random(0, possible.size()));
  207.                 final Point t = getInventoryItemPoint(idx);
  208.                 moveMouse(t, 5, 5);
  209.                 getMenuItems();
  210.                 final long waitTime = System.currentTimeMillis() + random(50, 250);
  211.                 boolean found = false;
  212.                 while (!found && System.currentTimeMillis() < waitTime) {
  213.                         wait(15);
  214.                         if (getMenuItems().get(0).toLowerCase().contains(
  215.                                         option.toLowerCase())) {
  216.                                 found = true;
  217.                         }
  218.                 }
  219.                 if (found) {
  220.                         clickMouse(true);
  221.                         wait(random(150, 250));
  222.                         return true;
  223.                 }
  224.                 clickMouse(false);
  225.                 wait(random(150, 250));
  226.                 return atMenu(option);
  227.         }
  228.  
  229.        
  230.  
  231.         public boolean atMenuItem(final int i) {
  232.                 if (!isMenuOpen()) {
  233.                         return false;
  234.                 }
  235.                 try {
  236.                         final RSTile menu = getMenuLocation();
  237.                         final List<String> items = getMenuItems();
  238.                         int longest = 0;
  239.                         for (final String s : items) {
  240.                                 if (s.length() > longest) {
  241.                                         longest = s.length();
  242.                                 }
  243.                         }
  244.                         final int xOff = random(4, longest * 4);
  245.                         final int yOff = random(21, 29) + 15 * i;
  246.                         clickMouse(menu.getX() + xOff, menu.getY() + yOff, 2, 2, true);
  247.                         return true;
  248.                 } catch (final Exception e) {
  249.                         e.printStackTrace();
  250.                         return false;
  251.                 }
  252.         }
  253.  
  254.         public boolean atTile(final RSTile tile, final String option) {
  255.                 final Point p = Calculations.tileToScreen(tile);
  256.                 p.x += random(-5, 6);
  257.                 p.y += random(-5, 6);
  258.                 if (p.x < 0 || p.y < 0) {
  259.                         return false;
  260.                 }
  261.                 moveMouse(p);
  262.                 // wait(random(100,150));
  263.                 getMenuItems();
  264.                 final long waitTime = System.currentTimeMillis() + random(50, 250);
  265.                 boolean found = false;
  266.                 while (System.currentTimeMillis() < waitTime && !found) {
  267.                         wait(15);
  268.                         found = getMenuItems().get(0).toLowerCase().contains(
  269.                                         option.toLowerCase());
  270.                 }
  271.                 if (found) {
  272.                         clickMouse(true);
  273.                         wait(random(150, 300));
  274.                         return true;
  275.                 }
  276.                 clickMouse(false);
  277.                 wait(random(150, 300));
  278.                 return atMenu(option);
  279.         }
  280.  
  281.         public int bankCount(final int itemID) {
  282.                 final int[] itemArray = bank.getItemArray();
  283.                 int count = 0;
  284.                 for (final int element : itemArray) {
  285.                         if (element == itemID) {
  286.                                 count++;
  287.                         }
  288.                 }
  289.                 return count;
  290.         }
  291.  
  292.  
  293.  
  294. }