Guest User

Untitled

a guest
Jul 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. /** TekksCrabs.java 1.9
  2. * Kills the eastern rock crabs.
  3. * Have fun and report bugs to me as this is my first script.
  4. */
  5.  
  6. import java.awt.*;
  7. import java.util.*;
  8. import com.speljohan.rsbot.script.*;
  9. import com.speljohan.rsbot.bot.*;
  10. import com.speljohan.rsbot.script.wrappers.*;
  11. import com.speljohan.rsbot.event.listeners.*;
  12. import com.speljohan.rsbot.script.ScriptManifest;
  13.  
  14. @ScriptManifest (authors = { "Tekk" },
  15. category = "Combat",
  16. name = "TekksCrabs",
  17. version = 1.9,
  18. description = "<i><b>TekksCrabs v1.9</b> By Tekk</i><br /><br /><b>Start at the eastern crabs. </b><br /><input type='radio' name='stat' value='att'> Attack<br /><input type='radio' name='stat' value='str'> Strength<br /><input type='radio' name='stat' value='def'> Defence<br /><input type='radio' name='stat' value='range'> Ranged<br /><br />Food ID: <input type='text' name='foodid' value=''><br /><br />HP To Eat At: <input type='text' name='eatat' value=''><br /><br />Arrow Pickup ID: <input type='text' name='pickupid' value=''><br /><br />Arrow Name: <input type='text' name='pickupname' value = ''><br /><i>Note: Capitalization counts in the 'Arrow Name' field. For example, 'bronze arrow' will not work but 'Bronze arrow' will.</i>")
  19.  
  20.  
  21. public class TekksCrabs extends Script implements PaintListener {
  22.  
  23. RSTile[] northToSouth = new RSTile[] { new RSTile(2707, 3717), new RSTile(2708, 3708),
  24. new RSTile(2706, 3697), new RSTile(2705, 3690), new RSTile(2706, 3685) };
  25.  
  26. RSTile[] southToNorth = reversePath(northToSouth);
  27.  
  28. private int expStart;
  29. private int hitpointsExpStart;
  30. private int statBeingTrained;
  31.  
  32. private int pickupID;
  33. private String pickupName;
  34.  
  35. private int eatAtHP = random(18,23);
  36. private int foodID;
  37. private boolean eating;
  38.  
  39. @SuppressWarnings("deprecation")
  40. public boolean onStart(Map<String, String> args) {
  41. Bot.getEventManager().addListener(PaintListener.class, this);
  42.  
  43. if(args.get("stat").equals("range")) {
  44. statBeingTrained = Constants.STAT_RANGE;
  45. }
  46. if(args.get("stat").equals("att")) {
  47. statBeingTrained = Constants.STAT_ATTACK;
  48. }
  49. if(args.get("stat").equals("str")) {
  50. statBeingTrained = Constants.STAT_STRENGTH;
  51. }
  52. if(args.get("stat").equals("def")) {
  53. statBeingTrained = Constants.STAT_DEFENSE;
  54. }
  55.  
  56. if(!args.get("foodid").equals("")) {
  57. eating = true;
  58. try {
  59. foodID = Integer.parseInt(args.get("foodid"));
  60. } catch (NumberFormatException e) {
  61. log("Enter food as an ID, not name!");
  62. stopAllScripts();
  63. }
  64. }
  65. if(!args.get("pickupid").equals("")) {
  66. try {
  67. pickupID = Integer.parseInt(args.get("pickupid"));
  68. } catch (NumberFormatException e) {
  69. log("Enter arrow pickup item as an ID, not name!");
  70. stopAllScripts();
  71. }
  72. }
  73.  
  74. if(!args.get("pickupname").equals("")) pickupName = args.get("pickupname");
  75.  
  76. if(!args.get("eatat").equals("")) {
  77. try {
  78. eatAtHP = Integer.parseInt(args.get("eatat"));
  79. } catch (NumberFormatException e) {
  80. log("You entered the Eat At HP wrong.");
  81. stopAllScripts();
  82. }
  83. }
  84. expStart = skills.getCurrentSkillExp(statBeingTrained);
  85. hitpointsExpStart = skills.getCurrentSkillExp(Constants.STAT_HITPOINTS);
  86. return true;
  87. }
  88.  
  89. public void onFinish(){
  90. Bot.getEventManager().removeListener(PaintListener.class, this);
  91. return;
  92. }
  93.  
  94. public int loop() {
  95. if(isFightingCrab()) {
  96. return random(500,700);
  97. }
  98. if(walkingToCrab()) {
  99. return random(500,700);
  100. }
  101. if(needToWalkSouth()) {
  102. walkSouth();
  103. return random(2000,4000);
  104. }
  105. if(needToWalkNorth()) {
  106. walkNorth();
  107. return random(2000,4000);
  108. }
  109. if(needToPickUpItems()) {
  110. pickUpItems();
  111. return random(500,700);
  112. }
  113. if(eating) {
  114. eatFood();
  115. }
  116. // we're not doing anything
  117. findAndAttackCrabs();
  118. return random(500,700);
  119.  
  120. }
  121.  
  122.  
  123. private boolean needToPickUpItems() {
  124. RSItemTile itemToPickUp = getGroundItemByID(3, pickupID);
  125. if(getMyPlayer().getLocation().getY() >= 3710) {
  126. if(itemToPickUp != null) {
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132.  
  133. private void pickUpItems() {
  134. RSItemTile itemToPickUp = getGroundItemByID(3, pickupID);
  135. atTile(itemToPickUp, pickupName);
  136. wait(random(500,700));
  137. if(inventoryContains(pickupID)) atInventoryItem(pickupID, "Wield");
  138. return;
  139. }
  140.  
  141. private void eatFood() {
  142. int currentHP = skills.getCurrentSkillLevel(STAT_HITPOINTS);
  143. if(currentHP <= eatAtHP) {
  144. if(inventoryContains(foodID)) {
  145. atInventoryItem(foodID, "Eat");
  146. wait(random(700,900));
  147. return;
  148. } else {
  149. log("No food and we are almost dead, stopping script.");
  150. walkSouth();
  151. stopAllScripts();
  152. }
  153. }
  154. return;
  155. }
  156.  
  157. private void walkNorth() {
  158. for(int i = 0; i<southToNorth.length; i++) {
  159. while(distanceTo(southToNorth[i]) > 5){
  160. walkTileMM(southToNorth[i]);
  161. moveMouseSlightly();
  162. wait(random(300,600));
  163. }
  164. }
  165. return;
  166. }
  167.  
  168. private boolean needToWalkNorth() {
  169. if(getMyPlayer().getLocation().getY() < 3710) {
  170. return true;
  171. }
  172. return false;
  173. }
  174.  
  175. private void walkSouth() {
  176. for(int i = 0; i<northToSouth.length; i++) {
  177. while(distanceTo(northToSouth[i]) > 5){
  178. walkTileMM(northToSouth[i]);
  179. moveMouseSlightly();
  180. wait(random(300,600));
  181. }
  182. }
  183. return;
  184. }
  185.  
  186. private boolean needToWalkSouth() {
  187. if(getNearestNPCByID(1266,1268) != null) {
  188. if(distanceTo(getNearestNPCByID(1266, 1268)) == 0 && !getMyPlayer().isInCombat()) {
  189. return true;
  190. }
  191. }
  192. return false;
  193. }
  194.  
  195. private void findAndAttackCrabs() {
  196. RSNPC newCrab = getNearestFreeNPCByID(1266, 1268);
  197. if(newCrab != null && newCrab.getLocation().getX() > 2691 && !getMyPlayer().isInCombat() && getMyPlayer().getAnimation() == -1) {
  198. RSTile crabLocation = newCrab.getLocation();
  199. if(getEnergy() > random(20,25) && isRunning() == false) {
  200. setRun(true);
  201. }
  202. walkTileMM(crabLocation);
  203. moveMouseSlightly();
  204. }
  205. return;
  206.  
  207. }
  208.  
  209. private boolean walkingToCrab() {
  210. if(getMyPlayer().isMoving()) {
  211. return true;
  212. }
  213. return false;
  214. }
  215.  
  216. private boolean isFightingCrab() {
  217. if(getMyPlayer().isInCombat()) {
  218. return true;
  219. }
  220. return false;
  221. }
  222.  
  223. @Override
  224. public void onRepaint(Graphics render) {
  225. if(isLoggedIn()) {
  226. render.setColor(Color.gray);
  227. render.fill3DRect(12, 250, 175, 75, true);
  228. render.setColor(Color.white);
  229. render.drawString("TekksCrabs v1.9", 17, 265);
  230. render.drawString("XP gained: " + (skills.getCurrentSkillExp(statBeingTrained) - expStart), 17, 280);
  231. render.drawString("XP to level " + (skills.getCurrentSkillLevel(statBeingTrained) + 1) + " : " + skills.getXPToNextLevel(statBeingTrained), 17, 295);
  232. render.drawString("Hitpoints XP gained: " + (skills.getCurrentSkillExp(STAT_HITPOINTS) - hitpointsExpStart), 17, 310);
  233. }
  234. }
  235.  
  236. }
Add Comment
Please, Sign In to add comment