Guest User

Untitled

a guest
Jun 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. package com.scripts; //You will ALWAYS need this
  2. import com.kbot2.scriptable.Script;
  3. import com.kbot2.scriptable.methods.wrappers.*;
  4. import com.kbot2.scriptable.methods.input.*;
  5. import com.kbot2.scriptable.methods.data.*;
  6. import com.kbot2.scriptable.methods.data.Camera.*;
  7. import com.kbot2.handlers.eventSystem.eventListeners.PaintListener;
  8.  
  9. import java.awt.*;
  10.  
  11. public class GoblinTrainer extends Script implements PaintListener {
  12.  
  13. public boolean active() { //if active() is true, then the script can run.
  14. return true;
  15. }
  16.  
  17. public String getName() {
  18. return "GoblinTrainer";
  19. }
  20.  
  21. public String getAuthor() {
  22. return "Wakka";
  23. }
  24.  
  25. public String getDescription() {
  26. return "Trains your beginner character so you don't have to!" +
  27. "Begin at Lumbridge, at the courtyard and it'll deathwalk.";
  28. }
  29. //misx
  30. int state = 1;
  31. int fight = 1;
  32. long startTime;
  33. //walk path
  34. public Tile[] toGoblins = new Tile [] { new Tile(3229, 3218), new Tile(3241, 3226), new Tile(3251, 3226) };
  35. public static final int[] doorClosed = new int[] { 1530 };
  36.  
  37. @Override
  38. public boolean onStart() {
  39. startTime = System.currentTimeMillis();
  40. return true;
  41. }
  42.  
  43.  
  44. public int loop() {
  45. if (getMyPlayer().isInCombat() || getMyPlayer().isMoving()) {
  46. return random(900, 1200);
  47. }
  48. switch (state) {
  49. case 1:
  50. //wieldItems();
  51. case 2:
  52. walkToGoblin();
  53. case 3:
  54. fightGoblin();
  55. }
  56. return random(500, 800);
  57. }
  58.  
  59. void walkToGoblin() {
  60. if (distanceTo(toGoblins[0]) <18) {
  61. walking.setRunning(true);
  62. walking.walkPath(walking.randomizePath(toGoblins, 2, 2));
  63. }
  64. }
  65.  
  66. public int fightGoblin() {
  67. if (!getMyPlayer().isInCombat()) {
  68. NPC goblin = getClosestFree(40, "Goblin");
  69. if (goblin == null) {
  70. return random(300, 600);
  71. }
  72. if (goblin != null && !goblin.isInCombat()) {
  73. goblin.doAction("Attack");
  74. sleep(200, 3000);
  75. }
  76. if(getMyPlayer().isInCombat()) {
  77. //antiBan();
  78. sleep(500, 1000);
  79. }
  80. sleep(1200, 1500);
  81. }
  82. return random(800, 1200);
  83. }
  84.  
  85. void onServerMessage(String s) {
  86. if (s.contains("I can't reach that!")) {
  87. Obj door = getClosestObject(15, 1530);
  88. camera.setCompass('n');
  89. if (door != null) {
  90. door.doActionAtDoor('n', "Open");
  91. }
  92. }
  93. }
  94.  
  95. public void onRepaint (Graphics g) {
  96. long runTime = System.currentTimeMillis() - startTime;
  97. int secs = ((int) ((runTime / 1000) % 60));
  98. int mins = ((int) (((runTime / 1000) / 60) % 60));
  99. int hours = ((int) ((((runTime / 1000) / 60) / 60) % 60));
  100. g.setColor(new Color(61, 61, 61, 200));
  101. g.setColor(Color.white);
  102. g.drawString("Run time: " + (hours < 10 ? "0" : "") + hours + ":"
  103. + (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "")
  104. + secs, 34, 61);
  105. }
  106.  
  107. public NPC getClosestFree(int range, String... names) {
  108. Tile myLoc = players.getMyPlayer().getLocation();
  109. double closestDist = 256;
  110. NPC[] allNPCs = npcs.getNPCs();
  111. NPC closestNPC = null;
  112. try {
  113. mainLoop:
  114. for (NPC tempNPC : allNPCs) {
  115. for (String s : names) {
  116. if (tempNPC.isInCombat())
  117. continue;
  118. int tempDist = tempNPC.getLocation().distanceTo(myLoc);
  119. if (tempNPC.getName().equalsIgnoreCase(s) && tempDist <= range && tempDist < closestDist) {
  120. closestNPC = tempNPC;
  121. closestDist = tempDist;
  122. continue mainLoop;
  123. }
  124. }
  125. }
  126. } catch (Exception betterSafeThanSorry) {
  127. return closestNPC;
  128. }
  129. return closestNPC;
  130. }
  131. }
Add Comment
Please, Sign In to add comment