Advertisement
Guest User

Miner

a guest
Oct 3rd, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.46 KB | None | 0 0
  1. package scripts;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.Toolkit;
  5.  
  6. import javax.swing.JFrame;
  7.  
  8. import org.tribot.api.DynamicClicking;
  9. import org.tribot.api.General;
  10. import org.tribot.api.Timing;
  11. import org.tribot.api.types.generic.Condition;
  12. import org.tribot.api.util.ABCUtil;
  13. import org.tribot.api2007.Banking;
  14. import org.tribot.api2007.Inventory;
  15. import org.tribot.api2007.Login;
  16. import org.tribot.api2007.Objects;
  17. import org.tribot.api2007.Player;
  18. import org.tribot.api2007.Skills;
  19. import org.tribot.api2007.Skills.SKILLS;
  20. import org.tribot.api2007.WebWalking;
  21. import org.tribot.api2007.types.RSItem;
  22. import org.tribot.api2007.types.RSObject;
  23. import org.tribot.api2007.types.RSTile;
  24. import org.tribot.script.Script;
  25. import org.tribot.script.ScriptManifest;
  26. import org.tribot.script.interfaces.Painting;
  27.  
  28. @ScriptManifest(authors = { "Netami" }, category = "Mining", name = "Lumbridge Miner", version = 1.00, description = "Mines Tin/Copper in Lumbridge swamp to get to a desired level. Currently supports logging off or walking to Motherlode mine following target level being reached. Please post on forums with any bugs/improvements, thanks!", gameMode = 1)
  29.  
  30. public class Miner_v2 extends Script implements Painting{
  31.  
  32. public boolean runScript = true;
  33. public boolean GUI_COMPLETE = false;
  34. public boolean walkToMotherload = false;
  35. public boolean logoutOnTarget = true;
  36. public int targetLevel;
  37. public ABCUtil abc = new ABCUtil();
  38. RSTile rockSpots[] = {new RSTile(3228,3145,0),new RSTile(3223,3147,0),new RSTile(3229,3147,0)};
  39. public RSTile rockSpot = rockSpots[General.random(0,2)];
  40. public int initialXp = Skills.getXP(SKILLS.MINING);
  41. public int initialLevel = Skills.getCurrentLevel(SKILLS.MINING);
  42.  
  43. @Override
  44. public void run() {
  45. miner_v2_GUI GUI = new miner_v2_GUI();
  46. JFrame f = new JFrame();
  47. f.getContentPane();
  48. f.add(GUI);
  49. Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
  50. int screenW = (screensize.width) / 2;
  51. int screenH = (screensize.height / 2);
  52. f.setVisible(true);
  53. f.setLocation(screenW / 2, screenH / 2);
  54. f.setSize(450,265);
  55.  
  56. while(!GUI_COMPLETE){
  57. sleep(300);
  58. }
  59. f.setVisible(false);
  60.  
  61. startBank();
  62.  
  63. if(Player.getPosition() != rockSpot && Skills.getCurrentLevel(SKILLS.MINING) != targetLevel){
  64. println("We are not at the mining spot, walking there now...");
  65. WebWalking.walkTo(rockSpot);
  66. }
  67. while(runScript){
  68. if(Skills.getCurrentLevel(SKILLS.MINING) < targetLevel){
  69. mine();
  70. sleep(50);
  71. }else{
  72. if(walkToMotherload){
  73. walkToMotherload();
  74. runScript = false;
  75. }else{
  76. Login.logout();
  77. runScript = false;
  78. }
  79. }
  80. }
  81. }
  82.  
  83. public void startBank(){
  84. WebWalking.walkToBank();
  85. sleep(1000,2000);
  86. Banking.openBank();
  87. sleep(500,800);
  88. Banking.depositAll();
  89. sleep(1000,2000);
  90. RSItem[] pick = Banking.find(1265,1267,1269,1271,1273,1275);
  91. if(pick.length == 0){
  92. runScript = false;
  93. println("No pickaxe found!");
  94. }else{
  95. Banking.withdrawItem(pick[0], 1);
  96. }
  97. sleep(1000,2000);
  98. Banking.close();
  99. sleep(500,900);
  100. RSItem[] inventPick = Inventory.find(1265,1267,1269,1271,1273,1275);
  101. if(inventPick[0] != null){
  102. inventPick[0].click("Wield");
  103. }
  104. sleep(2000,4000);
  105. }
  106.  
  107. public void mine(){
  108. if(this.abc.TIME_TRACKER.ROTATE_CAMERA.next() > System.currentTimeMillis()){
  109. abc.performRotateCamera();
  110. this.abc.TIME_TRACKER.ROTATE_CAMERA.reset();
  111. abc.performTimedActions(SKILLS.MINING);
  112. }
  113.  
  114. if(Inventory.isFull()){
  115. Inventory.dropAllExcept(1265,1267,1269,1271,1273,1275);
  116. }
  117.  
  118. if(!Player.isMoving() && Player.getAnimation() == -1 && !Inventory.isFull()){
  119. final RSObject rocks[]= Objects.findNearest(5, 14886,14884,14885,14864,14883);
  120. RSObject rockToClick = rocks[0];
  121. if(rocks.length > 0 && this.abc.BOOL_TRACKER.USE_CLOSEST.next()){
  122. rockToClick = rocks[1];
  123. }
  124. if(DynamicClicking.clickRSObject(rockToClick, "Mine")){
  125. sleep(500,1000);
  126. Timing.waitCondition(new Condition()
  127. {
  128. @Override
  129. public boolean active()
  130. {
  131. return Player.getAnimation() != -1;
  132. }
  133. }, General.random(500, 1000));
  134. }
  135. }
  136.  
  137. }
  138.  
  139. private void walkToMotherload()
  140. {
  141. WebWalking.walkTo(new RSTile (3061, 3376, 0));
  142. sleep(2000,5000);
  143. RSObject[] stairs = Objects.findNearest(10, 16664);
  144. if(stairs != null){
  145. DynamicClicking.clickRSObject(stairs[0], "Climb-down");
  146. }
  147. sleep(3000,5000);
  148. WebWalking.walkTo(new RSTile(3060,9766,0));
  149. sleep(500,800);
  150. RSObject[] cave = Objects.findNearest(10, 26654);
  151. if(cave != null){
  152. DynamicClicking.clickRSObject(cave[0], "Enter");
  153. }
  154. sleep(3000,5000);
  155. Login.logout();
  156. }
  157.  
  158. @SuppressWarnings("serial")
  159. class miner_v2_GUI extends javax.swing.JPanel {
  160.  
  161. public miner_v2_GUI() {
  162. initComponents();
  163. }
  164.  
  165. private void initComponents() {
  166.  
  167. buttonGroup1 = new javax.swing.ButtonGroup();
  168. jRadioButton1 = new javax.swing.JRadioButton();
  169. jRadioButton2 = new javax.swing.JRadioButton();
  170. jSpinner1 = new javax.swing.JSpinner();
  171. jButton1 = new javax.swing.JButton();
  172. jLabel1 = new javax.swing.JLabel();
  173. jLabel2 = new javax.swing.JLabel();
  174. jLabel3 = new javax.swing.JLabel();
  175.  
  176. buttonGroup1.add(jRadioButton1);
  177. jRadioButton1.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
  178. jRadioButton1.setText("Logout when target reached");
  179.  
  180. buttonGroup1.add(jRadioButton2);
  181. jRadioButton2.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
  182. jRadioButton2.setText("Walk to motherload when target reached");
  183.  
  184. jSpinner1.setModel(new javax.swing.SpinnerNumberModel(30, 2, 99, 1));
  185.  
  186. jButton1.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
  187. jButton1.setText("Start");
  188. jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
  189. jButton1.addActionListener(new java.awt.event.ActionListener() {
  190. public void actionPerformed(java.awt.event.ActionEvent evt) {
  191. jButton1ActionPerformed(evt);
  192. }
  193. });
  194.  
  195. jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 48)); // NOI18N
  196. jLabel1.setText("Lumby Miner ");
  197.  
  198. jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 36)); // NOI18N
  199. jLabel2.setText("Target Level:");
  200.  
  201. jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
  202. jLabel3.setText("by Netami");
  203.  
  204. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  205. this.setLayout(layout);
  206. layout.setHorizontalGroup(
  207. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  208. .addGroup(layout.createSequentialGroup()
  209. .addGap(31, 31, 31)
  210. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  211. .addGroup(layout.createSequentialGroup()
  212. .addGap(9, 9, 9)
  213. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  214. .addComponent(jRadioButton1)
  215. .addComponent(jRadioButton2))
  216. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 120, Short.MAX_VALUE)
  217. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
  218. .addGroup(layout.createSequentialGroup()
  219. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  220. .addGroup(layout.createSequentialGroup()
  221. .addComponent(jLabel2)
  222. .addGap(18, 18, 18)
  223. .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  224. .addGroup(layout.createSequentialGroup()
  225. .addComponent(jLabel1)
  226. .addGap(18, 18, 18)
  227. .addComponent(jLabel3)))
  228. .addGap(0, 0, Short.MAX_VALUE)))
  229. .addContainerGap())
  230. );
  231. layout.setVerticalGroup(
  232. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  233. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  234. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  235. .addGroup(layout.createSequentialGroup()
  236. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  237. .addComponent(jButton1))
  238. .addGroup(layout.createSequentialGroup()
  239. .addGap(29, 29, 29)
  240. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  241. .addGroup(layout.createSequentialGroup()
  242. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  243. .addComponent(jLabel1)
  244. .addComponent(jLabel3))
  245. .addGap(28, 28, 28)
  246. .addComponent(jLabel2))
  247. .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
  248. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
  249. .addComponent(jRadioButton1)
  250. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  251. .addComponent(jRadioButton2)))
  252. .addGap(26, 26, 26))
  253. );
  254. }// </editor-fold>
  255.  
  256. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  257. if(jRadioButton1.isSelected()){
  258. logoutOnTarget = true;
  259. walkToMotherload = false;
  260. }else{
  261. walkToMotherload = true;
  262. logoutOnTarget = false;
  263. }
  264. targetLevel = (Integer) jSpinner1.getValue();
  265. GUI_COMPLETE = true;
  266. }
  267.  
  268. // Variables declaration - do not modify
  269. private javax.swing.ButtonGroup buttonGroup1;
  270. private javax.swing.JButton jButton1;
  271. private javax.swing.JRadioButton jRadioButton1;
  272. private javax.swing.JRadioButton jRadioButton2;
  273. private javax.swing.JSpinner jSpinner1;
  274. private javax.swing.JLabel jLabel1;
  275. private javax.swing.JLabel jLabel2;
  276. private javax.swing.JLabel jLabel3;
  277. // End of variables declaration
  278. }
  279.  
  280. public void onPaint(Graphics g) {
  281. int gainedXp = (int)Skills.getXP(Skills.SKILLS.MINING) - initialXp;
  282. int currentLevel = (int)Skills.getCurrentLevel(Skills.SKILLS.MINING);
  283. int gainedLevels = currentLevel - initialLevel;
  284. g.drawString("Time Ran: " + Timing.msToString(getRunningTime()), 10, 40);
  285. g.drawString("Mining xp gained: " + gainedXp, 10, 60);
  286. g.drawString("Current Level: " + currentLevel + " (" + gainedLevels + ")" , 10, 80);
  287. }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement