Guest User

Untitled

a guest
Jan 4th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. import org.RSBot.Configuration;
  2. import org.RSBot.event.listeners.PaintListener;
  3. import org.RSBot.script.Script;
  4. import org.RSBot.script.ScriptManifest;
  5. import org.RSBot.script.methods.*;
  6. import org.RSBot.script.methods.GrandExchange.GEItem;
  7. import org.RSBot.script.wrappers.*;
  8. @ScriptManifest(authors = {"tholomew"}, keywords = {"tholomew merchant pure ess essence"}, name = "MerchantBot", description = "A simple and stable pure essence merchanting bot.", version = 1)
  9. public class MerchantBot extends Script{
  10. public static final int[] GRAND_EXCHANGE_CLERK = { 6528, 6529 , 1419, 2240, 2241, 2593};
  11. public static final int essBuyingLimit = 25000;
  12. public int startingCoins = 0;
  13. public int currentCoins = 0;
  14. public String state = "";
  15. private int[] collectBoxes = { 209, 211 };
  16. public int sellPrice = 0;
  17. public int buyPrice = 0;
  18. public boolean foundPrices = false;
  19. public int secondsWaitedForOffer = 0;
  20. public boolean everythingIsSold = true;
  21. public boolean buyOfferOpen = false;
  22. public boolean sellOfferOpen = false;
  23. public int[] previousPrices; //used later to detect price fluctuations
  24. @Override
  25. public boolean onStart() {
  26. if(game.isLoggedIn())
  27. {
  28. if(inventory.contains(995))
  29. {
  30. RSItem coins = inventory.getItem(995);
  31. if(coins.getStackSize() >= 3000000)
  32. {
  33. startingCoins = coins.getStackSize();
  34. log.info("Starting GP: "+startingCoins);
  35. }else{
  36. log.severe("You must start with at least 3 Million GP! You have: "+coins.getStackSize());
  37. stopScript();
  38. }
  39. }
  40. }
  41. else{
  42. game.login();
  43. }
  44. return true;
  45. }
  46. private void openGE()
  47. {
  48. state = "Opening the Grand Exchange...";
  49. RSNPC clerk = npcs.getNearest(GrandExchange.GRAND_EXCHANGE_CLERK);
  50. if (clerk != null)
  51. {
  52. clerk.interact("Exchange " + clerk.getName());
  53. sleep(1000, 2000);
  54. }
  55. }
  56. public void checkPrices(int box)
  57. {
  58. openGE();
  59. if(GrandExchange.checkSlotIsEmpty(1))
  60. {
  61. grandExchange.openBuy(1);
  62. sleep(random(200,700));
  63. grandExchange.searchItem(7936);
  64. sleep(random(200,700));
  65. grandExchange.setQuantity("1");
  66. sleep(random(200,700));
  67. for(int i = 0; i < random(2,4); i++)
  68. grandExchange.fivePercentUp();
  69. grandExchange.clickConfirm();
  70. }else
  71. {
  72. log.severe("Your box number 1 MUST be open.");
  73. stopScript();
  74. }
  75. waitUntilCompleted();
  76. if(GrandExchange.checkCompleted(1)) //find sell price
  77. {
  78. String itemBought = "";
  79. int itemBoughtParsed;
  80. int moneyBack = 0;
  81. grandExchange.openBox(1);
  82. sleep(random(1000,1250));
  83. moneyBack = interfaces.get(105).getComponent(206).getComponentStackSize();
  84. itemBought = interfaces.get(105).getComponent(153).getText();
  85. itemBought = itemBought.replace(" gp", "");
  86. itemBought = itemBought.replace(",", "");
  87. itemBoughtParsed = Integer.parseInt(itemBought);
  88. sellPrice = (itemBoughtParsed - moneyBack);
  89. sleep(random(250, 700));
  90. interfaces.get(105).getComponent(206).doClick(true);
  91. sleep(random(200,700));
  92. interfaces.get(105).getComponent(208).doClick(true);
  93. log.info("Sell Price: "+sellPrice);
  94. }
  95. waitUntilCompleted();
  96. if(GrandExchange.checkSlotIsEmpty(1))
  97. {
  98. grandExchange.openSell(1);
  99. sleep(random(200,700));
  100. inventory.getItem(7936).doClick(true);
  101. sleep(random(1000,1250));
  102. sleep(random(300,560));
  103. for(int i = 0; i < random(3,4); i++)
  104. grandExchange.fivePercentDown();
  105. sleep(random(200,700));
  106. grandExchange.clickConfirm();
  107. }
  108. waitUntilCompleted();
  109. if(GrandExchange.checkCompleted(1)) //find buy price
  110. {
  111. grandExchange.openBox(1);
  112. sleep(random(750,1250));
  113. buyPrice = interfaces.get(105).getComponent(206).getComponentStackSize();
  114. sleep(random(200,700));
  115. interfaces.get(105).getComponent(206).doClick(true);
  116. sleep(random(200,700));
  117. log.info("Buy Price: "+buyPrice);
  118. sleep(random(300,750));
  119. }
  120. foundPrices = true;
  121. }
  122. public void createBuyOffer()
  123. {
  124. if(!grandExchange.isOpen())
  125. openGE();
  126. sleep(random(300,750));
  127. if(GrandExchange.checkSlotIsEmpty(1))
  128. {
  129. sleep(random(300,750));
  130. grandExchange.openBuy(1);
  131. sleep(random(300,750));
  132. grandExchange.searchItem(7936);
  133. sleep(random(300,750));
  134. grandExchange.setPrice(""+buyPrice);
  135. sleep(random(300,750));
  136. grandExchange.setQuantity(""+essBuyingLimit);
  137. sleep(random(500,1000));
  138. grandExchange.clickConfirm();
  139. sleep(random(300,750));
  140. }
  141. else{
  142. log.severe("YOU MUST HAVE YOUR FIRST BOX OPEN!");
  143. stopScript();
  144. }
  145. buyOfferOpen = true;
  146. }
  147. public void createSellOffer()
  148. {
  149. if(!grandExchange.isOpen())
  150. openGE();
  151. sleep(random(300,750));
  152. if(GrandExchange.checkSlotIsEmpty(1))
  153. {
  154. sleep(random(300,750));
  155. grandExchange.openSell(1);
  156. sleep(random(300,750));
  157. inventory.getItem(7936).doClick(true);
  158. sleep(random(1000,1500));
  159. grandExchange.setPrice(""+sellPrice);
  160. sleep(random(750,1000));
  161. grandExchange.sellAll();
  162. sleep(random(750,1000));
  163. grandExchange.clickConfirm();
  164. sleep(random(750,1000));
  165. }
  166. else
  167. {
  168. log.severe("OMGXZZZ WE GOTS LIEK ERRORS N SHITS!");
  169. stopScript();
  170. }
  171. }
  172. public void waitUntilCompleted()
  173. {
  174. boolean complete = false;
  175. while(complete == false)
  176. {
  177. if(GrandExchange.isSlotFinished(1));
  178. complete = true;
  179. sleep(random(1000,3000));
  180. }
  181. }
  182. public boolean waitUntilSellOfferCompletes()
  183. {
  184. int secondsToWait = random(1200,1800);
  185. boolean complete = false;
  186. /*sleep(random(300,750));
  187. grandExchange.openBox(1);*/
  188. while(complete == false)
  189. {
  190. if(!interfaces.getComponent(105, grandExchange.INTERFACE_GRAND_EXCHANGE_OFFER_BOXES[0]).containsAction("Abort Offer"));
  191. complete = true;
  192. sleep(1000);
  193. secondsWaitedForOffer++;
  194. if(secondsWaitedForOffer >= secondsToWait)
  195. return false;
  196. }
  197. return true;
  198. }
  199. public boolean waitUntilBuyOfferCompletes()
  200. {
  201.  
  202. int secondsToWait = random(1200,1800);
  203. boolean complete = false;
  204. /*sleep(random(300,750));
  205. grandExchange.openBox(1);*/
  206. while(complete == false)
  207. {
  208. if(!interfaces.getComponent(105, grandExchange.INTERFACE_GRAND_EXCHANGE_OFFER_BOXES[0]).containsAction("Abort Offer"));
  209. complete = true;
  210. sleep(1000);
  211. secondsWaitedForOffer++;
  212. if(secondsWaitedForOffer >= secondsToWait)
  213. return false;
  214. }
  215. log.info("Buy Offer Finished. Total Seconds Waited: "+secondsWaitedForOffer);
  216. return true;
  217. }
  218. public int loop()
  219. {
  220. if(foundPrices == false)
  221. checkPrices(1);
  222. if(buyOfferOpen == false && sellOfferOpen == false)
  223. createBuyOffer();
  224. if(!waitUntilBuyOfferCompletes())
  225. {
  226. //get new prices
  227. }else{
  228. boolean successfulCollect = false;
  229. while(!successfulCollect)
  230. {
  231. sleep(random(300,750));
  232. grandExchange.openBox(1);
  233. sleep(random(300,750));
  234. if(interfaces.get(105).getComponent(206).isValid())
  235. interfaces.get(105).getComponent(206).doClick(true);
  236. sleep(random(200,600));
  237. if(interfaces.get(105).getComponent(208).isValid())
  238. interfaces.get(105).getComponent(208).doClick(true);
  239. sleep(random(2000,3000));
  240.  
  241. if(GrandExchange.checkSlotIsEmpty(1))
  242. {
  243. successfulCollect = true;
  244. buyOfferOpen = false;
  245. }
  246.  
  247. sleep(random(1000,1500));
  248. }
  249. }
  250.  
  251. sleep(random(300,750));
  252. if(buyOfferOpen == false && sellOfferOpen == false)
  253. createSellOffer();
  254.  
  255. sleep(random(300,750));
  256. if(!waitUntilSellOfferCompletes())
  257. {
  258. //checkAndDecreaseSellPrice();
  259. }else
  260. {
  261. sleep(random(300,750));
  262. boolean successfulCollect = false;
  263. while(!successfulCollect)
  264. {
  265. sleep(random(300,750));
  266. grandExchange.openBox(1);
  267. sleep(random(300,750));
  268. if(interfaces.get(105).getComponent(206).isValid())
  269. interfaces.get(105).getComponent(206).doClick(true);
  270. sleep(random(2000,3000));
  271. if(GrandExchange.checkSlotIsEmpty(1))
  272. {
  273. successfulCollect = true;
  274. sellOfferOpen = false;
  275. }
  276. sleep(random(1000,1500));
  277. }
  278. }
  279. return random(500, 1500);
  280. }
  281. @Override
  282. public void onFinish() {
  283. }
  284.  
  285. }
Add Comment
Please, Sign In to add comment