Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.RSBot.Configuration;
- import org.RSBot.event.listeners.PaintListener;
- import org.RSBot.script.Script;
- import org.RSBot.script.ScriptManifest;
- import org.RSBot.script.methods.*;
- import org.RSBot.script.methods.GrandExchange.GEItem;
- import org.RSBot.script.wrappers.*;
- @ScriptManifest(authors = {"tholomew"}, keywords = {"tholomew merchant pure ess essence"}, name = "MerchantBot", description = "A simple and stable pure essence merchanting bot.", version = 1)
- public class MerchantBot extends Script{
- public static final int[] GRAND_EXCHANGE_CLERK = { 6528, 6529 , 1419, 2240, 2241, 2593};
- public static final int essBuyingLimit = 25000;
- public int startingCoins = 0;
- public int currentCoins = 0;
- public String state = "";
- private int[] collectBoxes = { 209, 211 };
- public int sellPrice = 0;
- public int buyPrice = 0;
- public boolean foundPrices = false;
- public int secondsWaitedForOffer = 0;
- public boolean everythingIsSold = true;
- public boolean buyOfferOpen = false;
- public boolean sellOfferOpen = false;
- public int[] previousPrices; //used later to detect price fluctuations
- @Override
- public boolean onStart() {
- if(game.isLoggedIn())
- {
- if(inventory.contains(995))
- {
- RSItem coins = inventory.getItem(995);
- if(coins.getStackSize() >= 3000000)
- {
- startingCoins = coins.getStackSize();
- log.info("Starting GP: "+startingCoins);
- }else{
- log.severe("You must start with at least 3 Million GP! You have: "+coins.getStackSize());
- stopScript();
- }
- }
- }
- else{
- game.login();
- }
- return true;
- }
- private void openGE()
- {
- state = "Opening the Grand Exchange...";
- RSNPC clerk = npcs.getNearest(GrandExchange.GRAND_EXCHANGE_CLERK);
- if (clerk != null)
- {
- clerk.interact("Exchange " + clerk.getName());
- sleep(1000, 2000);
- }
- }
- public void checkPrices(int box)
- {
- openGE();
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- grandExchange.openBuy(1);
- sleep(random(200,700));
- grandExchange.searchItem(7936);
- sleep(random(200,700));
- grandExchange.setQuantity("1");
- sleep(random(200,700));
- for(int i = 0; i < random(2,4); i++)
- grandExchange.fivePercentUp();
- grandExchange.clickConfirm();
- }else
- {
- log.severe("Your box number 1 MUST be open.");
- stopScript();
- }
- waitUntilCompleted();
- if(GrandExchange.checkCompleted(1)) //find sell price
- {
- String itemBought = "";
- int itemBoughtParsed;
- int moneyBack = 0;
- grandExchange.openBox(1);
- sleep(random(1000,1250));
- moneyBack = interfaces.get(105).getComponent(206).getComponentStackSize();
- itemBought = interfaces.get(105).getComponent(153).getText();
- itemBought = itemBought.replace(" gp", "");
- itemBought = itemBought.replace(",", "");
- itemBoughtParsed = Integer.parseInt(itemBought);
- sellPrice = (itemBoughtParsed - moneyBack);
- sleep(random(250, 700));
- interfaces.get(105).getComponent(206).doClick(true);
- sleep(random(200,700));
- interfaces.get(105).getComponent(208).doClick(true);
- log.info("Sell Price: "+sellPrice);
- }
- waitUntilCompleted();
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- grandExchange.openSell(1);
- sleep(random(200,700));
- inventory.getItem(7936).doClick(true);
- sleep(random(1000,1250));
- sleep(random(300,560));
- for(int i = 0; i < random(3,4); i++)
- grandExchange.fivePercentDown();
- sleep(random(200,700));
- grandExchange.clickConfirm();
- }
- waitUntilCompleted();
- if(GrandExchange.checkCompleted(1)) //find buy price
- {
- grandExchange.openBox(1);
- sleep(random(750,1250));
- buyPrice = interfaces.get(105).getComponent(206).getComponentStackSize();
- sleep(random(200,700));
- interfaces.get(105).getComponent(206).doClick(true);
- sleep(random(200,700));
- log.info("Buy Price: "+buyPrice);
- sleep(random(300,750));
- }
- foundPrices = true;
- }
- public void createBuyOffer()
- {
- if(!grandExchange.isOpen())
- openGE();
- sleep(random(300,750));
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- sleep(random(300,750));
- grandExchange.openBuy(1);
- sleep(random(300,750));
- grandExchange.searchItem(7936);
- sleep(random(300,750));
- grandExchange.setPrice(""+buyPrice);
- sleep(random(300,750));
- grandExchange.setQuantity(""+essBuyingLimit);
- sleep(random(500,1000));
- grandExchange.clickConfirm();
- sleep(random(300,750));
- }
- else{
- log.severe("YOU MUST HAVE YOUR FIRST BOX OPEN!");
- stopScript();
- }
- buyOfferOpen = true;
- }
- public void createSellOffer()
- {
- if(!grandExchange.isOpen())
- openGE();
- sleep(random(300,750));
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- sleep(random(300,750));
- grandExchange.openSell(1);
- sleep(random(300,750));
- inventory.getItem(7936).doClick(true);
- sleep(random(1000,1500));
- grandExchange.setPrice(""+sellPrice);
- sleep(random(750,1000));
- grandExchange.sellAll();
- sleep(random(750,1000));
- grandExchange.clickConfirm();
- sleep(random(750,1000));
- }
- else
- {
- log.severe("OMGXZZZ WE GOTS LIEK ERRORS N SHITS!");
- stopScript();
- }
- }
- public void waitUntilCompleted()
- {
- boolean complete = false;
- while(complete == false)
- {
- if(GrandExchange.isSlotFinished(1));
- complete = true;
- sleep(random(1000,3000));
- }
- }
- public boolean waitUntilSellOfferCompletes()
- {
- int secondsToWait = random(1200,1800);
- boolean complete = false;
- /*sleep(random(300,750));
- grandExchange.openBox(1);*/
- while(complete == false)
- {
- if(!interfaces.getComponent(105, grandExchange.INTERFACE_GRAND_EXCHANGE_OFFER_BOXES[0]).containsAction("Abort Offer"));
- complete = true;
- sleep(1000);
- secondsWaitedForOffer++;
- if(secondsWaitedForOffer >= secondsToWait)
- return false;
- }
- return true;
- }
- public boolean waitUntilBuyOfferCompletes()
- {
- int secondsToWait = random(1200,1800);
- boolean complete = false;
- /*sleep(random(300,750));
- grandExchange.openBox(1);*/
- while(complete == false)
- {
- if(!interfaces.getComponent(105, grandExchange.INTERFACE_GRAND_EXCHANGE_OFFER_BOXES[0]).containsAction("Abort Offer"));
- complete = true;
- sleep(1000);
- secondsWaitedForOffer++;
- if(secondsWaitedForOffer >= secondsToWait)
- return false;
- }
- log.info("Buy Offer Finished. Total Seconds Waited: "+secondsWaitedForOffer);
- return true;
- }
- public int loop()
- {
- if(foundPrices == false)
- checkPrices(1);
- if(buyOfferOpen == false && sellOfferOpen == false)
- createBuyOffer();
- if(!waitUntilBuyOfferCompletes())
- {
- //get new prices
- }else{
- boolean successfulCollect = false;
- while(!successfulCollect)
- {
- sleep(random(300,750));
- grandExchange.openBox(1);
- sleep(random(300,750));
- if(interfaces.get(105).getComponent(206).isValid())
- interfaces.get(105).getComponent(206).doClick(true);
- sleep(random(200,600));
- if(interfaces.get(105).getComponent(208).isValid())
- interfaces.get(105).getComponent(208).doClick(true);
- sleep(random(2000,3000));
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- successfulCollect = true;
- buyOfferOpen = false;
- }
- sleep(random(1000,1500));
- }
- }
- sleep(random(300,750));
- if(buyOfferOpen == false && sellOfferOpen == false)
- createSellOffer();
- sleep(random(300,750));
- if(!waitUntilSellOfferCompletes())
- {
- //checkAndDecreaseSellPrice();
- }else
- {
- sleep(random(300,750));
- boolean successfulCollect = false;
- while(!successfulCollect)
- {
- sleep(random(300,750));
- grandExchange.openBox(1);
- sleep(random(300,750));
- if(interfaces.get(105).getComponent(206).isValid())
- interfaces.get(105).getComponent(206).doClick(true);
- sleep(random(2000,3000));
- if(GrandExchange.checkSlotIsEmpty(1))
- {
- successfulCollect = true;
- sellOfferOpen = false;
- }
- sleep(random(1000,1500));
- }
- }
- return random(500, 1500);
- }
- @Override
- public void onFinish() {
- }
- }
Add Comment
Please, Sign In to add comment