Thondar

sd

Jun 12th, 2011
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.74 KB | None | 0 0
  1. import org.rsbot.event.events.MessageEvent;
  2. import org.rsbot.event.listeners.PaintListener;
  3. import org.rsbot.script.*;
  4. import org.rsbot.script.methods.Skills;
  5. import org.rsbot.script.wrappers.*;
  6.  
  7. import javax.imageio.ImageIO;
  8. import javax.swing.*;
  9. import java.awt.*;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.io.IOException;
  13. import java.net.URL;
  14.  
  15.  
  16. @ScriptManifest(authors = {"TT Production"}, keywords = {"Al kharid", "Smelter"}, name = "TT Smelter", description = "Smelts ores in Al Kharid", version = 0.1)
  17.  
  18. public class TTSmelter extends Script implements PaintListener{
  19.  
  20. RSTile furnaceTile = new RSTile (3276,3186);
  21. RSTile bankTile = new RSTile (3270,3166);
  22.  
  23. int oreID1;
  24. int oreID2;
  25. int oreAmount1;
  26. int oreAmount2;
  27. int paintOre1;
  28. int paintOre2;
  29. int barID;
  30. int buttonID;
  31. int bankerID = 496;
  32. int furnaceID = 11666;
  33. int Inventory = 0;
  34. int ironOre = 440;
  35. int ironSteel = 440;
  36. int idle = -1;
  37. int smelting = 3243;
  38. int barsGot;
  39. int barPrice;
  40. int orePrice1;
  41. int orePrice2;
  42. int barcheck;
  43. int expGained = 0;
  44. int expStart = 0;
  45. boolean lvlgain;
  46.  
  47. long starttime;
  48.  
  49. private boolean restCheck;
  50. private boolean antibanCheck;
  51.  
  52. gui g = new gui();
  53.  
  54. private boolean guiWait = true;
  55.  
  56. String optionBar;
  57.  
  58.  
  59. @Override
  60. public boolean onStart() {
  61. mouse.setSpeed(random(4, 6));
  62. starttime = System.currentTimeMillis();
  63. expStart = skills.getCurrentExp(Skills.SMITHING);
  64. g.setVisible(true);
  65. while(guiWait) sleep(500);
  66. barPrice = grandExchange.lookup(barID).getGuidePrice();
  67. orePrice1 = grandExchange.lookup(oreID1).getGuidePrice();
  68. orePrice2 = grandExchange.lookup(oreID2).getGuidePrice();
  69. walking.setRun(true);
  70. return true;
  71. }
  72.  
  73. public void bank() {
  74. RSNPC banker = npcs.getNearest(bankerID);
  75. camera.turnTo(banker);
  76. if(restCheck == true);
  77. if(walking.getEnergy() < 30)
  78. walking.rest(random(70,95));
  79. if (bank.isOpen() && !inventory.contains(oreID1)) {
  80. bank.depositAll();
  81. sleep(200, 350);
  82. Inventory = inventory.getCount(barID);
  83. barsGot += Inventory;
  84. sleep(400, 650);
  85. bank.withdraw(oreID1, oreAmount1);
  86. sleep(700, 950);
  87. if (oreID1 == 436 | oreID1 == ironSteel | oreID1 == 447 | oreID1 == 449 | oreID1 == 451){
  88. bank.withdraw(oreID2, oreAmount2);
  89. }
  90. sleep(1800, 2100);
  91. bank.close();
  92. } else {
  93. if(banker != null) {
  94. if(banker.isOnScreen())
  95. banker.doAction("Bank Banker");{
  96. } sleep(1800, 2100);
  97. } else {
  98. walking.getPath(bankTile).traverse();
  99. }
  100. }
  101. }
  102.  
  103. public void smeltOres(){
  104. barcheck = inventory.getCount(barID);
  105. RSObject furnace = objects.getNearest(furnaceID);
  106. if(restCheck == true);
  107. if(walking.getEnergy() < 30)
  108. walking.rest(random(70,95));
  109. if (furnace.isOnScreen()){
  110. if (barcheck < 1)
  111. furnace.doAction("Smelt");
  112. sleep (1500, 1800);
  113. mouse.click(280,424,true);
  114. sleep(1700, 1900);
  115. }
  116. }
  117.  
  118.  
  119. public boolean atBank(){
  120. RSArea BankArea = new RSArea(new RSTile(3265, 3160),
  121. new RSTile(3272, 3273));
  122. return BankArea.contains(getMyPlayer().getLocation());
  123. }
  124.  
  125. public boolean atAlKharid(){
  126. RSArea AlKharidArea = new RSArea(new RSTile(3264, 3160),
  127. new RSTile(3286, 3197));
  128. return AlKharidArea.contains(getMyPlayer().getLocation());
  129. }
  130.  
  131.  
  132. public boolean atFurnace(){
  133. RSArea FurnaceArea = new RSArea(new RSTile(3272, 3181),
  134. new RSTile(3279, 3188));
  135. return FurnaceArea.contains(getMyPlayer().getLocation());
  136. }
  137.  
  138. private void rest() {
  139. if(restCheck == true);
  140. if(walking.getEnergy() < 30)
  141. walking.rest(random(70,95));
  142. }
  143.  
  144.  
  145. public int loop() {
  146. if(atBank() && !inventory.contains(oreID1)){
  147. bank();
  148. log ("1");
  149. }
  150. if(atBank() && inventory.contains(barID)){
  151. bank();
  152. log ("2");
  153. }
  154. if(atFurnace() && inventory.contains(oreID1)){
  155. smeltOres();
  156. log ("3");
  157. }
  158. if(!atFurnace() && inventory.contains(oreID1)){
  159. walking.walkTo(furnaceTile);
  160. log ("4");
  161. }
  162. if(!atBank() && !inventory.contains(oreID1)){
  163. walking.walkTo(bankTile);
  164. log ("5");
  165. }
  166. if (lvlgain = true)
  167.  
  168.  
  169. if(antibanCheck == true) {
  170. antiBan();
  171. }
  172. if(restCheck == true) {
  173. rest();
  174. }
  175. return random(500, 1500);
  176. }
  177.  
  178. private void antiBan() {
  179. int t = random(0, 10);
  180. int r = random(0, 15);
  181. if (t == 7);
  182. if (r == 2) {
  183. mouse.moveSlightly();
  184. sleep(500, 800);
  185. }
  186.  
  187. if (r == 3) {
  188. mouse.moveRandomly(10, 50);
  189. }
  190.  
  191. if (r == 5) {
  192. camera.moveRandomly(random(350, 650));
  193. }
  194.  
  195. if (r == 6) {
  196. camera.moveRandomly(random(450, 750));
  197. }
  198.  
  199. if (r == 8) {
  200. camera.moveRandomly(random(150, 450));
  201. }
  202.  
  203. if (r == 10) {
  204. camera.moveRandomly(random(750, 1250));
  205. }
  206.  
  207. if (r == 12) {
  208. mouse.moveOffScreen();
  209. }
  210.  
  211. if (r == 14) {
  212. camera.moveRandomly(random(500, 900));
  213. }
  214. }
  215.  
  216.  
  217. public void onFinish() {
  218. }
  219.  
  220. public void messageReceived(MessageEvent e) {
  221. String svrmsg = e.getMessage();
  222. if (svrmsg.contains("you gained a lvl")) {
  223. lvlgain = true;
  224. }
  225. }
  226.  
  227. //---------- PAINT -------------//
  228.  
  229. private Image getImage(String url) {
  230. try {
  231. return ImageIO.read(new URL(url));
  232. } catch(IOException e) {
  233. return null;
  234. }
  235. }
  236.  
  237. private final Color color1 = new Color(255, 255, 255);
  238.  
  239. private final Font font1 = new Font("Calibri", 0, 18);
  240.  
  241. private final Image img1 = getImage("http://i.imgur.com/Dtg7V.jpg");
  242. private final Image img2 = getImage("http://i.imgur.com/cYgmN.png");
  243. private final Image img3 = getImage("http://i.imgur.com/cwGcs.gif");
  244. private final Image img4 = getImage("http://i.imgur.com/DZYci.png");
  245. private final Image img5 = getImage("http://i.imgur.com/qpagD.png");
  246. private final Image img6 = getImage("http://i.imgur.com/1d2Ws.png");
  247. private final Image img9 = getImage("http://i.imgur.com/cayCD.png");
  248. private final Image img8 = getImage("http://i.imgur.com/AwBMJ.png");
  249. private final Image img10 = getImage("http://i.imgur.com/jUylh.png");
  250. private final Image img14 = getImage("http://i.imgur.com/0g8dI.png");
  251. private final Image img15 = getImage("http://i.imgur.com/e6Fw2.png");
  252. private final Image img16 = getImage("http://i.imgur.com/aUisg.png");
  253. private final Image img17 = getImage("http://i.imgur.com/2fxLu.png");
  254.  
  255.  
  256. public void onRepaint(Graphics g1) {
  257.  
  258. expGained = skills.getCurrentExp(Skills.SMITHING) - expStart;
  259.  
  260. long millis = System.currentTimeMillis() - starttime;
  261. long hours = millis / (1000 * 60 * 60);
  262. millis -= hours * (1000 * 60 * 60);
  263. long minutes = millis / (1000 * 60);
  264. millis -= minutes * (1000 * 60);
  265. long seconds = millis / 1000;
  266.  
  267. float barsec = 0;
  268. if ((minutes > 0 || hours > 0 || seconds > 0) && barsGot > 0) {
  269. barsec = ((float) barsGot)/(float)(seconds + (minutes*60) + (hours*60*60));
  270. }
  271.  
  272. float xpsec = 0;
  273. if ((minutes > 0 || hours > 0 || seconds > 0) && expGained > 0) {
  274. xpsec = ((float) expGained)/(float)(seconds + (minutes*60) + (hours*60*60));
  275. }
  276.  
  277. float barmin = barsec * 60;
  278. float abarhour = barmin * 60;
  279. float xpmin = xpsec * 60;
  280. float axphour = xpmin * 60;
  281. int ore1spend = orePrice1 * paintOre1;
  282. int ore2spend = orePrice2 * paintOre2;
  283. int goldspend = ore1spend + ore2spend;
  284. int totalBarPrice = barPrice - goldspend;
  285. float agoldhour = abarhour * totalBarPrice;
  286. int goldearned = barsGot * totalBarPrice;
  287. int barhour = Math.round(abarhour);
  288. int goldhour = Math.round(agoldhour);
  289. int xphour = Math.round(axphour);
  290.  
  291.  
  292. Graphics2D g = (Graphics2D)g1;
  293. g.drawImage(img1, 7, 345, null);
  294. g.drawImage(img2, 11, 439, null);
  295. g.drawImage(img3, 9, 392, null);
  296. g.drawImage(img4, 8, 349, null);
  297. g.setFont(font1);
  298. g.setColor(color1);
  299. g.drawString(+ hours + ":" + minutes + ":" + seconds, 428, 469);
  300. g.drawString("" + goldearned, 70, 417);
  301. g.drawString("" + goldhour, 240, 417);
  302. g.drawString("" + barsGot, 70, 462);
  303. g.drawString("" + barhour, 240, 462);
  304. g.drawString("" + xphour, 240, 371);
  305. g.drawString("" + expGained, 70, 371);
  306. g.drawImage(img5, -4, 428, null);
  307. g.drawImage(img5, -4, 382, null);
  308. g.drawImage(img9, -11, 338, null);
  309. g.drawImage(img6, 510, 332, null);
  310. g.drawImage(img10, 39, 340, null);
  311. g.drawImage(img10, 39, 386, null);
  312. g.drawImage(img10, 378, 340, null);
  313. g.drawImage(img10, 203, 340, null);
  314. g.drawImage(img10, 378, 386, null);
  315. g.drawImage(img10, 203, 385, null);
  316. g.drawImage(img8, -2, 335, null);
  317. g.drawImage(img8, -2, 468, null);
  318. g.drawImage(img14, 150, 403, null);
  319. g.drawImage(img14, 150, 448, null);
  320. g.drawImage(img14, 150, 360, null);
  321. g.drawImage(img15, 325, 403, null);
  322. g.drawImage(img15, 325, 448, null);
  323. g.drawImage(img15, 325, 360, null);
  324. g.drawImage(img16, 398, 346, null);
  325. g.drawImage(img17, 75, 292, null);
  326.  
  327. }
  328.  
  329.  
  330. //------------ GUI -------------//
  331.  
  332. class gui extends JFrame {
  333. public gui() {
  334. initComponents();
  335. }
  336.  
  337. private void startButtonActionPerformed(ActionEvent e) {
  338. String optionBar = oresToSmelt.getSelectedItem().toString();
  339.  
  340. if(optionBar.equals("Bronze")) {
  341. barID = 2349;
  342. oreID1 = 436;
  343. oreID2 = 438;
  344. oreAmount1 = 14;
  345. oreAmount2 = 14;
  346. paintOre1 = 1;
  347. paintOre2 = 1;
  348. }
  349. else if(optionBar.equals("Iron")) {
  350. barID = 2351;
  351. oreID1 = ironOre;
  352. oreAmount1 = 28;
  353. paintOre1 = 1;
  354. paintOre2 = 0;
  355. }
  356. else if(optionBar.equals("Silver")) {
  357. barID = 2355;
  358. oreID1 = 442;
  359. oreAmount1 = 28;
  360. paintOre1 = 1;
  361. paintOre2 = 0;
  362. }
  363. else if(optionBar.equals("Steel")) {
  364. barID = 2353;
  365. oreID1 = ironSteel;
  366. oreID2 = 453;
  367. oreAmount1 = 9;
  368. oreAmount2 = 18;
  369. paintOre1 = 1;
  370. paintOre2 = 2;
  371. }
  372. else if(optionBar.equals("Gold")) {
  373. barID = 2357;
  374. oreID1 = 444;
  375. oreAmount1 = 28;
  376. paintOre1 = 1;
  377. paintOre2 = 0;
  378. }
  379. else if(optionBar.equals("Mithril")) {
  380. barID = 2359;
  381. oreID1 = 447;
  382. oreID2 = 453;
  383. oreAmount1 = 5;
  384. oreAmount2 = 20;
  385. paintOre1 = 1;
  386. paintOre2 = 4;
  387. }
  388. else if(optionBar.equals("Adamantite")) {
  389. barID = 2361;
  390. oreID1 = 449;
  391. oreID2 = 453;
  392. oreAmount1 = 4;
  393. oreAmount2 = 24;
  394. paintOre1 = 1;
  395. paintOre2 = 6;
  396. }
  397. else {
  398. barID = 2363;
  399. oreID1 = 451;
  400. oreID2 = 453;
  401. oreAmount1 = 3;
  402. oreAmount2 = 24;
  403. paintOre1 = 1;
  404. paintOre2 = 8;
  405. }
  406. guiWait = false;
  407. g.dispose();
  408. }
  409.  
  410. private void initComponents() {
  411. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  412. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  413. label1 = new JLabel();
  414. label2 = new JLabel();
  415. checkBox1 = new JCheckBox();
  416. checkBox2 = new JCheckBox();
  417. startButton = new JButton();
  418. oresToSmelt = new JComboBox();
  419.  
  420. //======== this ========
  421. Container contentPane = getContentPane();
  422.  
  423. //---- label1 ----
  424. label1.setText("TT Smelter");
  425. label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 9f));
  426. label1.setHorizontalAlignment(SwingConstants.CENTER);
  427.  
  428. //---- label2 ----
  429. label2.setText("Ores to smelt:");
  430. label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 2f));
  431.  
  432. //---- checkBox1 ----
  433. checkBox1.setText("Rest");
  434.  
  435. //---- checkBox2 ----
  436. checkBox2.setText("Antiban");
  437.  
  438. //---- startButton ----
  439. startButton.setText("Start");
  440. startButton.setFont(startButton.getFont().deriveFont(startButton.getFont().getSize() + 2f));
  441. startButton.addActionListener(new ActionListener() {
  442. @Override
  443. public void actionPerformed(ActionEvent e) {
  444. startButtonActionPerformed(e);
  445. startButtonActionPerformed(e);
  446. }
  447. });
  448.  
  449. //---- oresToSmelt ----
  450. oresToSmelt.setModel(new DefaultComboBoxModel(new String[] {
  451. "Bronze",
  452. "Silver",
  453. "Gold",
  454. "Iron",
  455. "Steel",
  456. "Mithril",
  457. "Adamantite",
  458. "Runite"
  459. }));
  460.  
  461. GroupLayout contentPaneLayout = new GroupLayout(contentPane);
  462. contentPane.setLayout(contentPaneLayout);
  463. contentPaneLayout.setHorizontalGroup(
  464. contentPaneLayout.createParallelGroup()
  465. .addGroup(contentPaneLayout.createSequentialGroup()
  466. .addContainerGap()
  467. .addGroup(contentPaneLayout.createParallelGroup()
  468. .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
  469. .addGroup(contentPaneLayout.createParallelGroup()
  470. .addGroup(contentPaneLayout.createSequentialGroup()
  471. .addComponent(label2, GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
  472. .addGap(18, 18, 18)
  473. .addComponent(oresToSmelt, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE))
  474. .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
  475. .addComponent(checkBox1, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
  476. .addGap(34, 34, 34)
  477. .addComponent(checkBox2, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)))
  478. .addGap(20, 20, 20))
  479. .addGroup(contentPaneLayout.createSequentialGroup()
  480. .addComponent(startButton, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
  481. .addContainerGap())
  482. .addGroup(contentPaneLayout.createSequentialGroup()
  483. .addComponent(label1, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
  484. .addContainerGap())))
  485. );
  486. contentPaneLayout.setVerticalGroup(
  487. contentPaneLayout.createParallelGroup()
  488. .addGroup(contentPaneLayout.createSequentialGroup()
  489. .addGap(6, 6, 6)
  490. .addComponent(label1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  491. .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  492. .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  493. .addComponent(label2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
  494. .addComponent(oresToSmelt, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
  495. .addGap(18, 18, 18)
  496. .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  497. .addComponent(checkBox2)
  498. .addComponent(checkBox1))
  499. .addGap(12, 12, 12)
  500. .addComponent(startButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
  501. .addContainerGap())
  502. );
  503. pack();
  504. setLocationRelativeTo(getOwner());
  505. // JFormDesigner - End of component initialization //GEN-END:initComponents
  506. }
  507.  
  508. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  509. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  510. private JLabel label1;
  511. private JLabel label2;
  512. private JCheckBox checkBox1;
  513. private JCheckBox checkBox2;
  514. private JButton startButton;
  515. private JComboBox oresToSmelt;
  516. // JFormDesigner - End of variables declaration //GEN-END:variables
  517. }
  518. }
Advertisement
Add Comment
Please, Sign In to add comment