Ministry

Untitled

Jun 29th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.60 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.MouseMotionListener;
  8.  
  9. import org.rsbot.event.listeners.PaintListener;
  10. import org.rsbot.script.Script;
  11. import org.rsbot.script.ScriptManifest;
  12. import org.rsbot.script.wrappers.RSNPC;
  13.  
  14. @ScriptManifest(authors = { "Battleguard" }, version = 0.01, keywords = { "itemflipper2" }, description = "itemflipper2, by Battleguard", name = "itemflipper2")
  15. public class errorFreeItemFlipper extends Script implements PaintListener, MouseMotionListener {
  16.  
  17.         Rectangle itemBox;
  18.         Item item1 = new Item();
  19.         Box box = new Box();
  20.  
  21.         String action;
  22.         Color backArrow = new Color(91, 85, 78);
  23.  
  24.         // INSTEAD OF DOING GET COMPONENT WE NEED TO MANUALLY GET THE VALUES
  25.         // THIS WILL SERVE 2 PURPOSES
  26.         // 1 WE CANNOT GET THE COMPONENT IF IT DOES NOT EXIST YET EXAMPLE NATURE RUNE CLICK TEXT FOR BUY
  27.         // ALSO IT WILL GET RID OF ANY NULL POINTER EXCEPTIONS WE MAY ENCOUNTER
  28.  
  29.         // WE CAN ALSO TAKE A RISK APPROACH TO THIS PROBLEM BY MAKING SURE THAT WE ARE IN THE CORRECT SPOT B4
  30.         // EVERY CLICK BY USING GAME.GETCOLOR(X,Y); AND COMPARING IT TO THE COLOR WE SHOULD EXPECT
  31.         // IF COLOR IS LOAD THE PROGRAM WITH AN AUTOMATED RESET VECTOR
  32.  
  33.         public boolean onStart() {
  34.                 item1.startTime = System.currentTimeMillis();
  35.                 item1.initMoney = inventory.getItem(995).getStackSize();
  36.                 item1.initRunes = getInvItemCount();
  37.                 return true;
  38.         }
  39.  
  40.         int commandsDone = 0;
  41.  
  42.         @Override
  43.         public int loop() {
  44.                 try {
  45.                         if (!interfaces.getComponent(105, 15).getText().equalsIgnoreCase("grand exchange")) { // open grand exchange                  
  46.                                 action = "Opening GE";
  47.                                 RSNPC geNPC = npcs.getNearest(6528);
  48.                                 geNPC.interact("Exchange Grand Exchange clerk");
  49.                                 sleep(3000);
  50.                                 return 50;
  51.                         }
  52.                         item1.currentRunes = getInvItemCount();
  53.                         item1.currentMoney = inventory.getItem(995).getStackSize();
  54.                 } catch (Exception e) {
  55.                         log("problem opening up the GE Main Menu");
  56.                 }
  57.  
  58.                 if (buy()) {
  59.                         return 50;
  60.                 }
  61.                 if (sell()) {
  62.                         return 50;
  63.                 }
  64.                 if (checkBuy()) {
  65.                         return 50;
  66.                 }
  67.                 if (checkSell()) {
  68.                         return 50;
  69.                 }
  70.                 if (checkCancelSell()) {
  71.                         return 50;
  72.                 }
  73.                 if (checkTimer()) {
  74.                         return 50;
  75.                 }
  76.  
  77.                 // TEMPORARY ANTIBAN
  78.                 int i = random(0, 3);
  79.                 if (i == 0) {
  80.                         camera.moveRandomly(500);
  81.                 } else if (i == 2) {
  82.                         mouse.moveSlightly();
  83.                 } else if (i == 3) {
  84.                         mouse.click(mouse.getLocation().x + random(0, 100), mouse.getLocation().y + random(0, 100), false);
  85.                 }
  86.  
  87.                 return 1000;
  88.         }
  89.  
  90.         // POINTS THAT NEED TO BE CLICKED
  91.         // ALL POINTS ARE MADE AS RECTANGLES OF ON SCREEN POSITIONS
  92.         // THIS IS DONE TO ENSURE NO GETCOMPONENT() ERRORS OCCUR
  93.         Rectangle buyButtonBox = new Rectangle(54, 132, 35, 35);
  94.         Rectangle buyBox = new Rectangle(34, 84, 140, 110);
  95.         Rectangle searchSelectBox = new Rectangle(69, 343, 418, 11);
  96.         Rectangle enterQuantityBox = new Rectangle(220, 209, 35, 25);
  97.         Rectangle enterPriceBox = new Rectangle(370, 209, 35, 25);
  98.         Rectangle confirmBox = new Rectangle(204, 274, 120, 43);
  99.  
  100.         // box already made rectangle
  101.         Rectangle cancelButtonBox = new Rectangle(354, 276, 20, 20);
  102.         Rectangle collectCoinsBox = new Rectangle(401, 282, 36, 32);
  103.         Rectangle collectGoodsBox = new Rectangle(450, 282, 36, 32);
  104.         Rectangle backButtonBox = new Rectangle(29, 280, 35, 35);
  105.  
  106.         // sell boxes
  107.         Rectangle sellBox = new Rectangle(190, 84, 140, 110);
  108.         Rectangle sellButtonBox = new Rectangle(273, 132, 35, 35);
  109.  
  110.         // METHOD TO CLICK ON A RECTANGLE IN MY INTERFACE
  111.         void clickBox(Rectangle BOX) {
  112.                 Point clickSpot = new Point((BOX.x + random(0, BOX.width)), (BOX.y + random(0, BOX.height)));
  113.                 clickAndSleep(clickSpot);
  114.         }
  115.  
  116.         // METHOD TO MAKE SURE EVERY CLICK SLEEPS AFTER SO I DO NOT NEED TO MESS WITH SLEEPS
  117.         void clickAndSleep(Point spot) {
  118.                 mouse.click(spot, true);
  119.                 sleep(1500);
  120.         }
  121.  
  122.         // TYPES IN STRING AND HITS ENTER
  123.         void typeAndSleep(String text) {
  124.                 keyboard.sendText(text, true);
  125.                 sleep(1500);
  126.         }
  127.  
  128.         void pressBackButton() {
  129.                 clickBox(backButtonBox);
  130.         }
  131.  
  132.         // METHOD THAT HANDLES BUYING AN ITEM
  133.         boolean buy() {
  134.                 try {
  135.  
  136.                         // USED FOR CALCULATING PROFITS
  137.                         int oldMoney = inventory.getItem(995).getStackSize();
  138.                         // USED FOR CALCULATING PROFITS
  139.  
  140.                         if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("empty")) {
  141.                                 pressBackButton();
  142.                                 clickBox(buyButtonBox);
  143.                                 typeAndSleep(item1.name);
  144.                                 clickBox(searchSelectBox);
  145.                                 clickBox(enterQuantityBox);
  146.                                 typeAndSleep("" + item1.BuyQuantity);
  147.                                 clickBox(enterPriceBox);
  148.                                 typeAndSleep("" + item1.Price);
  149.                                 clickBox(confirmBox);
  150.                                 box.statusBar0 = 0;
  151.  
  152.                                 // USED FOR CALCULATING PROFITS
  153.                                 // ON BUY RUNEINGE+= ((newMoney - oldMoney) / item1.price)
  154.                                 int newMoney = inventory.getItem(995).getStackSize();
  155.                                 item1.RunesOnGE += ((oldMoney - newMoney) / item1.Price);
  156.                                 // USED FOR CALCULATING PROFITS
  157.  
  158.                                 return true;
  159.                         }
  160.                 } catch (Exception e) {
  161.                         log("Was not able to access name on BUYBOX");
  162.                 }
  163.                 return false;
  164.         }
  165.  
  166.         // METHOD THAT HANDLES SELLING AN ITEM
  167.         boolean sell() {
  168.                 try {
  169.                         if (inventory.getCount(this.item1.ID) > 0) { // MAKE SURE WE HAVE ITEMS TO SELL
  170.                                 if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("empty")) { // MAKE SURE SELL BOX IS EMPTY
  171.  
  172.                                         // USED FOR CALCULATING PROFIT
  173.                                         int oldRunes = getInvItemCount();
  174.                                         // USED FOR CALCULATING PROFIT
  175.  
  176.                                         pressBackButton();
  177.                                         clickBox(sellButtonBox);
  178.                                         clickAndSleep(inventory.getItem(item1.ID).getPoint());
  179.                                         clickBox(enterPriceBox);
  180.                                         typeAndSleep("" + (item1.Price + item1.PriceDiff));
  181.                                         clickBox(confirmBox);
  182.                                         box.statusBar1 = 0;
  183.  
  184.                                         // USED FOR CALCULATING PROFIT
  185.                                         // ON SELL RUNEINGE+= INV.GETCOUNT(ITEM1.ID)
  186.                                         int newRunes = getInvItemCount();
  187.                                         item1.RunesOnGE += (oldRunes - newRunes);
  188.                                         // USED FOR CALCULATING PROFIT
  189.  
  190.                                         return true;
  191.                                 }
  192.                         }
  193.  
  194.                 } catch (Exception e) {
  195.                         log("Was not able to access name on SELLBOX");
  196.                 }
  197.                 return false;
  198.         }
  199.  
  200.         boolean checkBuy() {
  201.                 try {
  202.                         if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
  203.                                 int currentBar = interfaces.getComponent(105, 19).getComponent(13).getArea().width;
  204.                                 if (currentBar > box.statusBar0) {
  205.                                         pressBackButton();
  206.                                         collectItems(buyBox);
  207.                                         box.statusBar0 = currentBar;
  208.                                         return true;
  209.                                 }
  210.                         }
  211.                 } catch (Exception e) {
  212.                         log("Problem checking status bar for BUY");
  213.                 }
  214.  
  215.                 return false;
  216.         }
  217.  
  218.         boolean checkSell() {
  219.                 try {
  220.                         if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
  221.                                 int currentBar = interfaces.getComponent(105, 35).getComponent(13).getArea().width;
  222.                                 if (currentBar > box.statusBar1) {
  223.                                         pressBackButton();
  224.                                         collectItems(sellBox);
  225.                                         box.statusBar1 = currentBar;
  226.                                         return true;
  227.                                 }
  228.                         }
  229.                 } catch (Exception e) {
  230.                         log("Problem Cancelling Sell");
  231.                 }
  232.  
  233.                 return false;
  234.         }
  235.  
  236.         boolean checkCancelSell() {
  237.                 try {
  238.                         if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
  239.                                 if (inventory.getCount(item1.ID) > 0) {
  240.                                         if (inventory.getItem(item1.ID).getStackSize() > 500) {
  241.                                                 cancelsell();
  242.                                                 return true;
  243.                                         }
  244.                                 }
  245.                         }
  246.                 } catch (Exception e) {
  247.                         log("Problem cancelling SELL");
  248.                 }
  249.                 return false;
  250.         }
  251.  
  252.         void cancelsell() {
  253.  
  254.                 // USED FOR CALCULATING PROFITS
  255.                 int oldRunes = getInvItemCount();
  256.                 int oldMoney = inventory.getItem(995).getStackSize();
  257.                 // USED FOR CALCULATING PROFITS
  258.  
  259.                 pressBackButton();
  260.                 clickBox(sellBox); // CLICK SELL BOX
  261.                 clickBox(cancelButtonBox); // CLICK CANCEL BUTTON
  262.                 clickBox(collectCoinsBox); // COLLECT COINS
  263.                 clickBox(collectGoodsBox); // COLLECT GOODS
  264.                 clickBox(backButtonBox); // HIT BACK BUTTON
  265.  
  266.                 // USED FOR CALCULATING PROFIT
  267.                 // ON CANCELSELL RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
  268.                 int newRunes = getInvItemCount();
  269.                 int newMoney = inventory.getItem(995).getStackSize();
  270.                 item1.RunesOnGE -= ((newRunes - oldRunes) + ((newMoney - oldMoney) / (item1.Price + item1.PriceDiff)));
  271.                 // USED FOR CALCULATING PROFIT
  272.  
  273.         }
  274.  
  275.         void cancelBuy() {
  276.  
  277.                 // USED FOR CALCULATING PROFITS
  278.                 int oldRunes = getInvItemCount();
  279.                 int oldMoney = inventory.getItem(995).getStackSize();
  280.                 // USED FOR CALCULATING PROFITS
  281.  
  282.                 pressBackButton();
  283.                 clickBox(buyBox); // CLICK SELL BOX
  284.                 clickBox(cancelButtonBox); // CLICK CANCEL BUTTON
  285.                 clickBox(collectCoinsBox); // COLLECT COINS
  286.                 clickBox(collectGoodsBox); // COLLECT GOODS
  287.                 clickBox(backButtonBox); // HIT BACK BUTTON
  288.  
  289.                 // USED FOR CALCULATING PROFIT
  290.                 // ON CANCELBUY RUNESINGE -= (NEWRUNES - OLDRUNES)
  291.                 int newRunes = getInvItemCount();
  292.                 int newMoney = inventory.getItem(995).getStackSize();
  293.                 newRunes += (newMoney - oldMoney) / item1.Price;
  294.  
  295.                 item1.RunesOnGE -= (newRunes - oldRunes);
  296.                 // USED FOR CALCULATING PROFIT
  297.  
  298.         }
  299.  
  300.         // CALCULATING PROFITS
  301.         // MONEY MADE = CURRENTMONEY + (RUNESINGE + RUNESININV * PRICE) +  - (STARTMONEY + (RUNES IN INV * PRICE));
  302.  
  303.         // CALCULATING RUNES IN GE
  304.  
  305.         // ON START GET INITMONEY & RUNESININV
  306.         // ON BUY RUNEINGE+= ITEM1.BUYQUANTITY
  307.         // ON SELL RUNEINGE+= INV.GETCOUNT(ITEM1.ID)
  308.         // ON CHECKBAR RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
  309.         // ON CANCELSELL RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
  310.         // ON CANCELBUY RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (ITEM1.PRICE))
  311.  
  312.         boolean checkTimer() {
  313.                 try {
  314.                         if (System.currentTimeMillis() - item1.lastTransaction > item1.TIME_TILL_PRICE_CHG) {
  315.                                 // IF SELL END IF THE PROBLEM REDUCE PRICE
  316.                                 if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
  317.                                         log("CANCELLING SELLITEMS");
  318.                                         cancelsell();
  319.                                         if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
  320.                                                 log("CANCELLING BUYITEMS");
  321.                                                 cancelBuy();
  322.                                         }
  323.                                         item1.Price--;
  324.                                         item1.lastTransaction = System.currentTimeMillis();
  325.                                         return true;
  326.                                 }
  327.                                 // IF BUY END IF THE PROBLEM INCREASE PRICE
  328.                                 if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
  329.                                         log("CANCELLING BUYITEMS");
  330.                                         cancelBuy();
  331.                                         item1.Price++;
  332.                                         item1.lastTransaction = System.currentTimeMillis();
  333.                                         return true;
  334.                                 }
  335.                         }
  336.                 } catch (Exception e) {
  337.                         log("Problem cancelling SELL");
  338.                 }
  339.                 return false;
  340.         }
  341.  
  342.         void collectItems(Rectangle boxWindow) {
  343.                 // CHECK TO SEE WE SHOULD UPDATE TIMER ( > 500 ITEMS SOLD)
  344.                 int oldMoney = inventory.getItem(995).getStackSize();
  345.                 int oldItems = getInvItemCount();
  346.                 clickBox(boxWindow);
  347.                 clickBox(collectCoinsBox);
  348.                 clickBox(collectGoodsBox);
  349.                 clickBox(backButtonBox);
  350.  
  351.                 int newMoney = inventory.getItem(995).getStackSize();
  352.                 int newItems = getInvItemCount();
  353.  
  354.                 if (newItems - oldItems > 500) {
  355.                         // UPDATE COUNTER 500 ITEMS BOUGHT
  356.                         item1.lastTransaction = System.currentTimeMillis();
  357.                 }
  358.                 if (newMoney - oldMoney > 500 * (item1.Price + item1.PriceDiff)) {
  359.                         // UPDATE COUNTER 500 ITEMS SOLD
  360.                         item1.lastTransaction = System.currentTimeMillis();
  361.                 }
  362.  
  363.                 // USED FOR CALCULATING PROFIT
  364.                 // ON CHECKBAR RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
  365.                 item1.RunesOnGE -= ((newItems - oldItems) + ((newMoney - oldMoney) / (item1.Price + item1.PriceDiff)));
  366.                 // USED FOR CALCULATING PROFIT
  367.  
  368.         }
  369.  
  370.         int getInvItemCount() {
  371.                 if (inventory.getCount(item1.ID) > 0) {
  372.                         return inventory.getItem(item1.ID).getStackSize();
  373.                 }
  374.                 return 0;
  375.         }
  376.  
  377.         public void onFinish() {
  378.                 log("Thank you for using the script!");
  379.         }
  380.  
  381.         class Box {
  382.                 private int statusBar0;
  383.                 private int statusBar1;
  384.  
  385.                 Box() {
  386.                         statusBar0 = 0;
  387.                         statusBar1 = 0;
  388.                 }
  389.         }
  390.  
  391.         class Item {
  392.                 public int ID;
  393.                 public String name;
  394.                 public int Price;
  395.                 public int BuyQuantity;
  396.                 public long TIME_TILL_PRICE_CHG;
  397.                 public long lastTransaction;
  398.                 public int PriceDiff;
  399.  
  400.                 // VARIABLES FOR PROFIT
  401.                 public int RunesOnGE = 0, initMoney = 0, initRunes = 0, currentMoney = 0, currentRunes = 0;
  402.                 public long startTime = 0;
  403.  
  404.                 Item() {
  405.                         this.name = "nature rune";
  406.                         this.ID = 561;
  407.                         this.Price = 133;
  408.                         this.PriceDiff = 1;
  409.                         this.BuyQuantity = 250000;
  410.                         this.TIME_TILL_PRICE_CHG = 1200000;
  411.                         lastTransaction = System.currentTimeMillis();
  412.                 }
  413.         }
  414.  
  415.         @Override
  416.         public void onRepaint(Graphics g) {
  417.                 Rectangle paintBox = new Rectangle(5, 345, 510, 130);
  418.  
  419.                 long hours = 0, minutes = 0, seconds = 0;
  420.                 // CALCULATE TOTAL RUNTIME
  421.                 long runTime = System.currentTimeMillis() - item1.startTime;
  422.  
  423.                 seconds = runTime / 1000;
  424.  
  425.                 if (seconds >= 60) {
  426.                         minutes = seconds / 60;
  427.                         seconds -= minutes * 60;
  428.                 }
  429.                 if (minutes >= 60) {
  430.                         hours = minutes / 60;
  431.                         minutes -= hours * 60;
  432.                 }
  433.  
  434.                 if (!paintBox.contains(mouseSpot)) {
  435.                         int secTilCanc;
  436.                         secTilCanc = (int) ((item1.TIME_TILL_PRICE_CHG - (System.currentTimeMillis() - item1.lastTransaction)) / 1000);
  437.  
  438.                         int minTillCanc = (secTilCanc / 60);
  439.                         secTilCanc = secTilCanc - (minTillCanc * 60);
  440.  
  441.                         g.setColor(Color.BLACK);
  442.                         g.setFont(new Font("Bodoni MT", 0, 13));
  443.                         g.fill3DRect(5, 345, 510, 130, true);
  444.                         g.setColor(Color.WHITE);
  445.                         g.drawString("Grand Exchange Item Flipper", 10, 360);
  446.                         g.drawString("Cancel Timer:  " + minTillCanc + ":" + secTilCanc, 10, 380);
  447.  
  448.                         // MONEY MADE = CURRENTMONEY + (RUNESINGE + RUNESININV * PRICE) +  - (STARTMONEY + (RUNES IN INV * PRICE));
  449.  
  450.                         int totalInitMoney = (item1.initMoney + (item1.initRunes * item1.Price));
  451.                         int moneyInGE = item1.RunesOnGE * item1.Price;
  452.                         int moneyInInv = item1.currentMoney + (item1.currentRunes * item1.Price);
  453.                         int profit = (moneyInInv + moneyInGE) - totalInitMoney;
  454.  
  455.                         double goldPerHour = (((float) profit / (float) runTime) * (float) (60 * 60 * 1000));
  456.  
  457.                         g.drawString("Starting money:  " + addCommas(totalInitMoney), 250, 360);
  458.                         g.drawString("Items in ge:  " + addCommas(item1.RunesOnGE), 250, 380);
  459.                         g.drawString("Money in ge:  " + addCommas(moneyInGE), 250, 400);
  460.                         g.drawString("Cur money in inv:  " + addCommas(moneyInInv), 250, 420);
  461.                         g.drawString("Profit:  " + addCommas(profit), 250, 440);
  462.  
  463.                         g.drawString("Time Ran  " + hours + ":" + minutes + ":" + seconds, 10, 400);
  464.                         g.drawString("Profit/Hour:  " + addCommas((int) goldPerHour), 10, 420);
  465.  
  466.                 }
  467.         }
  468.  
  469.         private Point mouseSpot;
  470.  
  471.         public void mouseDragged(MouseEvent e) {
  472.         }
  473.  
  474.         @Override
  475.         public void mouseMoved(MouseEvent e) {
  476.                 mouseSpot = e.getPoint();
  477.         }
  478.  
  479.         String addCommas(int bignum) {
  480.                 String num = Integer.toString(bignum);
  481.                 if (num.length() < 4) {
  482.                         return num;
  483.                 }
  484.                 String num2 = num.substring(0, ((num.length() - 1) % 3) + 1);
  485.  
  486.                 for (int i = ((num.length() - 1) % 3) + 1; i < num.length(); i = i + 3) {
  487.                         num2 = num2 + "," + num.substring(i, i + 3);
  488.                 }
  489.                 return num2;
  490.         }
  491.  
  492. }
Advertisement
Add Comment
Please, Sign In to add comment