Guest User

Untitled

a guest
Jul 19th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.89 KB | None | 0 0
  1. // Save files as CodeSpaceLawCrafter.java
  2.  
  3. import java.awt.*;
  4. import java.util.Map;
  5.  
  6. import org.rsbot.bot.Bot;
  7. import org.rsbot.event.listeners.PaintListener;
  8. import org.rsbot.script.Script;
  9. import org.rsbot.script.ScriptManifest;
  10. import org.rsbot.script.Skills;
  11. import org.rsbot.script.wrappers.RSInterface;
  12. import org.rsbot.script.wrappers.RSNPC;
  13. import org.rsbot.script.wrappers.RSTile;
  14.  
  15.  
  16. @ScriptManifest(authors = { "CodeSpace" }, category = "Runecraft", name = "CodeSpaces's FREE Law Crafter", version = 1.0,
  17. description = "<html><body style='font-family: Arial; padding: 0px; background-color: #FFFFFF;'>"
  18. + "<div style=\"background-color: #99CCFF; width: 100%; height: 34px; border: 3px coral solid;\">"
  19. + "<h1 style=\"font-size: 13px; color: #FFFFFF;\"><center>CodeSpaces's FREE Law Crafter"
  20. + "<br /><small>Version 1.0</small></center></h1></div>"
  21. + "<br /><center>Start at Draynor Bank.</center>"
  22. + "<br />&nbsp;&nbsp;&nbsp;&nbsp;<b>Requirements:</b> <ul><li>Ability to travel to Entrana.</li><li>54 Runecrafting</li></ul> "
  23. + "<br /><small><center>Note: You must be wearing a Law tiara before you start the script. Its important that pure essence is viewable when the bank opens.</center>")
  24.  
  25. public class CodeSpaceLawCrafter extends Script implements PaintListener {
  26.  
  27. private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
  28.  
  29. // VARIABLES
  30. private int startLvl;
  31. private int startXP;
  32. private int failCount = 0;
  33. private int bankBooth = 2213;
  34. private int runEnergy = random(50, 80);
  35. private boolean gotSkillLvl = false;
  36. private boolean tiaraCheck = false;
  37.  
  38. private final long startTime = System.currentTimeMillis();
  39.  
  40. // ITEM ID'S
  41. private int pureEssence = 7936;
  42. private int lawRune = 563;
  43. private int lawTiara = 5545;
  44.  
  45. // NPC'S
  46. private int monksID[] = {657, 2728, 2729, 658, 2730, 2731};
  47.  
  48. // OBJECT ID'S
  49. private int gangPlank[] = {2415, 2413};
  50. private int lawRuins = 2459;
  51. private int lawPortal = 2472;
  52. private int lawAltar = 2485;
  53.  
  54. // PATHS
  55. private RSTile bankToBoatPath[] = {new RSTile(3093, 3243), new RSTile(3085, 3248),
  56. new RSTile(3081, 3254), new RSTile(3079, 3265),
  57. new RSTile(3073, 3273), new RSTile(3066, 3275),
  58. new RSTile(3060, 3267), new RSTile(3057, 3260),
  59. new RSTile(3054, 3251), new RSTile(3043, 3245),
  60. new RSTile(3042, 3237), new RSTile(3048, 3235)};
  61.  
  62. private RSTile boatToRuinsPath[] = {new RSTile(2834, 3335), new RSTile(2842, 3335),
  63. new RSTile(2852, 3337), new RSTile(2859, 3342),
  64. new RSTile(2859, 3350), new RSTile(2858, 3357),
  65. new RSTile(2857, 3366), new RSTile(2858, 3378)};
  66.  
  67. private RSTile portalToAltarPath[] = {new RSTile(2464, 4818), new RSTile(2464, 4829)};
  68.  
  69. // GAME STATES
  70. private final int WALKTOBOAT = 1;
  71. private final int RIDEBOAT = 2;
  72. private final int WALKTORUINS = 3;
  73. private final int ENTERRUINS = 4;
  74. private final int WALKTOALTAR = 5;
  75. private final int CRAFTRUNES = 6;
  76. private final int LEAVEALTAR = 7;
  77. private final int WALKFROMRUINS = 8;
  78. private final int WALKTOBANK = 9;
  79. private final int BANK = 10;
  80. private int ACTION = WALKTOBANK;
  81.  
  82. public void onRepaint(Graphics g) {
  83. if(getCurrentTab() != TAB_INVENTORY) {
  84. return;
  85. }
  86. final int percentTilNext = skills.getPercentToNextLevel(Skills.getStatIndex("runecrafting"));
  87. final int fillBar = (int) (1.65 * (double) percentTilNext);
  88. final int gainedXP = (int) (skills.getCurrentSkillExp(Skills.getStatIndex("runecrafting")) - startXP);
  89. final int perHourXP = (int) ((gainedXP) * 3600000D / (System.currentTimeMillis() - startTime));
  90. final int lawsCrafted = (int) (gainedXP / 9.5);
  91. final int lawsPerHour = (int) ((lawsCrafted) * 3600000D / (System.currentTimeMillis() - startTime));
  92.  
  93. final long runTime = System.currentTimeMillis() - startTime;
  94. final int seconds = (int) ((runTime / 1000) % 60);
  95. final int minutes = (int) ((runTime / 1000) / 60) % 60;
  96. final int hours = (int) (((runTime / 1000) / 60) / 60) % 60;
  97.  
  98. final StringBuilder botTime = new StringBuilder();
  99. if (hours < 10) { botTime.append('0'); }
  100. botTime.append(hours);
  101. botTime.append(':');
  102. if (minutes < 10) { botTime.append('0'); }
  103. botTime.append(minutes);
  104. botTime.append(':');
  105. if (seconds < 10) { botTime.append('0'); }
  106. botTime.append(seconds);
  107.  
  108. try {
  109. g.setColor(new Color(70, 130, 180, 200));
  110. g.fillRoundRect(555, 210, 175, 250, 10, 10);
  111. g.setColor(Color.white);
  112. int[] coords = new int[] {225, 235, 255, 270, 285, 300, 315, 330, 345, 360, 375, 390, 405, 420, 440};
  113. g.setFont(new Font("Calibri", Font.PLAIN, 12));
  114. g.drawString("CodeSpace's", 570, coords[1]);
  115. g.setFont(new Font("Calibri", Font.BOLD, 18));
  116. g.drawString("FREE", 640, coords[1]);
  117. g.setFont(new Font("Calibri", Font.BOLD, 23));
  118. g.drawString("Law Crafter", 590, coords[2]);
  119. g.setFont(new Font("Calibri", Font.PLAIN, 10));
  120. g.drawString("Version: " + properties.version(), 618, coords[3]);
  121. g.setFont(new Font("Calibri", Font.PLAIN, 12));
  122. g.drawString("___________________________", 561, 280);
  123. g.drawString("Time running: " + botTime, 580 ,coords[5]);
  124.  
  125. g.drawString("Current Lvl: " + skills.getCurrentSkillLevel(Skills.getStatIndex("runecrafting")), 570, coords[7]);
  126. g.drawString("Lvls Gained: " + (skills.getCurrentSkillLevel(Skills.getStatIndex("runecrafting")) - startLvl), 570, coords[8]);
  127. g.drawString("Laws Crafted: " + Integer.toString(lawsCrafted) + "", 570, coords[9]);
  128. g.drawString("Laws/Hour: " + Integer.toString(lawsPerHour) + "", 570, coords[10]);
  129. g.drawString("XP Gained: " + Integer.toString(gainedXP) + "", 570, coords[12]);
  130. g.drawString("XP/Hour: " + Integer.toString(perHourXP) + "", 570, coords[13]);
  131.  
  132. g.setColor(new Color(255, 255, 255, 255));
  133. g.fillRect(559, 441 - 13, 167, 15);
  134. g.setColor(new Color(0, 0, 0, 175));
  135. g.fillRect(560, coords[14] - 11, 165, 13);
  136. g.setColor(new Color(70, 130, 180, 200));
  137. g.fillRect(560, coords[14] - 11, fillBar, 13);
  138. g.setColor(Color.WHITE);
  139. g.drawString(percentTilNext + "%", 565, coords[14]);
  140. } catch (NullPointerException e) {
  141. e.printStackTrace();
  142. }
  143. }
  144.  
  145. public boolean onStart( Map<String,String> args ) {
  146. return true;
  147. }
  148.  
  149. public int loop() {
  150. try {
  151. if(isLoggedIn() && !gotSkillLvl) {
  152. startLvl = skills.getCurrentSkillLevel(Skills.getStatIndex("runecrafting"));
  153. startXP = skills.getCurrentSkillExp(Skills.getStatIndex("runecrafting"));
  154. gotSkillLvl = true;
  155. return random(50,150);
  156. }
  157. } catch (Exception e) { }
  158.  
  159. try {
  160. if(isLoggedIn() && !tiaraCheck) {
  161. if (equipmentContainsOneOf(lawTiara)) {
  162. tiaraCheck = true;
  163. return random(50,150);
  164. } else {
  165. log("You need to have a law tiara equipped!");
  166. wait(10000);
  167. return random(50,150);
  168. }
  169. }
  170. } catch (Exception e) { }
  171.  
  172. try {
  173. if (energyCheck()) {
  174. setRun(true);
  175. wait(random(750,1000));
  176. return random(50, 150);
  177. }
  178. } catch (Exception e) { }
  179.  
  180. try {
  181. runScript();
  182. antiBan();
  183. } catch (Exception e) { }
  184.  
  185. return random(50,150);
  186. }
  187.  
  188. private void runScript() {
  189. if (ACTION == WALKTOBOAT) {
  190. if (distanceTo(getDestination()) < random(5, 7)) {
  191. if (walkMeTo((bankToBoatPath),false)) {
  192. ACTION = RIDEBOAT;
  193. }
  194. }
  195. return;
  196. }
  197. if (ACTION == RIDEBOAT) {
  198. if (getInterface(210).getChild(1).getText().contains("The ship arrives") && getInterface(210).getChild(2).getText().contains("to continue")) {
  199. while (getNearestObjectByID(gangPlank) != null) {
  200. atObject(getNearestObjectByID(gangPlank), "Gangplank");
  201. wait(random(1500,2000));
  202. }
  203. if (!needsBank()) {
  204. ACTION = WALKTORUINS;
  205. return;
  206. }
  207. if (needsBank()) {
  208. ACTION = WALKTOBANK;
  209. return;
  210. }
  211. return;
  212. }
  213.  
  214. final RSNPC monk = getNearestFreeNPCByID(monksID);
  215. atNPC(monk, "Take-boat");
  216. wait(random(1500,1700));
  217.  
  218. while (getInterface(64).getChild(4).getText().contains("Yes, ok") && getInterface(64).getChild(5).getText().contains("to continue")) {
  219. atInterface(64, 5);
  220. wait(random(750,1000));
  221. }
  222. while (getInterface(241).getChild(4).getText().contains("Very well.") && getInterface(241).getChild(5).getText().contains("to continue")) {
  223. atInterface(241, 5);
  224. wait(random(750,1000));
  225. }
  226. while (getInterface(210).getChild(1).getText().contains("The monk") && getInterface(210).getChild(2).getText().contains("to continue")) {
  227. atInterface(210, 2);
  228. wait(random(750,1000));
  229. }
  230. while (getInterface(241).getChild(4).getText().contains("All is satisfactory.") && getInterface(241).getChild(5).getText().contains("to continue")) {
  231. atInterface(241, 5);
  232. wait(random(750,1000));
  233. }
  234. while (getInterface(299).getChild(25).getText().contains("You sail to")) {
  235. wait(random(1000,1500));
  236. }
  237. while (getInterface(243).getChild(4).getText().contains("I see you are")) {
  238. log("ATTENTION: Script terminating due to users incoherence.");
  239. wait(random(750,1000));
  240. stopScript();
  241. }
  242. return;
  243. }
  244. if (ACTION == WALKTORUINS) {
  245. if (distanceTo(getDestination()) < random(5, 7)) {
  246. if (walkMeTo((boatToRuinsPath),false)) {
  247. ACTION = ENTERRUINS;
  248. }
  249. }
  250. return;
  251. }
  252. if (ACTION == ENTERRUINS) {
  253. if (getMyPlayer().getLocation().getY() >= 4812) {
  254. ACTION = WALKTOALTAR;
  255. return;
  256. }
  257. atObject(getNearestObjectByID(lawRuins), "Mysterious ruins");
  258. wait(random(1000,1500));
  259. return;
  260. }
  261. if (ACTION == WALKTOALTAR) {
  262. if (distanceTo(getDestination()) < random(5, 7)) {
  263. if (walkMeTo((portalToAltarPath),false)) {
  264. ACTION = CRAFTRUNES;
  265. }
  266. }
  267. return;
  268. }
  269. if (ACTION == CRAFTRUNES) {
  270. if (getInventoryCount(pureEssence) == 0) {
  271. ACTION = LEAVEALTAR;
  272. return;
  273. }
  274. atObject(getNearestObjectByID(lawAltar), "Altar");
  275. wait(random(1500,2000));
  276. return;
  277. }
  278. if (ACTION == LEAVEALTAR) {
  279. if (getMyPlayer().getLocation().getY() <= 3390) {
  280. ACTION = WALKFROMRUINS;
  281. return;
  282. }
  283. if (distanceTo(getDestination()) < random(5, 7)) {
  284. if (walkMeTo((portalToAltarPath),true)) {
  285. atObject(getNearestObjectByID(lawPortal), "Portal");
  286. wait(random(1000,1500));
  287. }
  288. }
  289. return;
  290. }
  291. if (ACTION == WALKFROMRUINS) {
  292. if (distanceTo(getDestination()) < random(5, 7)) {
  293. if (walkMeTo((boatToRuinsPath),true)) {
  294. ACTION = RIDEBOAT;
  295. }
  296. }
  297. return;
  298. }
  299. if (ACTION == WALKTOBANK) {
  300. if (distanceTo(getDestination()) < random(5, 7)) {
  301. if (walkMeTo((bankToBoatPath),true)) {
  302. ACTION = BANK;
  303. }
  304. }
  305. return;
  306. }
  307. if (ACTION == BANK) {
  308. if(getInventoryCount(pureEssence) > 0 && getInventoryCount(lawRune) <= 0)
  309. {
  310. bank.close();
  311. wait(random(150,300));
  312. ACTION = WALKTOBOAT;
  313. failCount = 0;
  314. return;
  315. }
  316. if (bank.getInterface().isValid()) {
  317. if (getInventoryCount() != 0)
  318. bank.depositAll();
  319. wait(random(750,1000));
  320. if (bank.atItem(pureEssence, "Withdraw-All")) {
  321. wait(random(750,1000));
  322. failCount = 0;
  323. return;
  324. } else {
  325. failCount++;
  326. if (failCount >= 5)
  327. stopScript();
  328. else
  329. return;
  330. }
  331. return;
  332. } else {
  333. wait(random(1000, 2000));
  334. if (!bank.isOpen()) {
  335. if (getNearestObjectByID(bankBooth) != null) {
  336. atObject(getNearestObjectByID(bankBooth), "uickly");
  337. wait(random(500, 1000));
  338. return;
  339. }
  340. }
  341. }
  342.  
  343. }
  344. }
  345.  
  346. private int onEnergyCheck() {
  347. return Integer.parseInt(RSInterface.getChildInterface(750, 5).getText());
  348. }
  349.  
  350. private boolean energyCheck() {
  351. try {
  352. if (onEnergyCheck() >= runEnergy && !isRunning()) {
  353. runEnergy = random(35, 65);
  354. return true;
  355. } else {
  356. return false;
  357. }
  358. } catch (Exception e) {
  359. return false;
  360. }
  361. }
  362.  
  363. private boolean walkMeTo(RSTile[] tilearr, boolean backwards){
  364. int i;
  365. int arrl = tilearr.length - 1;
  366. if(!backwards){
  367. for(i=0;i <= arrl;){
  368. if(distanceTo(tilearr[i]) <= 4){
  369. i++;
  370. if(i > arrl){
  371. return true;
  372. }
  373. }
  374. if(distanceTo(getDestination()) <= 4 || !getMyPlayer().isMoving()){
  375. walkTileMM(tilearr[i]);
  376. }
  377. }
  378. if(distanceTo(tilearr[arrl]) <= 4){
  379. return true;
  380. }
  381. }else{
  382. for(i= arrl;i >= 0;){
  383. if(distanceTo(tilearr[0]) <= 4){
  384. return true;
  385. }
  386. if(distanceTo(tilearr[i]) <= 4){
  387. i--;
  388. if(i < 0){
  389. return true;
  390. }
  391. }
  392. if(distanceTo(getDestination()) <= 4 || !getMyPlayer().isMoving()){
  393. walkTileMM(tilearr[i]);
  394. }
  395. }
  396. }
  397. return false;
  398. }
  399.  
  400. public boolean needsBank() {
  401. if (getInventoryCount(pureEssence) == 0) {
  402. return true;
  403. }
  404. else {
  405. return false;
  406. }
  407. }
  408.  
  409. private int antiBan() {
  410. int random = random(1, 24);
  411.  
  412. switch (random) {
  413. case 1:
  414. if (random(1, 4) == 2)
  415. {
  416. moveMouseRandomly(300);
  417. }
  418. return random(100, 500);
  419.  
  420. case 2:
  421. if (getCurrentTab() != TAB_INVENTORY) {
  422. openTab(TAB_INVENTORY);
  423. }
  424. return random(100, 500);
  425.  
  426. case 3:
  427. if (random(1, 40) == 30)
  428. {
  429. if (getMyPlayer().isMoving()) {
  430. return random(750, 1000);
  431. }
  432. if (getCurrentTab() != TAB_STATS) {
  433. openTab(TAB_STATS);
  434. }
  435. moveMouse(560, 420, 40, 20);
  436. wait(random(3000, 6000));
  437. return random(100, 200);
  438. }
  439.  
  440. case 4:
  441. if (random(1, 30) == 5) {
  442. int angle = getCameraAngle() + random(-90, 90);
  443. if (angle < 0) {
  444. angle = 0;
  445. }
  446. if (angle > 359) {
  447. angle = 0;
  448. }
  449. setCameraRotation(angle);
  450.  
  451. return random(500, 750);
  452. }
  453. }
  454. return 500;
  455. }
  456.  
  457. public void onFinish() {
  458. Bot.getEventManager().removeListener( PaintListener.class, this );
  459. }
  460. }
Add Comment
Please, Sign In to add comment