Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.61 KB | None | 0 0
  1. //
  2. // Created by [ ampzZ_ ] on 6/15/09
  3. //
  4.  
  5. package com.scripts;
  6.  
  7. import com.kbot2.handlers.eventSystem.eventListeners.PaintListener;
  8. import com.kbot2.handlers.eventSystem.eventListeners.ServerMessageListener;
  9. import com.kbot2.scriptable.Script;
  10. import com.kbot2.scriptable.methods.wrappers.*;
  11. import com.kbot2.scriptable.methods.data.Skills;
  12. import com.kbot2.scriptable.methods.data.GameScreen;
  13.  
  14. import java.awt.*;
  15. import java.text.DecimalFormat;
  16. import java.util.logging.Logger;
  17. import java.awt.event.KeyEvent;
  18.  
  19. public class ZanarisRingAlcher extends Script implements PaintListener, ServerMessageListener {
  20.  
  21. //-------------------
  22. // Variables
  23. //-----------------------------
  24. int fails = 0;
  25. boolean runnable = true;
  26. String statusMsg = "";
  27. int ringsAlched = 0;
  28. int origExp = 0;
  29. int origLvl = 0;
  30. long startTime = 0;
  31. long lastAlch = 0;
  32. long antibanTimer = System.currentTimeMillis() + random(15000, 40000);
  33.  
  34. //-------------------
  35. // Starting methods
  36. //------------------------------
  37. public boolean active() { return runnable; }
  38.  
  39. public String getName() { return "Zanaris Ring Alcher"; }
  40.  
  41. public String getAuthor() { return "ampzZ_"; }
  42.  
  43. public double getVersion() { return 1.0; }
  44.  
  45. public String getDescription() { return "Please refer to\nforum post."; }
  46.  
  47. public String[] getTags() { return new String[]{"ampzz", "Magic", "Zanaris", "Alcher"}; }
  48.  
  49. public boolean onStart() {
  50. camera.setAltitude(true);
  51. setMouseSpeed(1.5);
  52. origExp = skills.getExperience(Skills.SKILL_MAGIC);
  53. origLvl = skills.getLevel(Skills.SKILL_MAGIC);
  54. startTime = System.currentTimeMillis();
  55. return true;
  56. }
  57.  
  58. //-------------------
  59. // Loop
  60. //------------------------------
  61. public int loop() {
  62. try {
  63. if(!(inventory.contains(561))) {
  64. log("No more nature runes - Stopping;");
  65. runnable = false;
  66. return 1;
  67. }
  68.  
  69. if(fails > 15) {
  70. runnable = false;
  71. return 1;
  72. }
  73.  
  74. if(getMyPlayer().getAnimation() != -1 || getMyPlayer().isMoving()) // 9633 = alch anim
  75. return 100;
  76.  
  77. if(antibanTimer < System.currentTimeMillis())
  78. antiban();
  79.  
  80. if(inventory.contains(1641) && !interfaces.interfaceGroupExists(620)) {
  81. if(gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC)
  82. gameScreen.openTab(GameScreen.TAB_MAGIC);
  83. statusMsg = "Casting alch...";
  84. if(interfaces.getInterface(192, 34).isValid() && interfaces.getInterface(192, 34) != null) {
  85. interfaces.getInterface(192, 34).doClick();
  86. sleep(300, 500);
  87. if(inventory.atItem("Cast", 1641)) {
  88. statusMsg = "Alching...";
  89. ringsAlched++;
  90. lastAlch = System.currentTimeMillis()+5000;
  91. }
  92. return random(800, 1100);
  93. } else {
  94. if(gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC) {
  95. log("Hmm... couldnt open magic tab?");
  96. gameScreen.openTab(GameScreen.TAB_MAGIC);
  97. fails++;
  98. }
  99. }
  100. } else {
  101. if(interfaces.interfaceGroupExists(620) && inventory.contains(1641)) {
  102. statusMsg = "Closing trade";
  103. if(interfaces.getInterface(620, 7) != null) {
  104. interfaces.getInterface(620, 7).doClick();
  105. return random(500, 800);
  106. }
  107. }
  108. if(interfaces.getInterface(620, 21) != null && interfaces.getInterface(620, 21).getTextColor() != 16750623) {
  109. interfaces.getInterface(620, 21).doClick();
  110. return 1;
  111. }
  112. if(interfaces.interfaceGroupExists(620) && !inventory.contains(1641)) {
  113. if(interfaces.getInterface(620, 23) != null) {
  114. statusMsg = "Buying rings";
  115. Interface tehInterface= interfaces.getInterface(620, 23);
  116. Point randomPoint = tehInterface.getChild(0).getRandomPointInside();
  117. clickMouse(randomPoint, false);
  118. sleep(100);
  119. /*atMenu("Buy 10");
  120. sleep(100);
  121. clickMouse(randomPoint, false);
  122. sleep(100);
  123. atMenu("Buy 10");
  124. sleep(100);
  125. clickMouse(randomPoint, false);
  126. sleep(100);
  127. atMenu("Buy 10");*/
  128. atMenu("X");
  129. sleep(1000, 1500);
  130. sendText("" + random(26, 99), true);
  131. sleep(500, 800);
  132. }
  133. if(interfaces.getInterface(620, 7) != null) {
  134. statusMsg = "Closing trade";
  135. interfaces.getInterface(620, 7).doClick();
  136. return random(500, 800);
  137. }
  138. } else {
  139. statusMsg = "Finding Irksol";
  140. NPC irksol = npcs.getClosest(10, 566);
  141. if(irksol == null) {
  142. irksol = npcs.getClosest(10, "Irksol");
  143. if(irksol == null) {
  144. log("Cant find Irksol.");
  145. stopAllScripts();
  146. } else {
  147. statusMsg = "Trading Irksol";
  148. irksol.doAction("Trade Irksol");
  149. sleep(500, 800);
  150. }
  151. } else {
  152. statusMsg = "Trading Irksol";
  153. irksol.doAction("Trade Irksol");
  154. sleep(500, 800);
  155. }
  156. }
  157. }
  158.  
  159. return random(350, 500);
  160. } catch (Exception e) {
  161. return 100;
  162. }
  163.  
  164. }
  165.  
  166. //-------------------
  167. // Server messages
  168. //------------------------------
  169. public void onServerMessage(String m) {
  170. if(m.contains("have enough coins")) {
  171. log("Ran out of money somehow?");
  172. runnable = false;
  173. }
  174. }
  175.  
  176. //-------------------
  177. // Paint
  178. //------------------------------
  179. public void onRepaint(Graphics g) {
  180. long runTime = System.currentTimeMillis() - startTime;
  181. int secs = ((int) ((runTime / 1000) % 60));
  182. int mins = ((int) (((runTime / 1000) / 60) % 60));
  183. int hours = ((int) ((((runTime / 1000) / 60) / 60) % 60));
  184.  
  185. /* This is from z.Darkness as Im too lazy to do the logic */
  186. float xpsec = 0;
  187. if ((mins > 0 || hours > 0 || secs > 0) && (skills.getExperience(Skills.SKILL_MAGIC) - origExp) > 0) {
  188. xpsec = ((float) (skills.getExperience(Skills.SKILL_MAGIC) - origExp)) / (float) (secs + (mins * 60) + (hours * 60 * 60));
  189. }
  190. float xpmin = xpsec * 60;
  191. float xphours = xpmin * 60;
  192.  
  193. int x = 43;
  194. int y = 43;
  195.  
  196. DecimalFormat d = new DecimalFormat("#,#00");
  197. d.setMaximumFractionDigits(0);
  198.  
  199. g.setFont(new Font("Lucida", Font.BOLD, 12));
  200. g.setColor(Color.WHITE);
  201. g.drawString(getName() + " " + getVersion() + " | Created By: " + getAuthor(), x-18, y);
  202.  
  203. g.setFont(new Font("Lucida", Font.PLAIN, 12));
  204. y += 20;
  205. g.drawString("Status: " + statusMsg, x, y);
  206. y += 13;
  207. g.drawString("Run time: " + d.format(hours) + ":" + d.format(mins) + ":" + d.format(secs), x, y); // Yes alo, I took this from you :)
  208. y += 13;
  209. g.drawString("Rings Alched: " + ringsAlched, x, y);
  210. y += 13;
  211. g.drawString("Current level: " + skills.getLevel(Skills.SKILL_MAGIC), x, y);
  212. y += 13;
  213. g.drawString("Next level: " + (skills.getExperienceToNextLevel(Skills.SKILL_MAGIC)) + " experience", x, y);
  214. y += 13;
  215. g.drawString("Next level: " + ((ringsAlched == 0 || skills.getExperience(Skills.SKILL_MAGIC) - origExp == 0) ? 0 : (skills.getExperienceToNextLevel(Skills.SKILL_MAGIC)/((skills.getExperience(Skills.SKILL_MAGIC) - origExp)/ringsAlched))) + " rings", x, y);
  216. y += 13;
  217. g.drawString("Experience gained: " + (skills.getExperience(Skills.SKILL_MAGIC) - origExp), x, y);
  218. y += 13;
  219. g.drawString("Levels gained: " + (skills.getLevel(Skills.SKILL_MAGIC)-origLvl), x, y);
  220. y += 13;
  221. g.drawString("Projected XP/Hour: " + (int)xphours, x, y);
  222. y += 13;
  223. g.drawString("Projected Rings/Hour: " + (ringsAlched > 1 ? (int)xphours/((skills.getExperience(Skills.SKILL_MAGIC) - origExp)/ringsAlched) : 0), x, y);
  224. }
  225.  
  226. /* Contributed from mehhh */
  227. public void randomtab() {
  228. int randomtabs = random(1, 15);
  229. int chance = random(1, 2);
  230. if (randomtabs == 2) {
  231. if (gameScreen.getCurrentTab() != GameScreen.TAB_CLAN) {
  232. log("mehhh Antiban: Opening clan tab.");
  233. gameScreen.openTab(GameScreen.TAB_CLAN);
  234. } else {
  235. if (chance == 1) {
  236. randomtab();
  237. }
  238. }
  239. }
  240. if (randomtabs == 4) {
  241. if (gameScreen.getCurrentTab() != GameScreen.TAB_FRIENDS) {
  242. log("mehhh Antiban: Opening friends tab.");
  243. gameScreen.openTab(GameScreen.TAB_FRIENDS);
  244. } else {
  245. if (chance == 1) {
  246. randomtab();
  247. }
  248. }
  249. }
  250. if (randomtabs == 5) {
  251. if (gameScreen.getCurrentTab() != GameScreen.TAB_IGNORE) {
  252. log("mehhh Antiban: Opening ignore tab.");
  253. gameScreen.openTab(GameScreen.TAB_IGNORE);
  254. } else {
  255. if (chance == 1) {
  256. randomtab();
  257. }
  258. }
  259. }
  260. if (randomtabs >= 13) {
  261. if (gameScreen.getCurrentTab() != GameScreen.TAB_INVENTORY) {
  262. log("mehhh Antiban: Opening inventory tab.");
  263. gameScreen.openTab(GameScreen.TAB_INVENTORY);
  264. } else {
  265. if (chance == 1) {
  266. randomtab();
  267. }
  268. }
  269. }
  270. if (randomtabs == 7) {
  271. if (gameScreen.getCurrentTab() != GameScreen.TAB_MAGIC) {
  272. log("mehhh Antiban: Opening magic tab.");
  273. gameScreen.openTab(GameScreen.TAB_MAGIC);
  274. } else {
  275. if (chance == 1) {
  276. randomtab();
  277. }
  278. }
  279. }
  280. if (randomtabs == 12) {
  281. if (gameScreen.getCurrentTab() != GameScreen.TAB_STATS) {
  282. log("mehhh Antiban: Opening stat tab.");
  283. gameScreen.openTab(GameScreen.TAB_STATS);
  284. } else {
  285. if (chance == 1) {
  286. randomtab();
  287. }
  288. }
  289. }
  290. }
  291.  
  292. //converted from RSBot -- start
  293.  
  294. public void turnCamera() {
  295. char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
  296. char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
  297. char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_UP };
  298. int random2 = random(0,2);
  299. int random1 = random(0,2);
  300. int random4 = random(0,4);
  301. if(random(0,3) == 0) {
  302. botEnv.keyboard.pressKey(LR[random1]);
  303. try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
  304. botEnv.keyboard.pressKey(UD[random2]);
  305. try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
  306. botEnv.keyboard.releaseKey(UD[random2]);
  307. try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
  308. botEnv.keyboard.releaseKey(LR[random1]);
  309. } else {
  310. botEnv.keyboard.pressKey(LRUD[random4]);
  311. if(random4>1) {
  312. try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
  313. } else {
  314. try { Thread.sleep(random(500, 900)); } catch (Exception e) {}
  315. }
  316. botEnv.keyboard.releaseKey(LRUD[random4]);
  317. }
  318. }
  319.  
  320. protected final Logger log = Logger.getLogger(this.getClass().getName());
  321.  
  322. public boolean setCameraAltitude(final double altPercent) {
  323. final int alt = (int) (altPercent / 100 * -1237 - 1226);
  324. int curAlt = botEnv.getClient().getCameraZ();
  325. int lastAlt = 0;
  326.  
  327. if (curAlt == alt) {
  328. log.info("Good: " + curAlt);
  329. return true;
  330. } else if (curAlt > alt) {
  331. botEnv.keyboard.pressKey((char) KeyEvent.VK_UP);
  332. long start = System.currentTimeMillis();
  333. while (curAlt > alt && System.currentTimeMillis() - start < 30) {
  334. if (lastAlt != curAlt) {
  335. start = System.currentTimeMillis();
  336. }
  337. lastAlt = curAlt;
  338.  
  339. sleep(1);
  340. curAlt = botEnv.getClient().getCameraZ();
  341. }
  342. botEnv.keyboard.releaseKey((char) KeyEvent.VK_UP);
  343. return true;
  344. } else {
  345. botEnv.keyboard.pressKey((char) KeyEvent.VK_DOWN);
  346. long start = System.currentTimeMillis();
  347. while (curAlt < alt && System.currentTimeMillis() - start < 30) {
  348. if (lastAlt != curAlt) {
  349. start = System.currentTimeMillis();
  350. }
  351. lastAlt = curAlt;
  352. sleep(1);
  353. curAlt = botEnv.getClient().getCameraZ();
  354. }
  355. botEnv.keyboard.releaseKey((char) KeyEvent.VK_DOWN);
  356. return true;
  357. }
  358. }
  359. //end
  360.  
  361. public void magic() {
  362. if (gameScreen.getCurrentTab() != GameScreen.TAB_STATS) {
  363. gameScreen.openTab(GameScreen.TAB_STATS);
  364. magic();
  365. } else {
  366. log("Checking magic stat.");
  367. moveMouse(new Point(577, 395), random(-15, 15), random(-5, 10));
  368. sleep(random(2000, 2500));
  369. }
  370. }
  371.  
  372. public void antiban() {
  373. int r = random(0, 25);
  374. if(r == 0){
  375. gameScreen.openTab(GameScreen.TAB_INVENTORY);
  376. sleep(800, 1500);
  377. }
  378. if(r == 1) { // Open friends tab
  379. gameScreen.openTab(GameScreen.TAB_FRIENDS);
  380. sleep(800, 1500);
  381. }
  382. if(r == 2 && random(1, 5) == 2 && !getMyPlayer().isMoving()) { // Asks what magic level is
  383. Interface qChat = interfaces.getInterface(137, 52);
  384. if(qChat != null) {
  385. clickMouse(qChat.getRandomPointInside(), true);
  386. sleep(100);
  387. sendText("s", false);
  388. sleep(100);
  389. sendText("m", false);
  390. sleep(800, 1000);
  391. sendText("1", false);
  392. }
  393. }
  394. if(r == 3) { // Move mouse random position
  395. mouse.moveMouse(random(5, 420), random(5, 420));
  396. sleep(300, 700);
  397. }
  398. if(r == 4 && random(1, 3) == 2 && !getMyPlayer().isMoving()) { // Randomly click on players near - 1% chance of this :P
  399. if(players.getPlayers().length == 0)
  400. return;
  401. int randPlayer = random(0, players.getPlayers().length-1);
  402. Point onePoint = getCalculations().tileToScreen(players.getPlayers()[randPlayer].getLocation());
  403. clickMouse(onePoint, 1, 1, false);
  404. sleep(2000);
  405. atMenu("Cancel");
  406. }
  407. if(r == 5 && !getMyPlayer().isMoving()) { // Randomly examine objects
  408. Obj[] objectsAround = objects.getObjects(10);
  409. if(objectsAround.length == 0) // Shouldnt be 0;
  410. return;
  411. int randObjs = random(0, objectsAround.length-1);
  412. objectsAround[randObjs].doAction("Examine");
  413. }
  414. if(r == 5 || r == 6) { // Move camera up and down
  415. char k = (random(0, 1) == 0 ? (char)KeyEvent.VK_DOWN : (char)KeyEvent.VK_UP);
  416. keyboard.pressKey(k);
  417. sleep(random(10, 400));
  418. keyboard.releaseKey(k);
  419. }
  420. if(r == 7 || r == 8) { // Rotate camera
  421. camera.setAngle(camera.getAngle() + random(-90, 90));
  422. gameScreen.openTab(GameScreen.TAB_MAGIC);
  423. antibanTimer = System.currentTimeMillis() + random(15000, 40000);
  424. log("Doing antiban again in: " + ((antibanTimer-System.currentTimeMillis())/1000) + " seconds");
  425. }
  426. if (r == 9 || r == 10) {
  427. magic();
  428. }
  429. if (r == 11 || r == 12) {
  430. sleep(random(1000, 2000));
  431. }
  432. if (r == 13 || r == 14) {
  433. int randomcompass = random(1, 4);
  434. if (randomcompass == 1) {
  435. camera.setCompass('e');
  436. }
  437. if (randomcompass == 2) {
  438. camera.setCompass('w');
  439. }
  440. if (randomcompass == 3) {
  441. camera.setCompass('n');
  442. }
  443. if (randomcompass == 4) {
  444. camera.setCompass('s');
  445. }
  446. }
  447. if (r == 15 || r == 16) {
  448. sleep(random(2000, 3000));
  449. }
  450. if (r == 17 || r == 18) {
  451. setCameraAltitude(random(1, 100));
  452. }
  453. if (r == 19 || r == 20) {
  454. randomtab();
  455. }
  456. if (r >= 21 && r <= 25) {
  457. turnCamera();
  458. }
  459. }
  460.  
  461. }
Add Comment
Please, Sign In to add comment