Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.wrappers.RSNPC;
- @ScriptManifest(authors = { "Battleguard" }, version = 0.01, keywords = { "itemflipper2" }, description = "itemflipper2, by Battleguard", name = "itemflipper2")
- public class errorFreeItemFlipper extends Script implements PaintListener, MouseMotionListener {
- Rectangle itemBox;
- Item item1 = new Item();
- Box box = new Box();
- String action;
- Color backArrow = new Color(91, 85, 78);
- // INSTEAD OF DOING GET COMPONENT WE NEED TO MANUALLY GET THE VALUES
- // THIS WILL SERVE 2 PURPOSES
- // 1 WE CANNOT GET THE COMPONENT IF IT DOES NOT EXIST YET EXAMPLE NATURE RUNE CLICK TEXT FOR BUY
- // ALSO IT WILL GET RID OF ANY NULL POINTER EXCEPTIONS WE MAY ENCOUNTER
- // WE CAN ALSO TAKE A RISK APPROACH TO THIS PROBLEM BY MAKING SURE THAT WE ARE IN THE CORRECT SPOT B4
- // EVERY CLICK BY USING GAME.GETCOLOR(X,Y); AND COMPARING IT TO THE COLOR WE SHOULD EXPECT
- // IF COLOR IS LOAD THE PROGRAM WITH AN AUTOMATED RESET VECTOR
- public boolean onStart() {
- item1.startTime = System.currentTimeMillis();
- item1.initMoney = inventory.getItem(995).getStackSize();
- item1.initRunes = getInvItemCount();
- return true;
- }
- int commandsDone = 0;
- @Override
- public int loop() {
- try {
- if (!interfaces.getComponent(105, 15).getText().equalsIgnoreCase("grand exchange")) { // open grand exchange
- action = "Opening GE";
- RSNPC geNPC = npcs.getNearest(6528);
- geNPC.interact("Exchange Grand Exchange clerk");
- sleep(3000);
- return 50;
- }
- item1.currentRunes = getInvItemCount();
- item1.currentMoney = inventory.getItem(995).getStackSize();
- } catch (Exception e) {
- log("problem opening up the GE Main Menu");
- }
- if (buy()) {
- return 50;
- }
- if (sell()) {
- return 50;
- }
- if (checkBuy()) {
- return 50;
- }
- if (checkSell()) {
- return 50;
- }
- if (checkCancelSell()) {
- return 50;
- }
- if (checkTimer()) {
- return 50;
- }
- // TEMPORARY ANTIBAN
- int i = random(0, 3);
- if (i == 0) {
- camera.moveRandomly(500);
- } else if (i == 2) {
- mouse.moveSlightly();
- } else if (i == 3) {
- mouse.click(mouse.getLocation().x + random(0, 100), mouse.getLocation().y + random(0, 100), false);
- }
- return 1000;
- }
- // POINTS THAT NEED TO BE CLICKED
- // ALL POINTS ARE MADE AS RECTANGLES OF ON SCREEN POSITIONS
- // THIS IS DONE TO ENSURE NO GETCOMPONENT() ERRORS OCCUR
- Rectangle buyButtonBox = new Rectangle(54, 132, 35, 35);
- Rectangle buyBox = new Rectangle(34, 84, 140, 110);
- Rectangle searchSelectBox = new Rectangle(69, 343, 418, 11);
- Rectangle enterQuantityBox = new Rectangle(220, 209, 35, 25);
- Rectangle enterPriceBox = new Rectangle(370, 209, 35, 25);
- Rectangle confirmBox = new Rectangle(204, 274, 120, 43);
- // box already made rectangle
- Rectangle cancelButtonBox = new Rectangle(354, 276, 20, 20);
- Rectangle collectCoinsBox = new Rectangle(401, 282, 36, 32);
- Rectangle collectGoodsBox = new Rectangle(450, 282, 36, 32);
- Rectangle backButtonBox = new Rectangle(29, 280, 35, 35);
- // sell boxes
- Rectangle sellBox = new Rectangle(190, 84, 140, 110);
- Rectangle sellButtonBox = new Rectangle(273, 132, 35, 35);
- // METHOD TO CLICK ON A RECTANGLE IN MY INTERFACE
- void clickBox(Rectangle BOX) {
- Point clickSpot = new Point((BOX.x + random(0, BOX.width)), (BOX.y + random(0, BOX.height)));
- clickAndSleep(clickSpot);
- }
- // METHOD TO MAKE SURE EVERY CLICK SLEEPS AFTER SO I DO NOT NEED TO MESS WITH SLEEPS
- void clickAndSleep(Point spot) {
- mouse.click(spot, true);
- sleep(1500);
- }
- // TYPES IN STRING AND HITS ENTER
- void typeAndSleep(String text) {
- keyboard.sendText(text, true);
- sleep(1500);
- }
- void pressBackButton() {
- clickBox(backButtonBox);
- }
- // METHOD THAT HANDLES BUYING AN ITEM
- boolean buy() {
- try {
- // USED FOR CALCULATING PROFITS
- int oldMoney = inventory.getItem(995).getStackSize();
- // USED FOR CALCULATING PROFITS
- if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("empty")) {
- pressBackButton();
- clickBox(buyButtonBox);
- typeAndSleep(item1.name);
- clickBox(searchSelectBox);
- clickBox(enterQuantityBox);
- typeAndSleep("" + item1.BuyQuantity);
- clickBox(enterPriceBox);
- typeAndSleep("" + item1.Price);
- clickBox(confirmBox);
- box.statusBar0 = 0;
- // USED FOR CALCULATING PROFITS
- // ON BUY RUNEINGE+= ((newMoney - oldMoney) / item1.price)
- int newMoney = inventory.getItem(995).getStackSize();
- item1.RunesOnGE += ((oldMoney - newMoney) / item1.Price);
- // USED FOR CALCULATING PROFITS
- return true;
- }
- } catch (Exception e) {
- log("Was not able to access name on BUYBOX");
- }
- return false;
- }
- // METHOD THAT HANDLES SELLING AN ITEM
- boolean sell() {
- try {
- if (inventory.getCount(this.item1.ID) > 0) { // MAKE SURE WE HAVE ITEMS TO SELL
- if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("empty")) { // MAKE SURE SELL BOX IS EMPTY
- // USED FOR CALCULATING PROFIT
- int oldRunes = getInvItemCount();
- // USED FOR CALCULATING PROFIT
- pressBackButton();
- clickBox(sellButtonBox);
- clickAndSleep(inventory.getItem(item1.ID).getPoint());
- clickBox(enterPriceBox);
- typeAndSleep("" + (item1.Price + item1.PriceDiff));
- clickBox(confirmBox);
- box.statusBar1 = 0;
- // USED FOR CALCULATING PROFIT
- // ON SELL RUNEINGE+= INV.GETCOUNT(ITEM1.ID)
- int newRunes = getInvItemCount();
- item1.RunesOnGE += (oldRunes - newRunes);
- // USED FOR CALCULATING PROFIT
- return true;
- }
- }
- } catch (Exception e) {
- log("Was not able to access name on SELLBOX");
- }
- return false;
- }
- boolean checkBuy() {
- try {
- if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
- int currentBar = interfaces.getComponent(105, 19).getComponent(13).getArea().width;
- if (currentBar > box.statusBar0) {
- pressBackButton();
- collectItems(buyBox);
- box.statusBar0 = currentBar;
- return true;
- }
- }
- } catch (Exception e) {
- log("Problem checking status bar for BUY");
- }
- return false;
- }
- boolean checkSell() {
- try {
- if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
- int currentBar = interfaces.getComponent(105, 35).getComponent(13).getArea().width;
- if (currentBar > box.statusBar1) {
- pressBackButton();
- collectItems(sellBox);
- box.statusBar1 = currentBar;
- return true;
- }
- }
- } catch (Exception e) {
- log("Problem Cancelling Sell");
- }
- return false;
- }
- boolean checkCancelSell() {
- try {
- if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
- if (inventory.getCount(item1.ID) > 0) {
- if (inventory.getItem(item1.ID).getStackSize() > 500) {
- cancelsell();
- return true;
- }
- }
- }
- } catch (Exception e) {
- log("Problem cancelling SELL");
- }
- return false;
- }
- void cancelsell() {
- // USED FOR CALCULATING PROFITS
- int oldRunes = getInvItemCount();
- int oldMoney = inventory.getItem(995).getStackSize();
- // USED FOR CALCULATING PROFITS
- pressBackButton();
- clickBox(sellBox); // CLICK SELL BOX
- clickBox(cancelButtonBox); // CLICK CANCEL BUTTON
- clickBox(collectCoinsBox); // COLLECT COINS
- clickBox(collectGoodsBox); // COLLECT GOODS
- clickBox(backButtonBox); // HIT BACK BUTTON
- // USED FOR CALCULATING PROFIT
- // ON CANCELSELL RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
- int newRunes = getInvItemCount();
- int newMoney = inventory.getItem(995).getStackSize();
- item1.RunesOnGE -= ((newRunes - oldRunes) + ((newMoney - oldMoney) / (item1.Price + item1.PriceDiff)));
- // USED FOR CALCULATING PROFIT
- }
- void cancelBuy() {
- // USED FOR CALCULATING PROFITS
- int oldRunes = getInvItemCount();
- int oldMoney = inventory.getItem(995).getStackSize();
- // USED FOR CALCULATING PROFITS
- pressBackButton();
- clickBox(buyBox); // CLICK SELL BOX
- clickBox(cancelButtonBox); // CLICK CANCEL BUTTON
- clickBox(collectCoinsBox); // COLLECT COINS
- clickBox(collectGoodsBox); // COLLECT GOODS
- clickBox(backButtonBox); // HIT BACK BUTTON
- // USED FOR CALCULATING PROFIT
- // ON CANCELBUY RUNESINGE -= (NEWRUNES - OLDRUNES)
- int newRunes = getInvItemCount();
- int newMoney = inventory.getItem(995).getStackSize();
- newRunes += (newMoney - oldMoney) / item1.Price;
- item1.RunesOnGE -= (newRunes - oldRunes);
- // USED FOR CALCULATING PROFIT
- }
- // CALCULATING PROFITS
- // MONEY MADE = CURRENTMONEY + (RUNESINGE + RUNESININV * PRICE) + - (STARTMONEY + (RUNES IN INV * PRICE));
- // CALCULATING RUNES IN GE
- // ON START GET INITMONEY & RUNESININV
- // ON BUY RUNEINGE+= ITEM1.BUYQUANTITY
- // ON SELL RUNEINGE+= INV.GETCOUNT(ITEM1.ID)
- // ON CHECKBAR RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
- // ON CANCELSELL RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
- // ON CANCELBUY RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (ITEM1.PRICE))
- boolean checkTimer() {
- try {
- if (System.currentTimeMillis() - item1.lastTransaction > item1.TIME_TILL_PRICE_CHG) {
- // IF SELL END IF THE PROBLEM REDUCE PRICE
- if (interfaces.getComponent(105, 35).getComponent(10).getText().equalsIgnoreCase("sell")) {
- log("CANCELLING SELLITEMS");
- cancelsell();
- if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
- log("CANCELLING BUYITEMS");
- cancelBuy();
- }
- item1.Price--;
- item1.lastTransaction = System.currentTimeMillis();
- return true;
- }
- // IF BUY END IF THE PROBLEM INCREASE PRICE
- if (interfaces.getComponent(105, 19).getComponent(10).getText().equalsIgnoreCase("buy")) {
- log("CANCELLING BUYITEMS");
- cancelBuy();
- item1.Price++;
- item1.lastTransaction = System.currentTimeMillis();
- return true;
- }
- }
- } catch (Exception e) {
- log("Problem cancelling SELL");
- }
- return false;
- }
- void collectItems(Rectangle boxWindow) {
- // CHECK TO SEE WE SHOULD UPDATE TIMER ( > 500 ITEMS SOLD)
- int oldMoney = inventory.getItem(995).getStackSize();
- int oldItems = getInvItemCount();
- clickBox(boxWindow);
- clickBox(collectCoinsBox);
- clickBox(collectGoodsBox);
- clickBox(backButtonBox);
- int newMoney = inventory.getItem(995).getStackSize();
- int newItems = getInvItemCount();
- if (newItems - oldItems > 500) {
- // UPDATE COUNTER 500 ITEMS BOUGHT
- item1.lastTransaction = System.currentTimeMillis();
- }
- if (newMoney - oldMoney > 500 * (item1.Price + item1.PriceDiff)) {
- // UPDATE COUNTER 500 ITEMS SOLD
- item1.lastTransaction = System.currentTimeMillis();
- }
- // USED FOR CALCULATING PROFIT
- // ON CHECKBAR RUNESINGE -= (CHANGE IN RUNES IN INV + CHANGEINMONEY / (item1.Price + item1.PriceDiff))
- item1.RunesOnGE -= ((newItems - oldItems) + ((newMoney - oldMoney) / (item1.Price + item1.PriceDiff)));
- // USED FOR CALCULATING PROFIT
- }
- int getInvItemCount() {
- if (inventory.getCount(item1.ID) > 0) {
- return inventory.getItem(item1.ID).getStackSize();
- }
- return 0;
- }
- public void onFinish() {
- log("Thank you for using the script!");
- }
- class Box {
- private int statusBar0;
- private int statusBar1;
- Box() {
- statusBar0 = 0;
- statusBar1 = 0;
- }
- }
- class Item {
- public int ID;
- public String name;
- public int Price;
- public int BuyQuantity;
- public long TIME_TILL_PRICE_CHG;
- public long lastTransaction;
- public int PriceDiff;
- // VARIABLES FOR PROFIT
- public int RunesOnGE = 0, initMoney = 0, initRunes = 0, currentMoney = 0, currentRunes = 0;
- public long startTime = 0;
- Item() {
- this.name = "nature rune";
- this.ID = 561;
- this.Price = 133;
- this.PriceDiff = 1;
- this.BuyQuantity = 250000;
- this.TIME_TILL_PRICE_CHG = 1200000;
- lastTransaction = System.currentTimeMillis();
- }
- }
- @Override
- public void onRepaint(Graphics g) {
- Rectangle paintBox = new Rectangle(5, 345, 510, 130);
- long hours = 0, minutes = 0, seconds = 0;
- // CALCULATE TOTAL RUNTIME
- long runTime = System.currentTimeMillis() - item1.startTime;
- seconds = runTime / 1000;
- if (seconds >= 60) {
- minutes = seconds / 60;
- seconds -= minutes * 60;
- }
- if (minutes >= 60) {
- hours = minutes / 60;
- minutes -= hours * 60;
- }
- if (!paintBox.contains(mouseSpot)) {
- int secTilCanc;
- secTilCanc = (int) ((item1.TIME_TILL_PRICE_CHG - (System.currentTimeMillis() - item1.lastTransaction)) / 1000);
- int minTillCanc = (secTilCanc / 60);
- secTilCanc = secTilCanc - (minTillCanc * 60);
- g.setColor(Color.BLACK);
- g.setFont(new Font("Bodoni MT", 0, 13));
- g.fill3DRect(5, 345, 510, 130, true);
- g.setColor(Color.WHITE);
- g.drawString("Grand Exchange Item Flipper", 10, 360);
- g.drawString("Cancel Timer: " + minTillCanc + ":" + secTilCanc, 10, 380);
- // MONEY MADE = CURRENTMONEY + (RUNESINGE + RUNESININV * PRICE) + - (STARTMONEY + (RUNES IN INV * PRICE));
- int totalInitMoney = (item1.initMoney + (item1.initRunes * item1.Price));
- int moneyInGE = item1.RunesOnGE * item1.Price;
- int moneyInInv = item1.currentMoney + (item1.currentRunes * item1.Price);
- int profit = (moneyInInv + moneyInGE) - totalInitMoney;
- double goldPerHour = (((float) profit / (float) runTime) * (float) (60 * 60 * 1000));
- g.drawString("Starting money: " + addCommas(totalInitMoney), 250, 360);
- g.drawString("Items in ge: " + addCommas(item1.RunesOnGE), 250, 380);
- g.drawString("Money in ge: " + addCommas(moneyInGE), 250, 400);
- g.drawString("Cur money in inv: " + addCommas(moneyInInv), 250, 420);
- g.drawString("Profit: " + addCommas(profit), 250, 440);
- g.drawString("Time Ran " + hours + ":" + minutes + ":" + seconds, 10, 400);
- g.drawString("Profit/Hour: " + addCommas((int) goldPerHour), 10, 420);
- }
- }
- private Point mouseSpot;
- public void mouseDragged(MouseEvent e) {
- }
- @Override
- public void mouseMoved(MouseEvent e) {
- mouseSpot = e.getPoint();
- }
- String addCommas(int bignum) {
- String num = Integer.toString(bignum);
- if (num.length() < 4) {
- return num;
- }
- String num2 = num.substring(0, ((num.length() - 1) % 3) + 1);
- for (int i = ((num.length() - 1) % 3) + 1; i < num.length(); i = i + 3) {
- num2 = num2 + "," + num.substring(i, i + 3);
- }
- return num2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment