Guest User

Untitled

a guest
Oct 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. import java.awt.Graphics;
  2.  
  3. import org.rsbot.event.events.ServerMessageEvent;
  4. import org.rsbot.event.listeners.PaintListener;
  5. import org.rsbot.event.listeners.ServerMessageListener;
  6. import org.rsbot.script.Script;
  7. import org.rsbot.script.ScriptManifest;
  8. import org.rsbot.script.methods.Players;
  9. import org.rsbot.script.methods.Skills;
  10. import org.rsbot.script.util.Filter;
  11. import org.rsbot.script.wrappers.RSObject;
  12. import org.rsbot.script.wrappers.RSObject.Type;
  13. import org.rsbot.script.wrappers.RSPlayer;
  14. import org.rsbot.script.wrappers.RSTile;
  15.  
  16. @ScriptManifest(authors = { "Speed" }, name = "SpeedIvy", version = 1.01, keywords = { "Woodcutting", "Ivy" }, description = "Cuts ivy in any location.")
  17. public class SpeedIvy extends Script implements PaintListener, ServerMessageListener {
  18.  
  19. private RSTile currentIvy;
  20. private int ivyChopped;
  21. private char direction = 'f';
  22. private long startTime, minutes, hours, seconds, runTime;
  23. private int startXP;
  24. private static final int[] NESTS = { 5070, 5071, 5072, 5073, 5074, 5075, 5076, 7413, 11966 };
  25. private static final int[] IVY_ID = { 46318, 46320, 46322, 46324 };
  26.  
  27. public boolean onStart() {
  28. mouse.setSpeed(random(3, 6));
  29. return true;
  30. }
  31.  
  32. private boolean isBusy() {
  33. int timesBusy = 0;
  34. int timesNotBusy = 0;
  35. for (int i = 0; i < 10; i++) {
  36. if (players.getMyPlayer().getAnimation() != -1 || getMyPlayer().isInCombat() || getMyPlayer().isMoving()
  37. || !getMyPlayer().isIdle())
  38. timesBusy++;
  39. else
  40. timesNotBusy++;
  41. sleep(random(150, 200));
  42. }
  43. return timesBusy >= timesNotBusy;
  44. }
  45.  
  46. private int canChop() {
  47. while (getMyPlayer().isMoving())
  48. sleep(random(300, 500));
  49. return random(300, 500);
  50. }
  51.  
  52. public int loop() {
  53. if (startTime == 0 && skills.getRealLevel(Skills.CONSTITUTION) > 1) {
  54. startTime = System.currentTimeMillis();
  55. startXP = skills.getCurrentExp(Skills.WOODCUTTING);
  56. }
  57. if (groundItems.getNearest(NESTS) != null) {
  58. groundItems.getNearest(NESTS).doAction("Take");
  59. return canChop();
  60. }
  61.  
  62. if (isBusy()) {
  63. if (random(0, 5) > 3) {
  64. switch (random(1, 9)) {
  65. case 1:
  66. camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
  67. break;
  68. case 2:
  69. mouse.move((int) ((mouse.getLocation().x * 3.5) / 2.5) + random(10, 30),
  70. ((int) ((mouse.getLocation().y * 3.5) / 2.5) + random(10, 30)));
  71. break;
  72. case 3:
  73. mouse.move((int) ((mouse.getLocation().x * 3.5) / 2.5) + random(10, 30),
  74. ((int) ((mouse.getLocation().y * 3.5) / 2.5) + random(10, 30)));
  75. camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
  76. break;
  77.  
  78. case 5:
  79. camera.setAngle((int) (((camera.getAngle() + random(0, 180)) * 3) / 2));
  80. break;
  81. case 6:
  82. final RSObject[] obj = objects.getAll(new Filter<RSObject>() {
  83. public boolean accept(RSObject t) {
  84. return t.isOnScreen();
  85. }
  86. });
  87. if (obj.length == 0) {
  88. break;
  89. }
  90. final RSObject ran = obj[random(0, obj.length - 1)];
  91. if (ran.getType().equals(RSObject.Type.INTERACTABLE)) {
  92. ran.doAction("Examine");
  93. }
  94. break;
  95. case 7:
  96. RSPlayer play = players.getNearest(Players.ALL_FILTER);
  97.  
  98. if (play.isOnScreen()) {
  99. mouse.move(play.getScreenLocation());
  100. sleep(random(300, 800));
  101.  
  102. }
  103. break;
  104. case 8:
  105. final RSObject ivy = objects.getNearest(new Filter<RSObject>() {
  106. public boolean accept(final RSObject t) {
  107. for (final int i : IVY_ID) {
  108. if (t.getType().equals(Type.WALL_DECORATION) && !t.getLocation().equals(currentIvy)
  109. && t.getID() == i) {
  110. return true;
  111. }
  112. }
  113. return false;
  114. }
  115. });
  116. ivy.doHover();
  117. sleep(random(900, 1800));
  118. break;
  119. default:
  120. break;
  121. }
  122. }
  123.  
  124. } else {
  125. final RSObject ivy = objects.getNearest(new Filter<RSObject>() {
  126. public boolean accept(final RSObject t) {
  127. for (final int i : IVY_ID) {
  128. if (t.getType().equals(Type.WALL_DECORATION) && t.getID() == i) {
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. });
  135. if (ivy != null) {
  136. final RSTile ivyTile = ivy.getLocation();
  137. currentIvy = ivyTile;
  138. if (direction == 'f') {
  139. ivyFail(ivy, 0);
  140. } else {
  141. camera.setCompass(direction);
  142. if (!ivy.doAction("Chop"))
  143. ivyFail(ivy, 0);
  144. }
  145. return canChop();
  146. }
  147. }
  148. return random(500, 700);
  149. }
  150.  
  151. private boolean ivyFail(final RSObject ivy, int i) {
  152. if (i > 3) {
  153. return ivy.doAction("Chop");
  154. }
  155. switch (i) {
  156. case 0:
  157. direction = 'n';
  158. camera.setCompass('n');
  159. break;
  160. case 1:
  161. direction = 'e';
  162. camera.setCompass('e');
  163. break;
  164. case 2:
  165. direction = 's';
  166. camera.setCompass('s');
  167. break;
  168. case 3:
  169. direction = 'w';
  170. camera.setCompass('w');
  171. break;
  172. }
  173. ivy.doAction("Chop");
  174. canChop();
  175. return isBusy() ? true : ivyFail(ivy, ++i);
  176.  
  177. }
  178.  
  179. public void serverMessageRecieved(final ServerMessageEvent e) {
  180. if (e.getMessage().contains("some")) {
  181. ivyChopped++;
  182. }
  183.  
  184. }
  185.  
  186. public void onRepaint(final Graphics g) {
  187. runTime = System.currentTimeMillis() - startTime;
  188. seconds = runTime / 1000;
  189. if (seconds >= 60) {
  190. minutes = seconds / 60;
  191. seconds -= (minutes * 60);
  192. }
  193. if (minutes >= 60) {
  194. hours = minutes / 60;
  195. minutes -= (hours * 60);
  196. }
  197. final int xpGained = skills.getCurrentExp(Skills.WOODCUTTING) - startXP;
  198. g.drawString("SpeedIvy by Speed.", 15, 30);
  199. g.drawString("Run time: " + hours + ":" + minutes + ":" + seconds + ".", 15, 45);
  200. g.drawString("Ivy Chopped: " + ivyChopped + ".", 15, 60);
  201. g.drawString("XP Gained: " + xpGained + ".", 15, 75);
  202. }
  203. }
Add Comment
Please, Sign In to add comment