Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 36.77 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //---------------------------------------------------------------------------
  2. //***************************************************************************
  3. //***************************************************************************
  4. //
  5. //             *             BE ORIGINAL              *
  6. //             *   DON'T COPY WORK THAT'S NOT YOURS   *
  7. //             *              xScriptx                *
  8. //
  9. //           You may learn from this script, but not copy.
  10. //
  11. //***************************************************************************
  12. //***************************************************************************
  13. //---------------------------------------------------------------------------
  14. //IMPORTS RSBOT
  15. import org.rsbot.script.wrappers.*;
  16. import org.rsbot.script.methods.*;
  17. import org.rsbot.script.util.*;
  18. import org.rsbot.event.listeners.*;
  19. import org.rsbot.script.Script;
  20. import org.rsbot.script.ScriptManifest;
  21. import org.rsbot.script.wrappers.RSTile;
  22. import org.rsbot.script.wrappers.RSNPC;
  23. import org.rsbot.script.wrappers.RSObject;
  24. import org.rsbot.script.util.WindowUtil;
  25. import org.rsbot.event.events.MessageEvent;
  26. import org.rsbot.util.GlobalConfiguration;
  27. //IMPORTS JAVA
  28. import java.util.regex.Matcher;
  29. import java.util.regex.Pattern;
  30. import java.awt.*;
  31. import java.lang.String.*;
  32. import java.io.*;
  33. import java.awt.Graphics;
  34. import java.awt.Graphics2D;
  35. import java.awt.Point;
  36. import java.awt.Rectangle;
  37. import java.awt.Color;
  38. import java.awt.Font;
  39. import java.awt.event.*;
  40. import java.awt.image.BufferedImage;
  41. import java.io.BufferedReader;
  42. import java.io.InputStreamReader;
  43. import java.io.IOException;
  44. import java.net.URL;
  45. import java.net.URLConnection;
  46. import java.net.MalformedURLException;
  47. import javax.imageio.ImageIO;
  48.  
  49. @ScriptManifest(authors = {"<html><style>div{color:green;}</tyle><div><h3>xScriptx<h3></div></html>"}, keywords = {"Chopper"}, name = "xScriptxChopper", description = "<html><style>div{background-color:blue; color:white;}</tyle><div><h3>PowerChops any Willow Tree - By xScriptx<h3></div></html>", version = 3.0)
  50. public class xScriptxChopper extends Script implements PaintListener, MouseListener, MessageListener {
  51.     /*       Variables & Constants       */
  52.     //ETC
  53.  
  54.     private gui gui;
  55.     private Point mousePoint;
  56.     private static final Pattern UPDATER_VERSION_PATTERN = Pattern.compile("version\\s*=\\s*([0-9.]+)");
  57.     //BOOLEAN
  58.     private boolean hide = false, logout = false, dropping = false;
  59.     private boolean startScript = false;
  60.     //IMAGES
  61.     private Rectangle closeFixed = new Rectangle(480, 459, 30, 13), close = new Rectangle(466, 111, 30, 13);
  62.     private BufferedImage normal = null, clicked = null;
  63.     private final Image logo = getImage("http://img156.imageshack.us/img156/763/xscriptx.png");
  64.     private final Image back = getImage("http://img573.imageshack.us/img573/7755/backr.png");
  65.     //INT
  66.     private int WillowTrees[] = {5551, 5552, 5553}, Hatchets[] = {1349, 1351, 1353, 1355, 1357, 1359, 1361, 6739, 13470};
  67.     private int levelsGained;
  68.     private int storeNpc = 531;
  69.     private int bankMode;
  70.     private int mode;
  71.     private int BankId;
  72.     private int startexp = 0;
  73.     private int startlevel;
  74.     //STRING
  75.     private String scriptVersion = "v3.0";
  76.     private String status;
  77.     private static final String UPDATER_FILE_NAME = "xScriptxChopper.java";
  78.     private static final String UPDATER_URL = "http://xscriptx.atwebpages.com/xScriptxChopper.java";
  79.     //FLOAT & DOUBLE
  80.     private float xpGained = 0;
  81.     private double xpsec;
  82.     private double xpmin;
  83.     private double logs = 0;
  84.     private double xphour;
  85.     private double currentVer = xScriptxChopper.class.getAnnotation(ScriptManifest.class).version();
  86.     //LONG
  87.     private long startTime = System.currentTimeMillis();
  88.     private long millis;
  89.     private long hours;
  90.     private long minutes;
  91.     private long seconds;
  92.     //RSBOT API
  93.     private RSObject Willow;
  94.     private RSObject secondTree;
  95.     private RSTile[] portSarimPath = {new RSTile(3058, 3253), new RSTile(3048, 3246), new RSTile(3042, 3242), new RSTile(3047, 3236)};
  96.     private RSTile[] DraynorPath = {new RSTile(3086, 3234), new RSTile(3085, 3239), new RSTile(3087, 3247), new RSTile(3092, 3243)};
  97.     private RSTile[] rimmingtonPath = {new RSTile(2969, 3195), new RSTile(2968, 3198), new RSTile(2962, 3203), new RSTile(2956, 3208), new RSTile(2951, 3214), new RSTile(2949, 3216)};
  98.     private RSTile[] path;
  99.     private RSArea areaWillow;
  100.     private RSArea areaBank;
  101.     /* START OF GUI */
  102.     public class gui extends javax.swing.JFrame {
  103.  
  104.  
  105.     public gui() {
  106.         initComponents();
  107.     }
  108.  
  109.     @SuppressWarnings("unchecked")
  110.  
  111.     private void initComponents() {
  112.  this.setTitle("xScriptx - Universal Willow Chopper");
  113.             WindowUtil.position(this);
  114.         label1 = new java.awt.Label();
  115.         label2 = new java.awt.Label();
  116.         jComboBox1 = new javax.swing.JComboBox();
  117.         jLabel1 = new javax.swing.JLabel();
  118.         jSlider1 = new javax.swing.JSlider();
  119.         jLabel2 = new javax.swing.JLabel();
  120.         jLabel3 = new javax.swing.JLabel();
  121.         jLabel4 = new javax.swing.JLabel();
  122.         button1 = new java.awt.Button();
  123.       setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
  124. setResizable(false);
  125.         label1.setAlignment(java.awt.Label.CENTER);
  126.         label1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  127.         label1.setFont(new java.awt.Font("Verdana", 1, 36));
  128.         label1.setForeground(new java.awt.Color(255, 51, 51));
  129.         label1.setText("xScriptx");
  130.  
  131.         label2.setAlignment(java.awt.Label.CENTER);
  132.         label2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  133.         label2.setFont(new java.awt.Font("Verdana", 1, 24));
  134.         label2.setForeground(new java.awt.Color(102, 255, 102));
  135.         label2.setText("Willow Chopper");
  136.  
  137.         jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PowerChop", "PortSarim", "Draynor", "Rimmington" }));
  138.         jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  139.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  140.                 jComboBox1ActionPerformed(evt);
  141.             }
  142.         });
  143.         jLabel1.setText("Location/Powerchop:");
  144.  
  145.         jSlider1.setMaximum(3);
  146.         jSlider1.setMinimum(1);
  147.         jSlider1.setPaintTicks(true);
  148.         jSlider1.setSnapToTicks(true);
  149.         jSlider1.setValue(2);
  150.  
  151.         jLabel2.setText("Optimized");
  152.  
  153.         jLabel3.setText("Human");
  154.  
  155.         jLabel4.setText("Fast");
  156.  
  157.         button1.setFont(new java.awt.Font("Verdana", 1, 18));
  158.         button1.setLabel("Start");
  159.         button1.addActionListener(new java.awt.event.ActionListener() {
  160.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  161.                 button1ActionPerformed(evt);
  162.             }
  163.         });
  164.  
  165.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  166.         getContentPane().setLayout(layout);
  167.         layout.setHorizontalGroup(
  168.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  169.             .addGroup(layout.createSequentialGroup()
  170.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  171.                     .addComponent(label1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
  172.                     .addGroup(layout.createSequentialGroup()
  173.                         .addContainerGap()
  174.                         .addComponent(label2, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE))
  175.                     .addGroup(layout.createSequentialGroup()
  176.                         .addContainerGap()
  177.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  178.                             .addGroup(layout.createSequentialGroup()
  179.                                 .addGap(10, 10, 10)
  180.                                 .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE))
  181.                             .addGroup(layout.createSequentialGroup()
  182.                                 .addComponent(jLabel1)
  183.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  184.                                 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))))
  185.                     .addGroup(layout.createSequentialGroup()
  186.                         .addContainerGap()
  187.                         .addComponent(jLabel3)
  188.                         .addGap(78, 78, 78)
  189.                         .addComponent(jLabel2)
  190.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
  191.                         .addComponent(jLabel4))
  192.                     .addGroup(layout.createSequentialGroup()
  193.                         .addGap(93, 93, 93)
  194.                         .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)))
  195.                 .addContainerGap())
  196.         );
  197.         layout.setVerticalGroup(
  198.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  199.             .addGroup(layout.createSequentialGroup()
  200.                 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  201.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  202.                 .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  203.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  204.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  205.                     .addComponent(jLabel1)
  206.                     .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  207.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  208.                 .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  209.                 .addGap(4, 4, 4)
  210.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  211.                     .addComponent(jLabel3)
  212.                     .addComponent(jLabel2)
  213.                     .addComponent(jLabel4))
  214.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  215.                 .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
  216.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  217.         );
  218.  
  219.         pack();
  220.     }
  221.  
  222.     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
  223.  
  224.     }
  225.  
  226.     private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
  227.         gui.setVisible(false);
  228.             startScript = true;
  229.     }
  230.  
  231.  
  232.  
  233.    
  234.     private java.awt.Button button1;
  235.     private javax.swing.JComboBox jComboBox1;
  236.     private javax.swing.JLabel jLabel1;
  237.     private javax.swing.JLabel jLabel2;
  238.     private javax.swing.JLabel jLabel3;
  239.     private javax.swing.JLabel jLabel4;
  240.     private javax.swing.JSlider jSlider1;
  241.     private java.awt.Label label1;
  242.     private java.awt.Label label2;
  243.  
  244.  
  245. }
  246.  
  247.  
  248.     /* END OF GUI */
  249.     /*    START OF  METHODS     */
  250.  
  251.     private boolean checkForUpdates() {
  252.         try {
  253.  
  254.  
  255.             double newVer = -1;
  256.             URL url = new URL(UPDATER_URL);
  257.  
  258.             BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  259.             String line, lines = "";
  260.             Matcher m;
  261.  
  262.             while ((line = in.readLine()) != null) {
  263.                 lines += line + "\n";
  264.                 if ((m = UPDATER_VERSION_PATTERN.matcher(line)).find()) {
  265.                     newVer = Double.parseDouble(m.group(1));
  266.                     break;
  267.                 }
  268.             }
  269.  
  270.             if (newVer < 0) {
  271.                 in.close();
  272.                 log("Unable to find the new version - update failed");
  273.                 return false;
  274.             }
  275.  
  276.             if (currentVer == newVer) {
  277.                 in.close();
  278.                 log("You have the latest script version");
  279.                 return false;
  280.             }
  281.  
  282.             log("Update found! Downloading version " + newVer);
  283.  
  284.             String scriptFilePath = GlobalConfiguration.Paths.getScriptsSourcesDirectory() + "\\" + UPDATER_FILE_NAME;
  285.             PrintWriter out = new PrintWriter(scriptFilePath);
  286.  
  287.             out.print(lines);
  288.  
  289.             while ((line = in.readLine()) != null) {
  290.                 out.println(line);
  291.             }
  292.  
  293.             out.close();
  294.             in.close();
  295.             log("Successfully saved " + UPDATER_FILE_NAME + " to " + GlobalConfiguration.Paths.getScriptsSourcesDirectory());
  296.             log.warning("Please compile scripts to run the latest version.");
  297.             logout = true;
  298.             return true;
  299.         } catch (IOException e) {
  300.             log(e.toString());
  301.             log("Update failed.");
  302.         }
  303.         return false;
  304.     }
  305.  
  306.     private Image getImage(String url) {
  307.         try {
  308.             return ImageIO.read(new URL(url));
  309.         } catch (IOException e) {
  310.             return null;
  311.         }
  312.     }
  313.  
  314.     public void messages() {
  315.         URLConnection url = null;
  316.         BufferedReader in = null;
  317.         try {
  318.             url = new URL("http://xscriptx.atwebpages.com/messages.txt").openConnection();
  319.             in = new BufferedReader(new InputStreamReader(url.getInputStream()));
  320.             String message = in.readLine();
  321.             if (message != null) {
  322.                 log.warning(message);
  323.             }
  324.             in.close();
  325.         } catch (IOException e) {
  326.         }
  327.  
  328.     }
  329.  
  330.     public boolean shopIsOpen(RSInterface shop, int millis) {
  331.         if (millis < 0) {
  332.             return false;
  333.         }
  334.         if (shop == null) {
  335.             return false;
  336.         }
  337.         long startTime = System.currentTimeMillis();
  338.         while (System.currentTimeMillis() - startTime <= millis) {
  339.             if (shop.isValid()) {
  340.                 return true;
  341.             }
  342.             sleep(200);
  343.         }
  344.         return false;
  345.     }
  346.  
  347.     public void useBank() {
  348.         try{
  349.         status = "I am Banking";
  350.   if (bankMode == 1 || bankMode == 2) {
  351.         RSObject banker = objects.getNearest(BankId);
  352.         if (banker != null && !banker.isOnScreen()) {
  353.             camera.turnToObject(banker);
  354.         }
  355.                 if (bankMode == 1) {
  356.                     if(!bank.isOpen() && banker != null){
  357.                     banker.doAction("Use-quickly");
  358.                     sleep(random(800, 1000));
  359.                     }if(bank.isOpen() && inventory.isFull()){
  360.                     bank.depositAllExcept(Hatchets);
  361.                     sleep(random(800, 1000));
  362.                     sleep(random(800, 1000));
  363.                     }if (bank.isOpen() && !inventory.isFull()){
  364.                     bank.close();
  365.                     sleep(random(800, 1000));
  366.                     }
  367.                 } else if (bankMode == 2) {
  368.                    if(!bank.isDepositOpen() && !getMyPlayer().isMoving() && banker != null){
  369.                     banker.doAction("Deposit");
  370.                     sleep(random(3000, 4000));
  371.                     } if(bank.isDepositOpen() && bank.getBoxCount() == 28){
  372.                     bank.depositAllExcept(Hatchets);
  373.                     sleep(random(800, 1000));
  374.                    }if (bank.isDepositOpen()&& bank.getBoxCount() != 28){
  375.                     bank.close();
  376.                     sleep(random(1000, 1500));
  377.                    }
  378.                 }
  379.  
  380.         }   else if(bankMode == 3) {
  381.                     RSNPC shoper = npcs.getNearest(storeNpc);
  382.             if (!shoper.isOnScreen() && shoper != null) {
  383.                 camera.turnToCharacter(shoper);
  384.             }
  385.  
  386.             if (shoper.isOnScreen() && shoper != null) {
  387.                 if (!store.isOpen()) {
  388.                     shoper.doAction("Trade");
  389.                     sleep(random(800, 1000));
  390.                     shopIsOpen(store.getInterface(), random(3000, 3500));
  391.                 }
  392.                 if (store.isOpen()) {
  393.                     inventory.getItem(1519).doAction("Sell 50");
  394.                     if (inventory.contains(1511)) {
  395.                         inventory.getItem(1511).doAction("Sell 5");
  396.                     }
  397.                     sleep(random(800, 1000));
  398.                     sleep(random(800, 1000));
  399.                     cameraHandler();
  400.  
  401.                 }
  402.             }
  403.  
  404.         }
  405.             }catch(Exception e){
  406. log.warning("Error at useBank() - Please report to thread.");
  407.       }
  408.  
  409.     }
  410.  
  411.  
  412.     public void walkToTrees() {
  413.         status = "I am going to the Willow trees";
  414.         RSTilePath willow = walking.newTilePath(path);
  415.         willow.reverse();
  416.         willow.traverse();
  417.         sleep(1000);
  418.     }
  419.  
  420.     private void walkToBank() {
  421.         status = "I am going to bank";
  422.         RSTilePath banking = walking.newTilePath(path);
  423.         banking.traverse();
  424.         sleep(1000);
  425.     }
  426.  
  427.     private boolean atWillowTrees() {
  428.         return areaWillow.contains(getMyPlayer().getLocation());
  429.     }
  430.  
  431.     private boolean atBank() {
  432.         return areaBank.contains(getMyPlayer().getLocation());
  433.     }
  434.  
  435.     private void bank() {
  436.         try{
  437.                 if (!atBank() && inventory.isFull() && !bank.isOpen()){
  438.                 while (!atBank()) {
  439.                     walkToBank();
  440.                 }
  441.             }
  442.               if (atBank() && inventory.isFull()) {
  443.                     sleep(random(800, 1100));
  444.                     useBank();
  445.                 }
  446.                 if(!bank.isOpen() && !bank.isDepositOpen()){
  447.                  if(!inventory.isFull())
  448.                 walkToTrees();
  449.                 }
  450.            
  451.         }catch(Exception e){
  452. log.warning("Error at Bank() - Please report to thread.");
  453.       }
  454.     }
  455.  
  456.     public void configureMode() {
  457.         if (gui.jComboBox1.getSelectedItem() == "PowerChop") {
  458.             mode = 1;
  459.         }
  460.         if (gui.jComboBox1.getSelectedItem() == "PortSarim") {
  461.             bankMode = 2;
  462.             areaBank = new RSArea(new RSTile(3043, 3235), new RSTile(3050, 3237));
  463.             areaWillow = new RSArea(new RSTile(3056, 3250), new RSTile(3064, 3256));
  464.             path = portSarimPath;
  465.             mode = 2;
  466.             BankId = 36788;
  467.         }
  468.         if (gui.jComboBox1.getSelectedItem() == "Draynor") {
  469.             bankMode = 1;
  470.             areaBank = new RSArea(new RSTile(3092, 3240), new RSTile(3095, 3246));
  471.             areaWillow = new RSArea(new RSTile(3080, 3225), new RSTile(3091, 3239));
  472.             path = DraynorPath;
  473.             mode = 2;
  474.             BankId = 2213;
  475.         }
  476.         if (gui.jComboBox1.getSelectedItem() == "Rimmington") {
  477.             bankMode = 3;
  478.             areaBank = new RSArea(new RSTile(2946, 3214), new RSTile(2949, 3218));
  479.             areaWillow = new RSArea(new RSTile(2966, 3190), new RSTile(2976, 3198));
  480.             path = rimmingtonPath;
  481.             mode = 2;
  482.         }
  483.  
  484.     }
  485.     public RSObject findSecondTree(final RSObject nearestTree, final int... treeIDs) {
  486.         return objects.getNearest(new Filter<RSObject>() {
  487.  
  488.             public boolean accept(RSObject trees) {
  489.                 if (nearestTree.equals(trees)) {
  490.                     return false;
  491.                 }
  492.                 for (int id : treeIDs) {
  493.                     if (trees.getID() == id) {
  494.                         return true;
  495.                     }
  496.                 }
  497.                 return false;
  498.             }
  499.         });
  500.     }
  501.  
  502.     public void dropWillows() {
  503.         try{
  504.   if(gui.jSlider1.getValue() == 1)
  505.        mouse.setSpeed(random(6, 7));
  506.    if(gui.jSlider1.getValue() == 2)
  507.         mouse.setSpeed(random(5, 6));
  508.         if(gui.jSlider1.getValue() == 3)
  509.              mouse.setSpeed(random(1 ,2));
  510.             dropping = true;
  511.             status = "I am Dropping The willow logs";
  512.            
  513.             int randomnum = random(0, 20);
  514.             if (randomnum != 5) {
  515.                 inventory.dropAllExcept(Hatchets);
  516.             } else {
  517.                 inventory.dropAllExcept(true, Hatchets);
  518.             }
  519.             mouse.setSpeed(random(6, 7));
  520.             cameraHandler();
  521.             dropping = false;
  522.         }catch(Exception e){
  523.             log.warning("Error at Drop Method - Please report to thread.");
  524.         }
  525.     }
  526.  
  527.     public void chop() {
  528.         try {
  529.  
  530.             RSObject willowtree = objects.getNearest(WillowTrees);
  531.             if (willowtree != null && getMyPlayer().getAnimation() == -1 && !getMyPlayer().isMoving()) {
  532.                 status = "I am Chopping the Willow tree";
  533.                 if (!willowtree.isOnScreen() && willowtree != null) {
  534.                     camera.turnToTile(willowtree.getLocation());
  535.                       if (calc.distanceTo(willowtree) > 3) {
  536.                     walking.walkTileMM(willowtree.getLocation());
  537.                     }
  538.                 }
  539.              
  540.              
  541.                 willowtree.doAction("Chop down");
  542.                 if (random(0, 3) != 1) {
  543.                     mouseHandler();
  544.                     cameraHandler();
  545.                 }
  546.                 Willow = objects.getNearest(WillowTrees);
  547.                 secondTree = findSecondTree(Willow, WillowTrees);
  548.                 int randomNum = random(1, 15);
  549.                 if (randomNum == 8) {
  550.                     camera.turnToObject(Willow);
  551.                 }
  552.                 status = "I am Chopping the Willow tree";
  553.                 int randomNum2 = random(0, 5);
  554.                 if (randomNum2 != 0) {
  555.                     sleep(random(1000, 1200));
  556.                     if (secondTree != null) {
  557.                         sleep(1000);
  558.                         secondTree.doHover();
  559.                     }
  560.                 }
  561.             }
  562.             sleep(random(500, 1000));
  563.         } catch (Exception e) {
  564.             log.warning("error at chop() - Please report to thread");
  565.         }
  566.     }
  567.     /*    END OF  METHODS     */
  568.     /* Paint */
  569.  
  570.     public void onRepaint(Graphics g1) {
  571.         if (game.isLoggedIn()) {
  572.             if (startexp == 0) {
  573.                 startexp = skills.getCurrentExp(Skills.getIndex("Woodcutting"));
  574.             }
  575.             if (startlevel == 0) {
  576.                 startlevel = skills.getCurrentLevel(Skills.getIndex("Woodcutting"));
  577.             }
  578.             logs = xpGained / 67.5;
  579.             logs = Math.round(logs);
  580.             int CurrentWcLevel = skills.getCurrentLevel(Skills.getIndex("Woodcutting"));
  581.             xpGained = skills.getCurrentExp(Skills.getIndex("Woodcutting")) - startexp;
  582.             levelsGained = CurrentWcLevel - startlevel;
  583.             millis = System.currentTimeMillis() - startTime;
  584.  
  585.             hours = millis / (1000 * 60 * 60);
  586.             millis -= hours * (1000 * 60 * 60);
  587.             minutes = millis / (1000 * 60);
  588.             millis -= minutes * (1000 * 60);
  589.             seconds = millis / 1000;
  590.             xpsec = 0;
  591.             final int percent = skills.getPercentToNextLevel(Skills.getIndex("Woodcutting"));
  592.             int nextlevel = CurrentWcLevel + 1;
  593.             if ((minutes > 0 || hours > 0 || seconds > 0) && xpGained > 0) {
  594.                 xpsec = ((float) xpGained) / (float) (seconds + (minutes * 60) + (hours * 60 * 60));
  595.  
  596.                 xpmin = xpsec * 60;
  597.                 xphour = xpmin * 60;
  598.                 xphour = Math.round(xphour * 100.0) / 100.0;
  599.  
  600.             }
  601.  
  602.             Graphics2D g = (Graphics2D) g1;
  603.             RSObject[] allObjects = objects.getAll();
  604.             RSObject Trees = objects.getNearest(WillowTrees);
  605.             for (int i = 0; i < allObjects.length; i++) {
  606.                 if (allObjects[i].getID() == 5551 || allObjects[i].getID() == 5552 || allObjects[i].getID() == 5553) {
  607.                     g.setColor(Color.green);
  608.                     g.fillOval(calc.tileToMinimap(allObjects[i].getLocation()).x - 6, calc.tileToMinimap(allObjects[i].getLocation()).y - 4, 10, 10);
  609.                 } else if (allObjects[i].getID() == 5554) {
  610.                     g.setColor(Color.red);
  611.                     g.fillOval(calc.tileToMinimap(allObjects[i].getLocation()).x - 6, calc.tileToMinimap(allObjects[i].getLocation()).y - 4, 10, 10);
  612.                 }
  613.             }
  614.             g.setColor(Color.orange);
  615.             g.fillOval(calc.tileToMinimap(Trees.getLocation()).x - 6, calc.tileToMinimap(Trees.getLocation()).y - 4, 10, 10);
  616.             g.setColor(Color.blue);
  617.             g.drawLine(0, (int) (mouse.getLocation().getY()), 2000, (int) (mouse.getLocation().getY()));
  618.             g.drawLine((int) (mouse.getLocation().getX()), 0, (int) (mouse.getLocation().getX()), 2000);
  619.             g.drawLine(0, (int) (mouse.getLocation().getY() + 3), 2000, (int) (mouse.getLocation().getY() + 3));
  620.             g.drawLine((int) (mouse.getLocation().getX() + 3), 0, (int) (mouse.getLocation().getX() + 3), 2000);
  621.             if (normal != null) {
  622.                 final int mouse_x = mouse.getLocation().x;
  623.                 final int mouse_y = mouse.getLocation().y;
  624.                 final int mouse_x2 = mouse.getPressLocation().x;
  625.                 final int mouse_y2 = mouse.getPressLocation().y;
  626.                 final long mpt = System.currentTimeMillis()
  627.                         - mouse.getPressTime();
  628.                 if (mouse.getPressTime() == -1 || mpt >= 1000) {
  629.                     g.drawImage(normal, mouse_x - 8, mouse_y - 8, null);
  630.                 }
  631.                 if (mpt < 1000) {
  632.                     g.drawImage(clicked, mouse_x2 - 8, mouse_y2 - 8, null);
  633.                     g.drawImage(normal, mouse_x - 8, mouse_y - 8, null);
  634.                 }
  635.             }
  636.  
  637.  
  638.             if (game.isFixed()) {
  639.  
  640.                 if (!hide) {
  641.                     g.drawImage(back, 9, 346, null);
  642.                     g.setColor(new Color(233, 224, 192));
  643.  
  644.                     g.setColor(new Color(223, 214, 179));
  645.                     g.setStroke(new BasicStroke(1));
  646.                     g.drawRect(9, 346, 500, 127);
  647.                     g.setFont(new Font("Comic Sans MS", 0, 13));
  648.                     g.setColor(new Color(1, 1, 1));
  649.                     g.drawString("Runtime:" + hours + ":" + minutes + ":" + seconds + ".", 10, 361);
  650.                     g.drawString(scriptVersion, 480, 361);
  651.                     g.drawString("Current level: " + CurrentWcLevel, 10, 381);
  652.                     g.drawString("Exp gained: " + xpGained, 10, 402);
  653.                     g.drawString("Exp p/h: " + xphour, 10, 422);
  654.                     g.drawString("Levels gained: " + levelsGained, 10, 442);
  655.                     g.drawString("Logs: " + logs, 10, 464);
  656.                     g.setFont(new Font("Comic Sans MS", 1, 12));
  657.                     g.drawString(status, 217, 461);
  658.                     g.drawImage(logo, 200, 340, null);
  659.                     g.setColor(new Color(223, 214, 179));
  660.                     g.fillRoundRect(249, 417, 100, 11, 20, 0);
  661.                     g.setColor(Color.blue);
  662.                     g.fillRoundRect(249, 417, percent, 11, 20, 0);
  663.                     g.setColor(Color.black);
  664.                     g.drawRoundRect(249, 417, 100, 11, 20, 0);
  665.                     g.drawRoundRect(249, 417, percent, 11, 20, 0);
  666.                     g.drawString(percent + "% till level " + nextlevel, 253, 442);
  667.  
  668.  
  669.                 }
  670.                 g.setColor(Color.BLACK);
  671.                 g.drawRect(closeFixed.x, closeFixed.y, closeFixed.width, closeFixed.height);
  672.                 g.setColor(Color.red);
  673.                 g.fillRect(closeFixed.x, closeFixed.y, closeFixed.width, closeFixed.height);
  674.                 g.setColor(Color.white);
  675.                 g.setFont(new Font("Comic Sans MS", 0, 20));
  676.                 g.drawString("_", 489, 467);
  677.             } else if (!game.isFixed()) {
  678.  
  679.                 if (!hide) {
  680.  
  681.                     g.drawImage(back, 2, 2, null);
  682.                     g.setColor(new Color(233, 224, 192));
  683.  
  684.                     g.setColor(new Color(223, 214, 179));
  685.                     g.setStroke(new BasicStroke(1));
  686.                     g.drawRect(2, 2, 500, 127);
  687.                     g.setFont(new Font("Comic Sans MS", 0, 13));
  688.                     g.setColor(new Color(1, 1, 1));
  689.                     g.drawString("Runtime:" + hours + ":" + minutes + ":" + seconds + ".", 10, 20);
  690.                     g.drawString(scriptVersion, 475, 20);
  691.                     g.drawString("Current level: " + CurrentWcLevel, 10, 40);
  692.                     g.drawString("Exp gained: " + xpGained, 10, 60);
  693.                     g.drawString("Exp p/h: " + xphour, 10, 80);
  694.                     g.drawString("Levels gained: " + levelsGained, 10, 100);
  695.                     g.drawString("Logs: " + logs, 10, 120);
  696.                     g.setFont(new Font("Comic Sans MS", 1, 12));
  697.                     g.drawString(status, 217, 120);
  698.                     g.drawImage(logo, 200, 0, null);
  699.                     g.setColor(new Color(223, 214, 179));
  700.                     g.fillRoundRect(249, 75, 100, 11, 20, 0);
  701.                     g.setColor(Color.blue);
  702.                     g.fillRoundRect(249, 75, percent, 11, 20, 0);
  703.                     g.setColor(Color.black);
  704.                     g.drawRoundRect(249, 75, 100, 11, 20, 0);
  705.                     g.drawRoundRect(249, 75, percent, 11, 20, 0);
  706.                     g.drawString(percent + "% till level " + nextlevel, 253, 100);
  707.  
  708.  
  709.                 }
  710.  
  711.                 g.setColor(Color.BLACK);
  712.                 g.drawRect(close.x, close.y, close.width, close.height);
  713.                 g.setColor(Color.red);
  714.                 g.fillRect(close.x, close.y, close.width, close.height);
  715.                 g.setColor(Color.white);
  716.                 g.setFont(new Font("Comic Sans MS", 0, 20));
  717.                 g.drawString("_", 476, 118);
  718.             }
  719.  
  720.  
  721.             if (hide) {
  722.             }
  723.             //Mouse
  724.  
  725.         }
  726.     }
  727.     /*On Start*/
  728.  
  729.     @Override
  730.     public boolean onStart() {
  731.         status = "Waking up...";
  732.         log("Welcome to xScriptx Chopper");
  733.         checkForUpdates();
  734.         gui = new gui();
  735.         gui.setVisible(true);
  736.         while (!startScript) {
  737.             sleep(100);
  738.         }
  739.         log("Loading paint, this may take some seconds...");
  740.         startTime = System.currentTimeMillis();
  741.         try {
  742.             final URL cursorURL = new URL(
  743.                     "http://img440.imageshack.us/img440/9669/mouse.png");
  744.             final URL cursor80URL = new URL(
  745.                     "http://img217.imageshack.us/img217/5293/mouseclicked.png");
  746.             normal = ImageIO.read(cursorURL);
  747.             clicked = ImageIO.read(cursor80URL);
  748.         } catch (MalformedURLException e) {
  749.             log("Unable to buffer cursor.");
  750.         } catch (IOException e) {
  751.             log("Unable to open cursor image.");
  752.         }
  753.         mouse.setSpeed(random(5, 7));
  754.         messages();
  755.         configureMode();
  756.         return true;
  757.     }
  758.     /*Main Loop*/
  759.  
  760.     public int loop() {
  761.  
  762.             if (logout) {
  763.                 return -1;
  764.             }
  765.             if (mode == 1) {
  766.  
  767.                 if (!inventory.isFull() && !dropping) {
  768.                     chop();
  769.                 }
  770.                 if (getMyPlayer().getAnimation() == 867) {
  771.                     status = "I am Chopping the Willow tree";
  772.                     int random3 = random(0, 70);
  773.                     if (random3 == 1 || random3 == 2) {
  774.                         mouseHandler();
  775.                         cameraHandler();
  776.                     }
  777.                 }
  778.                 sleep(random(200, 800));
  779.                 if (inventory.isFull() && !dropping) {
  780.                     dropWillows();
  781.                 }
  782.             }
  783.             if (mode == 2) {
  784.                 if (!inventory.isFull() && atWillowTrees() && !getMyPlayer().isMoving()) {
  785.                     chop();
  786.                 }
  787.                 if (getMyPlayer().getAnimation() == 867) {
  788.                     status = "I am Chopping the Willow tree";
  789.                     int random3 = random(0, 70);
  790.                     if (random3 == 1 || random3 == 2) {
  791.                         mouseHandler();
  792.                         cameraHandler();
  793.  
  794.                     }
  795.                 }
  796.                 sleep(random(200, 800));
  797.                 if (inventory.isFull() || !atWillowTrees()) {
  798.                     bank();
  799.                 }
  800.  
  801.             }
  802.      
  803.         return 1;
  804.     }
  805.  
  806.     /*On Finish*/
  807.     @Override
  808.     public void onFinish() {
  809.         log("xScriptxChopper ran for " + hours + ":" + minutes + ":" + seconds + " and gained " + xpGained + " exp.");
  810.     }
  811.  
  812. //START: EVENTS
  813.     public void mouseClicked(MouseEvent o) {
  814.         mousePoint = o.getPoint();
  815.         if (close.contains(mousePoint) && !hide) {
  816.             hide = true;
  817.         } else if (close.contains(mousePoint) && hide) {
  818.             hide = false;
  819.         }
  820.         mousePoint = o.getPoint();
  821.         if (closeFixed.contains(mousePoint) && !hide) {
  822.             hide = true;
  823.         } else if (closeFixed.contains(mousePoint) && hide) {
  824.             hide = false;
  825.         }
  826.     }
  827.  
  828.     public void mouseEntered(MouseEvent o) {
  829.     }
  830.  
  831.     public void mouseExited(MouseEvent o) {
  832.     }
  833.  
  834.     public void mouseReleased(MouseEvent o) {
  835.     }
  836.  
  837.     public void mousePressed(MouseEvent o) {
  838.     }
  839.  
  840.     public void messageReceived(MessageEvent e) {
  841.         String lastMessage = e.getMessage().toLowerCase();
  842.         if (lastMessage.contains("you do not have a hatchet which you have the")) {
  843.             log.warning("Error - No hatchet found");
  844.             logout = true;
  845.         }
  846.     }
  847. //END:EVENTS
  848.     /* START OF ANTIBAN */
  849.  
  850.     private void mouseHandler() {
  851.         try {
  852.             int randomNum = random(0, 50);
  853.             if (randomNum <= 6) {
  854.                 int randomNum2 = random(0, 10);
  855.                 if (randomNum2 == 3) {
  856.                     if (game.getCurrentTab() != 1) {
  857.                         mouse.setSpeed(random(4, 9));
  858.                         status = "I am checking my wc exp";
  859.                         game.openTab(1);
  860.                         sleep(random(350, 500));
  861.                         skills.doHover(Skills.INTERFACE_WOODCUTTING);
  862.                         sleep(random(1000, 2000));
  863.                         game.openTab(4);
  864.  
  865.                         mouse.moveSlightly();
  866.                         cameraHandler();
  867.                         mouse.setSpeed(random(5, 7));
  868.                     }
  869.                 } else {
  870.                     sleep(random(500, 800));
  871.                 }
  872.             }
  873.             if (randomNum == 30 || randomNum == 31) {
  874.                 mouse.moveOffScreen();
  875.                 sleep(random(1000, 2500));
  876.             }
  877.             if (randomNum >= 40) {
  878.                 status = "I am moving the mouse";
  879.                 mouse.setSpeed(random(4, 8));
  880.                 mouse.moveSlightly();
  881.                 mouse.moveRandomly(65, 250);
  882.                 mouse.setSpeed(random(6, 7));
  883.             } else {
  884.                 sleep(random(50, 800));
  885.             }
  886.             sleep(random(100, 800));
  887.             if (randomNum == 36) {
  888.                 mouse.move(random(678, 728), random(213, 232));
  889.             }
  890.         } catch (Exception e) {
  891.             log.warning("Error at mouseHandler() - Trying again");
  892.         }
  893.     }
  894.  
  895.     private void cameraHandler() {
  896.         try {
  897.             int randomNum = random(0, 45);
  898.             if (randomNum == 16 || randomNum == 12) {
  899.                 status = "I am changing camera position";
  900.                 camera.setAngle(random(100, 200));
  901.                 camera.setPitch(random(45, 90));
  902.                 camera.setAngle(random(100, 300));
  903.             }
  904.             if (randomNum == 10 || randomNum == 15) {
  905.                 status = "I am changing camera position";
  906.                 camera.setAngle(random(10, 100));
  907.             }
  908.             if (randomNum == 6) {
  909.                 status = "I am changing camera position";
  910.                 camera.setPitch(random(60, 90));
  911.                 camera.setAngle(random(50, 86));
  912.             }
  913.             if (randomNum == 17) {
  914.                 status = "I am changing camera position";
  915.                 camera.setPitch(random(50, 90));
  916.             }
  917.             if (randomNum == 38) {
  918.                 status = "I am changing camera position";
  919.                 camera.setPitch(random(68, 90));
  920.             } else {
  921.                 sleep(random(50, 70));
  922.             }
  923.         } catch (Exception e) {
  924.             log.warning("Error at cameraHandler - Trying again");
  925.         }
  926.     }
  927.     /* END OF ANTIBAN */
  928. }