Thondar

sd

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