Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Condition;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.node.SceneObject;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Image;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.text.DecimalFormat;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- @Manifest(authors = { "Gene" }, name = "First Script", description = "Don't Judge", version = 1.0)
- public class Script extends ActiveScript implements PaintListener, MessageListener, MouseListener{
- int[] dropID = { 440, 1607, 1623, 1621, 1619 };
- int MouseX, MouseY;
- int mined;
- int gemCollected;
- int gainLvl;
- int startLvl;
- int MININGCurrentLvl = 0;
- int oN;
- int ironProfit;
- int iron = 440;
- int mineLvl;
- int timeRun;
- int startXP;
- long expHour = 0;
- long startTime;
- long sec, min, hr;
- long elapsedTime;
- long xpTime;
- String xptime;
- long xphr;
- long xpmin;
- long xpsec;
- boolean guiWait = true;
- boolean showPaint = true;
- String time;
- gui gui;
- //START: Code generated using Enfilade's Easel
- private final Color color1 = new Color(255, 102, 0, 127);
- private final Color color2 = new Color(0, 0, 0);
- private final Color color3 = new Color(255, 102, 0, 188);
- private final Color color4 = new Color(255, 102, 0);
- private final Color color5 = new Color(238, 255, 0);
- private final Color color6 = new Color(213, 93, 6);
- public String timeRun() {
- elapsedTime = System.currentTimeMillis() - startTime;
- time = "";
- hr = elapsedTime / (1000 * 60 * 60);
- min = (elapsedTime % (1000 * 60 * 60)) / (1000 * 60);
- sec = ((elapsedTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
- if (hr < 10)
- time += "0" + hr + ":";
- else
- time += hr + ":";
- if (min < 10)
- time += "0" + min + ":";
- else
- time += min + ":";
- if (sec < 10)
- time += "0" + sec;
- else
- time += sec;
- return time;
- }
- int getPrice(int id) throws IOException {
- String price;
- URL url = new URL("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" + id);
- java.net.URLConnection con = url.openConnection();
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String line;
- while ((line = in.readLine()) != null) {
- if (line.contains("<td>")) {
- price = line.substring(line.indexOf(">") + 1, line.indexOf("/") - 1);
- price = price.replace(",", "");
- try {
- return Integer.parseInt(price);
- } catch (Exception e) {
- return -1;
- }
- }
- }
- return -1;
- }
- private class WaitGui implements Task, Condition {
- @Override
- public void run() {
- while (guiWait) {
- Time.sleep(500);
- }
- }
- public boolean validate() {
- return guiWait;
- }
- }
- @Override
- protected void setup() {
- final Mine mine = new Mine();
- final Strategy mineAction = new Strategy(mine, mine);
- final Drop drop = new Drop();
- final Strategy dropAction = new Strategy (drop, drop);
- final WaitGui guiTask = new WaitGui();
- provide(new Strategy(guiTask, guiTask));
- provide(mineAction);
- provide(dropAction);
- startXP = Skills.getExperience(Skills.MINING);
- startLvl = Skills.getLevel(Skills.MINING);
- mineLvl = Skills.getLevel(Skills.MINING);
- startTime = System.currentTimeMillis();
- Tabs.INVENTORY.open();
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- gui = new gui();
- gui.setVisible(true);
- } catch (Exception gui) {
- log.warning("Can't open the GUI: ");
- stop();
- }
- }
- });
- log.info("Author: Gene");
- log.info("Welcome to my first script!");
- }
- public void messageReceived(MessageEvent e) {
- String txt = e.getMessage().toLowerCase();
- if(txt.contains("just found")) {
- System.out.println("You have found a gem!");
- ++gemCollected;
- }
- if(txt.contains("manage to mine")) {
- ++mined;
- }
- }
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch (IOException e) {
- return null;
- }
- }
- private final Image img1 = getImage("http://img442.imageshack.us/img442/258/bg2d.png");
- private final Image img2 = getImage("http://img98.imageshack.us/img98/7050/showbc.png");
- private final Image img3 = getImage("http://img72.imageshack.us/img72/8359/ironv.png");
- private final Image img4 = getImage("http://img339.imageshack.us/img339/3108/progressbar.png");
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Calibri", 1, 18);
- private final Font font2 = new Font("Calibri", 0, 12);
- private final Color orange = new Color(227, 127, 20);
- public void onRepaint(Graphics g1) {
- Graphics2D g2d = (Graphics2D)g1;
- DecimalFormat format = new DecimalFormat("#.##");
- int ironHour = (int) ((mined * 3600000D) / (elapsedTime));
- int gemHour = (int) ((gemCollected * 3600000D) / (elapsedTime));
- gainLvl = (Skills.getLevel(Skills.MINING) - startLvl);
- int xpGain = (Skills.getExperience(Skills.MINING) - startXP);
- int xpHour = (int) ((xpGain) * 3600000D / (System
- .currentTimeMillis() - startTime));
- int currentLvl = (Skills.getLevel(Skills.MINING));
- int lvlGained = (currentLvl - startLvl);
- int level = Skills.getLevel(Skills.MINING);
- int startXP = Skills.getExperienceRequired(level);
- int nextXP = Skills.getExperienceRequired(level + 1);
- double rangeXP = nextXP-startXP;
- double currentRelativeXP = Skills.getExperience(Skills.MINING) - startXP;
- double currentXPleft = nextXP - Skills.getExperience(Skills.MINING);
- double percentA = currentRelativeXP/rangeXP;
- double percentToLvl = ((percentA) * 100D);
- double percent = (int) ((percentA) * 372D);
- xpTime = (long) ((currentXPleft / xpHour) * 3600000D);
- xptime = "";
- if(mined == 0) {
- xphr = 0;
- xpmin = 0;
- xpsec = 0;
- }
- if(mined >= 1) {
- xphr = xpTime / (1000 * 60 * 60);
- xpmin = (xpTime % (1000 * 60 * 60)) / (1000 * 60);
- xpsec = ((xpTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
- }
- if (showPaint) {
- g2d.setColor(orange);
- g2d.setFont(font2);
- g2d.drawImage(img1, -2, 295, null);
- g2d.drawString("" + mined, 120, 389);
- g2d.drawString("" + ironHour, 116, 406);
- g2d.drawString("" + gemCollected, 128, 427);
- g2d.drawString("" + gemHour, 120, 444);
- g2d.drawString("" + currentLvl, 349, 389);
- g2d.drawString("" + lvlGained, 349, 407);
- g2d.drawString("" + xpGain, 328, 429);
- g2d.drawString("" + xpHour, 313, 446);
- g2d.drawString(timeRun(), 315, 489);
- g2d.drawString(xphr + ":" + xpmin + ":" + xpsec, 77, 352);
- g2d.setColor(Color.BLACK);
- g2d.drawImage(img4, 145, 332,(int) (percent), 29, null);
- g2d.setFont(font1);
- g2d.drawString (String.format("%.2f",percentToLvl) + "%" , 310, 352);
- }
- else {
- g2d.drawImage(img2, 459, 472, null);
- }
- }
- private class Mine implements Task, Condition {
- @Override
- public void run() {
- SceneObject rock = SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject entity) {
- return entity.getId() == 11955 || entity.getId() == 11956;
- }
- });
- try {
- ironProfit = (mined*getPrice(iron));
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (rock !=null) {
- if (rock.isOnScreen()) {
- rock.interact("Mine");
- Time.sleep(1700);
- }
- }
- }
- @Override
- public boolean validate() {
- return Inventory.getCount() < 28 && Players.getLocal().getAnimation() == -1;
- }
- }
- private class Drop implements Task, Condition {
- @Override
- public void run() {
- log.info("Dropping...");
- for(;
- Inventory.getItem(iron).getWidgetChild().interact("Drop");
- Time.sleep(1000));
- }
- @Override
- public boolean validate() {
- return Inventory.getCount() == 28;
- }
- }
- @SuppressWarnings("serial")
- public class gui extends JFrame {
- private JPanel contentPane;
- /**
- * Create the frame.
- */
- public gui() {
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- GridBagLayout gbl_contentPane = new GridBagLayout();
- gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- contentPane.setLayout(gbl_contentPane);
- JButton btnStart = new JButton("Start");
- btnStart.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- System.out.println("Bro. Try this.");
- gui.setVisible(false);
- guiWait = false;
- dispose();
- }
- });
- GridBagConstraints gbc_btnStart = new GridBagConstraints();
- gbc_btnStart.insets = new Insets(150, 175, 5, 5);
- gbc_btnStart.gridx = 6;
- gbc_btnStart.gridy = 4;
- contentPane.add(btnStart, gbc_btnStart);
- }
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- Point a = e.getPoint();
- Rectangle area = new Rectangle(464, 478, 48, 17);
- if (area.contains(a)) {
- showPaint = !showPaint;
- }
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- }
- @Override
- public void mousePressed(MouseEvent e) {
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment