BrownBirdScripts

BBtoadCollector

Aug 22nd, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.61 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Image;
  6. import java.awt.Point;
  7. import java.io.IOException;
  8. import java.net.URL;
  9.  
  10. import javax.imageio.ImageIO;
  11.  
  12. import java.awt.event.MouseEvent;
  13. import java.awt.Rectangle;
  14.  
  15. import org.osbot.script.MethodProvider;
  16. import org.osbot.script.Script;
  17. import org.osbot.script.ScriptManifest;
  18. import org.osbot.script.rs2.map.Position;
  19. import org.osbot.script.rs2.model.Entity;
  20. import org.osbot.script.rs2.model.Player;
  21. import org.osbot.script.rs2.model.RS2Object;
  22. import org.osbot.script.rs2.ui.Tab;
  23. import org.osbot.script.rs2.utility.Area;
  24.  
  25. @ScriptManifest(author = "BrownBird", name = "BBtoadCollector", version = 1.5, info = "Collects swamp toad for money || V1.5")
  26.  
  27. public class BBtoadCollector extends Script {
  28.  
  29. boolean hide = false;
  30. Point p;
  31. Rectangle close = new Rectangle(499, 274, 509, 287);
  32. Rectangle open = new Rectangle(464, 316, 514, 336);
  33. public String TOAD = "Swamp toad";
  34. public String STAIR = "Staircase";
  35. public String BANK = "Bank booth";
  36. String status = "Starting script";
  37. public long startTime = 0;
  38. public long millis = 0;
  39. public long hours = 0;
  40. public long minutes = 0;
  41. public long seconds = 0;
  42. public long last = 0;
  43. int itemCount = 0;
  44. int currentItemCount = -1;
  45. public int toadsPH;
  46. public long moneyMade;
  47. public int moneyPH;
  48. public String run = "False";
  49. int toadPrice;
  50.  
  51. // PATHS
  52. // Paths to swamp -
  53. private int[][] swampPath1 = new int[][] { { 2440, 3447 }, { 2433, 3461 },
  54. { 2428, 3474 }, { 2424, 3490 }, { 2421, 3501 },
  55. { 2419, 3508 } };
  56. private int[][] swampPath2 = new int[][] { { 2441, 3447 }, { 2432, 3458 },
  57. { 2431, 3473 }, { 2426, 3486 }, { 2425, 3500 },
  58. { 2420, 3508 } };
  59. private int[][] swampPath3 = new int[][] { { 2441, 3448 }, { 2436, 3460 },
  60. { 2431, 3471 }, { 2428, 3484 }, { 2428, 3498 },
  61. { 2419, 3507 } };
  62. // Paths to staircase -
  63. private int[][] bankPath1 = new int[][] { { 2419, 3508 }, { 2424, 3502 },
  64. { 2425, 3487 }, { 2427, 3471 }, { 2423, 3457 }, { 2437, 3449 },
  65. { 2445, 3437 } };
  66. private int[][] bankPath2 = new int[][] { { 2423, 3502 }, { 2428, 3488 },
  67. { 2436, 3478 }, { 2435, 3464 }, { 2438, 3450 }, { 2446, 3437 } };
  68. private int[][] bankPath3 = new int[][] { { 2426, 3500 }, { 2425, 3486 },
  69. { 2428, 3473 }, { 2436, 3461 }, { 2448, 3454 }, { 2434, 3443 },
  70. { 2446, 3437 } };
  71. private final Area swampArea = (new Area(2431, 3506, 2406, 3520));
  72. private final Area stairArea = (new Area(2442, 3432, 2449, 3440));
  73.  
  74.  
  75. @Override
  76. public void onStart() {
  77. log("BBtoadCollector Started!");
  78. startTime = System.currentTimeMillis();
  79.  
  80. }
  81.  
  82. @Override
  83. public void onExit() {
  84. log("Thanks for using BBtoadCollector!");
  85. log("Ran for: " + hours + ":" + minutes + ":" + seconds);
  86. log("Swamp toad collected: " + itemCount);
  87. log("Swamp toad collected P/H: " + toadsPH);
  88. log("Money Made: " + moneyMade);
  89. log("Money Made PH: " + moneyPH);
  90. log("Toad price: " + toadPrice);
  91. }
  92.  
  93. @Override
  94. public int onLoop() throws InterruptedException {
  95. Player player = myPlayer();
  96. Entity toad = closestGroundItemForName(TOAD);
  97. Entity stair = closestObjectForName(STAIR);
  98. Entity bank = closestObjectForName(BANK);
  99.  
  100. if(!Tab.INVENTORY.isOpen(null)) {
  101. openTab(Tab.INVENTORY);
  102. }
  103.  
  104. int amt = (int) client.getInventory().getAmount(TOAD);
  105. if(currentItemCount == -1) currentItemCount = amt;
  106. else if(amt < currentItemCount) {
  107. currentItemCount = amt;
  108. } else {
  109. itemCount += amt - currentItemCount;
  110. currentItemCount = amt;
  111. }
  112.  
  113. if (client.getInventory().getTotalItemsAmount() < 28
  114. && player.isInArea(swampArea)) {
  115. if (toad != null) {
  116. if (toad.isVisible()) {
  117. if (!player.isAnimating()) {
  118. if (!player.isMoving()) {
  119. status = "Picking up toad";
  120. toad.interact("Take");
  121. sleep(random(700,900));
  122. }
  123. }
  124. } else {
  125. if (!player.isAnimating()) {
  126. if (!player.isMoving()) {
  127. status = "Walking to toad";
  128. toad.getPosition().walkMinimap(bot);
  129. sleep(random(700, 900));
  130. }
  131. }
  132. }
  133. }
  134. }
  135.  
  136. if (client.getInventory().isFull() && player.getZ() == 0) {
  137. status = "Going to bank";
  138. if (!player.isMoving()) {
  139. walkToBank();
  140. }
  141. }
  142.  
  143. if (client.getInventory().isFull() && player.getZ() == 0 && player.isInArea(stairArea)) {
  144. if (stair != null) {
  145. if (!player.isAnimating() && !player.isMoving()) {
  146. if (stair.isVisible()) {
  147. status = "Climbing up stairs";
  148. stair.interact("Climb-Up");
  149. sleep(random(700,900));
  150. } else {
  151. client.moveCameraToEntity(stair);
  152. }
  153. }
  154. }
  155. }
  156.  
  157. if (client.getInventory().isFull() && player.getZ() == 1) {
  158. if (bank != null) {
  159. if (!player.isAnimating() && !player.isMoving()) {
  160. if (bank.isVisible()) {
  161. status = "Banking";
  162. bankDeposit();
  163. } else {
  164. client.rotateCameraToAngle(random(100, 180));
  165. }
  166. }
  167. }
  168. }
  169.  
  170. if (client.getInventory().isEmpty() && player.getZ() == 1) {
  171. if (stair != null) {
  172. if (!player.isAnimating() && !player.isMoving()) {
  173. if (stair.isVisible()) {
  174. status = "Climbing down stairs";
  175. stair.interact("Climb-down");
  176. } else {
  177. client.rotateCameraToAngle(350);
  178. }
  179. }
  180. }
  181. }
  182.  
  183. if (client.getInventory().getTotalItemsAmount() == 0
  184. && player.getZ() == 0) {
  185. status = "Going to swamp";
  186. if (!player.isMoving()) {
  187. walkToSwamp();
  188. }
  189. }
  190.  
  191. if (client.getRunEnergy() == 100 && run == "False") {
  192. status = "Toggling running";
  193. settingsTab.open();
  194. random(199, 246);
  195. setRunning(true);
  196. run = "True";
  197. }
  198.  
  199. if(run == "True" && client.getRunEnergy() < 100) {
  200. run = "False";
  201. }
  202.  
  203. AntiBan();
  204.  
  205. return random(500, 650);
  206. }
  207.  
  208. public void walkToBank() {
  209. switch (random(1, 3)) {
  210.  
  211. case 1:
  212. WalkAlongPath(bankPath1, true);
  213. case 2:
  214. WalkAlongPath(bankPath2, true);
  215. case 3:
  216. WalkAlongPath(bankPath3, true);
  217. }
  218. }
  219.  
  220. public void walkToSwamp() {
  221. switch (random(1, 3)) {
  222.  
  223. case 1:
  224. WalkAlongPath(swampPath1, true);
  225. case 2:
  226. WalkAlongPath(swampPath2, true);
  227. case 3:
  228. WalkAlongPath(swampPath3, true);
  229. }
  230.  
  231.  
  232. }
  233.  
  234. private Image getImage(String url) {
  235. try {
  236. return ImageIO.read(new URL(url));
  237. } catch (IOException e) {
  238. return null;
  239. }
  240. }
  241.  
  242. private final Color color1 = new Color(0, 0, 0);
  243.  
  244. private final Font font1 = new Font("Arial", 0, 14);
  245.  
  246. private final Image img1 = getImage("http://i40.tinypic.com/1zq4gv6.png");
  247. private final Image img2 = getImage("http://i39.tinypic.com/29y1hnc.png");
  248. private final Image img3 = getImage("http://i42.tinypic.com/2lbo0p5.png");
  249.  
  250. public void onPaint(Graphics graphics) {
  251. millis = System.currentTimeMillis() - startTime;
  252. hours = millis / (1000 * 60 * 60);
  253. millis -= hours * (1000 * 60 * 60);
  254. minutes = millis / (1000 * 60);
  255. millis -= minutes * (1000 * 60);
  256. seconds = millis / 1000;
  257. toadsPH = (int) ((itemCount) * 3600000D / (System.currentTimeMillis() - startTime));
  258. moneyMade = itemCount * toadPrice;
  259. moneyPH = (int) ((moneyMade) * 3600000D / (System.currentTimeMillis() - startTime));
  260. Graphics2D g = (Graphics2D) graphics;
  261.  
  262. if (!hide) {
  263. g.drawImage(img1, 1, 196, null);
  264. g.drawImage(img2, 499, 274, null);
  265. g.setFont(font1);
  266. g.setColor(color1);
  267. g.drawString(" " + hours + " hours " + minutes + " minutes " + seconds + " seconds", 98, 292);
  268. g.drawString(" " + itemCount , 133, 310);
  269. g.drawString(" " + toadsPH, 164, 327);
  270. g.drawString(" " + moneyMade, 407, 293);
  271. g.drawString(" " + moneyPH, 430, 313);
  272. g.drawString(" " + status, 362, 334);
  273. } else {
  274. g.drawImage(img3, 464, 316, null);
  275. }
  276.  
  277. }
  278.  
  279. public void AntiBan() throws InterruptedException {
  280. Entity toad = closestGroundItemForName(TOAD);
  281. switch (random(1, 1000)) {
  282.  
  283. case 23:
  284. status = "Anti-ban";
  285. client.moveCameraToEntity(toad);
  286. case 14:
  287. status = "Anti-ban";
  288. client.rotateCameraPitch(50);
  289. case 6:
  290. status = "Anti-ban";
  291. client.rotateCameraToAngle(350);
  292. case 3:
  293. status = "Anti-ban";
  294. openTab(Tab.SKILLS);
  295. case 56:
  296. status = "Anti-ban";
  297. openTab(Tab.ATTACK);
  298. case 106:
  299. status = "Anti-ban";
  300. openTab(Tab.QUEST);
  301. case 107:
  302. status = "Anti-ban";
  303. openTab(Tab.SETTINGS);
  304. case 108:
  305. status = "Anti-ban";
  306. openTab(Tab.SETTINGS);
  307. case 109:
  308. status = "Anti-ban";
  309. openTab(Tab.SETTINGS);
  310. case 530:
  311. status = "Anti-ban";
  312. client.rotateCameraPitch(50);
  313.  
  314. }
  315. random(100, 500);
  316. }
  317.  
  318. public boolean WalkAlongPath(int[][] path, boolean AscendThroughPath,
  319. int distanceFromEnd) {
  320. if (distanceToPoint(AscendThroughPath ? path[path.length - 1][0]
  321. : path[0][0], AscendThroughPath ? path[path.length - 1][1]
  322. : path[0][1]) <= distanceFromEnd)
  323. return true;
  324. else {
  325. WalkAlongPath(path, AscendThroughPath);
  326. return false;
  327. }
  328. }
  329.  
  330. public void WalkAlongPath(int[][] path, boolean AscendThroughPath) {
  331. int destination = 0;
  332. for (int i = 0; i < path.length; i++)
  333. if (distanceToPoint(path[i][0], path[i][1]) < distanceToPoint(
  334. path[destination][0], path[destination][1]))
  335. destination = i;
  336. if (client.getMyPlayer().isMoving()
  337. && distanceToPoint(path[destination][0], path[destination][1]) > (isRunning() ? 3
  338. : 2))
  339. return;
  340. if (AscendThroughPath && destination != path.length - 1
  341. || !AscendThroughPath && destination != 0)
  342. destination += (AscendThroughPath ? 1 : -1);
  343. try {
  344. walk(new Position(path[destination][0], path[destination][1], 0));
  345. Thread.sleep(700 + MethodProvider.random(600));
  346. } catch (InterruptedException e) {
  347. e.printStackTrace();
  348. }
  349. }
  350.  
  351. private int distanceToPoint(int pointX, int pointY) {
  352. return (int) Math.sqrt(Math
  353. .pow(client.getMyPlayer().getX() - pointX, 2)
  354. + Math.pow(client.getMyPlayer().getY() - pointY, 2));
  355. }
  356.  
  357. public void bankDeposit() throws InterruptedException {
  358. RS2Object booth = closestObjectForName(new String[] { "Bank booth" });
  359. if ((booth != null) && (booth.interact("Bank"))) {
  360. booth.interact("Bank");
  361. sleep(2500);
  362. }
  363. while (this.client.getMyPlayer().isMoving()) {
  364. sleep(1500);
  365. }
  366. if (this.client.getBank().isOpen()) {
  367. this.client.getBank().depositAll();
  368. sleep(1000);
  369. }
  370. if (this.client.getInventory().isEmpty()) {
  371. this.client.getBank().close();
  372. }
  373. }
  374.  
  375. @Override
  376. public void mouseClicked(MouseEvent e) {
  377. p = e.getPoint();
  378. if (close.contains(p) && !hide) {
  379. hide = true;
  380. } else if (open.contains(p) && hide) {
  381. hide = false;
  382. }
  383. }
  384.  
  385. }
Advertisement
Add Comment
Please, Sign In to add comment