Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.rsbot.event.events.ServerMessageEvent;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.event.listeners.ServerMessageListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.util.Timer;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSObject;
- import org.rsbot.script.wrappers.RSTile;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- @ScriptManifest(authors = {"zr0k5"}, keywords = "Money Making", name = "AlKharidTanner", version = 1.0,
- description = "Tans hides for money")
- public class AlKharidTanner extends Script implements PaintListener, ServerMessageListener {
- private final double version = getClass().getAnnotation(
- ScriptManifest.class).version();
- private final int[] HIDE_ID = { 1739,
- 1739, 1753, 1751, 1749, 1747 };
- private final int[] LEATHER_ID = { 1741,
- 1743, 1745, 2505, 2507, 2509 };
- private final int[] CHILD_ID = { 9,
- 10, 13, 14, 15, 16 };
- private final RSTile[] TANNING_PATH = { new RSTile(3269, 3168),
- new RSTile(3277, 3175), new RSTile(3278, 3181),
- new RSTile(3281, 3191), new RSTile(3275, 3192) };
- private final String[] NAMES = { "Cowhides",
- "Cowhides", "Green d'hides", "Blue d'hides",
- "Red d'hides", "Black d'hides" };
- private final int BOOTH_ID = 35647;
- private final int TANNER_ID = 2824;
- private RSTile lastStep = new RSTile(-1, -1);
- private boolean noMoney;
- private int index;
- private int profit;
- private int tanned;
- private final Font font1 = new Font("Tahoma", Font.BOLD, 11);
- private final Font font2 = new Font("Tahoma", Font.PLAIN, 11);
- private final Color color1 = new Color(0, 0, 0, 180);
- private long startTime;
- private long runTime;
- private Timer cameraTimer = new Timer(random(90000, 230000));
- private Timer mouseTimer = new Timer(random(20000, 50000));
- @Override
- public boolean onStart() {
- TannerGUI gui = new TannerGUI();
- gui.setVisible(true);
- while (!gui.isReady) {
- sleep(500);
- }
- gui.dispose();
- log.info("Loading prices...");
- profit = grandExchange.getMarketPrice(LEATHER_ID[index]) -
- grandExchange.getMarketPrice(HIDE_ID[index]);
- startTime = System.currentTimeMillis();
- return true;
- }
- @Override
- public int loop() {
- if (!game.isLoggedIn()) {
- return random(800, 1200);
- }
- mouse.setSpeed(random(8, 11));
- if (noMoney) {
- log.info("No money left");
- stopScript(true);
- }
- antiban();
- if (inventory.contains(HIDE_ID[index])) {
- tan();
- } else {
- bank();
- }
- return random(100, 250);
- }
- private void tan() {
- final RSComponent window = getTanningWindow();
- if (window != null) {
- final int count = inventory.getCount(HIDE_ID[index]);
- if (window.doAction("Tan All")) {
- waitForInventory(HIDE_ID[index], count, true);
- }
- } else {
- if (useTanner()) {
- for (int i = 0; i < 25; i++) {
- if (getMyPlayer().isMoving())
- i = 0;
- if (getTanningWindow() != null)
- break;
- sleep(100, 150);
- }
- }
- }
- }
- private void bank() {
- if (bank.isOpen()) {
- final int count = inventory.getCount(HIDE_ID[index]);
- final int count2 = inventory.getCount(LEATHER_ID[index]);
- if (count2 > 0) {
- bank.deposit(LEATHER_ID[index], 0);
- waitForInventory(LEATHER_ID[index], count2, true);
- } else {
- if (bank.getCount(HIDE_ID[index]) < 1) {
- log.info("All hides tanned");
- stopScript(true);
- }
- bank.withdraw(HIDE_ID[index], 0);
- waitForInventory(HIDE_ID[index], count, false);
- }
- } else {
- if (useBooth()) {
- for (int i = 0; i < 25; i++) {
- if (getMyPlayer().isMoving())
- i = 0;
- if (bank.isOpen())
- break;
- sleep(100, 150);
- }
- }
- }
- }
- private RSComponent getTanningWindow() {
- final RSComponent window = interfaces.getComponent(324, CHILD_ID[index]);
- if (window != null && window.isValid() && window.getArea().getX() > 0
- && window.getArea().getY() > 0 && window.getArea().width > 0 && window.getArea().height > 0)
- return window;
- return null;
- }
- private boolean useBooth() {
- final RSObject booth = objects.getNearest(BOOTH_ID);
- if (booth != null && booth.isOnScreen()) {
- if (!getMyPlayer().isMoving())
- return booth.doAction("Use-quickly");
- } else {
- walkPath(walking.reversePath(TANNING_PATH));
- }
- return false;
- }
- private boolean useTanner() {
- final RSNPC tanner = npcs.getNearest(TANNER_ID);
- if (tanner != null && tanner.isOnScreen()) {
- if (!getMyPlayer().isMoving())
- return tanner.doAction("Trade Ellis");
- } else {
- walkPath(TANNING_PATH);
- }
- return false;
- }
- private void waitForInventory(final int id, final int count, final boolean less) {
- for (int i = 0; i < 25; i++) {
- final int thisCount = inventory.getCount(id);
- if ((less && thisCount < count) || (!less && thisCount > count))
- break;
- sleep(100, 150);
- }
- }
- private void walkPath(final RSTile[] path) {
- if (!walking.isRunEnabled() && walking.getEnergy() >= random(35, 50)) {
- walking.setRun(true);
- sleep(900, 1200);
- }
- if (!(getMyPlayer().isMoving() && lastStep.equals(path[path.length - 1]))) {
- final RSTile step = getNextTile(path);
- if (step != null) {
- if (!getMyPlayer().isMoving() || (step != null && !step.equals(lastStep))) {
- if (walking.walkTileMM(step, 2, 2)) {
- sleep(700, 900);
- lastStep = step;
- }
- }
- }
- }
- }
- private RSTile getNextTile(final RSTile[] path) {
- for (int i = path.length - 1; i >= 0; i--) {
- if (calc.tileOnMap(path[i]))
- return path[i];
- }
- return null;
- }
- private void antiban() {
- if (!mouseTimer.isRunning()) {
- if (random(0, 2) == 1) {
- mouse.moveSlightly();
- } else {
- mouse.moveRandomly(random(100, 350));
- }
- mouseTimer.setEndIn(random(20000, 50000));
- }
- if (!cameraTimer.isRunning()) {
- if (random(0, 10) < 9) {
- camera.setAngle(random(1, 360));
- }
- if (random(0, 6) == 1) {
- camera.setPitch(random(1, 100));
- }
- cameraTimer.setEndIn(random(90000, 230000));
- }
- }
- @SuppressWarnings("serial")
- public class TannerGUI extends JFrame {
- private boolean isReady;
- public TannerGUI() {
- initComponents();
- }
- private void button1ActionPerformed(ActionEvent e) {
- index = comboBox1.getSelectedIndex();
- isReady = true;
- }
- private void initComponents() {
- comboBox1 = new JComboBox();
- button1 = new JButton();
- setTitle("AlKharidTanner");
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- setResizable(false);
- setAlwaysOnTop(true);
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- comboBox1.setModel(new DefaultComboBoxModel(new String[] {
- "Cowhide (soft)",
- "Cowhide (hard)",
- "Green dragonhide",
- "Blue dragonhide",
- "Red dragonhide",
- "Black dragonhide"
- }));
- contentPane.add(comboBox1);
- comboBox1.setBounds(10, 20, 170, 30);
- button1.setText("Start");
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(10, 65, 170, 25);
- {
- Dimension preferredSize = new Dimension();
- for(int i = 0; i < contentPane.getComponentCount(); i++) {
- Rectangle bounds = contentPane.getComponent(i).getBounds();
- preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
- preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
- }
- Insets insets = contentPane.getInsets();
- preferredSize.width += insets.right;
- preferredSize.height += insets.bottom;
- contentPane.setMinimumSize(preferredSize);
- contentPane.setPreferredSize(preferredSize);
- }
- setSize(200, 125);
- setLocationRelativeTo(getOwner());
- }
- private JComboBox comboBox1;
- private JButton button1;
- }
- @Override
- public void serverMessageRecieved(ServerMessageEvent e) {
- final String msg = e.getMessage();
- if (msg != null) {
- if (msg.startsWith("You haven't got enough")) {
- noMoney = true;
- } else if (msg.startsWith("The tanner tans")) {
- tanned += Integer.parseInt(msg.split(" ")[3]);
- }
- }
- }
- private String formatTime(final long time) {
- final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
- return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
- + (s < 10 ? "0" + s : s);
- }
- @Override
- public void onRepaint(Graphics g1) {
- final Graphics2D g2 = (Graphics2D) g1;
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setColor(color1);
- g2.fillRect(350, 5, 160, 115);
- g2.setColor(Color.WHITE);
- g2.setFont(font1);
- g2.drawString("AlKharidTanner v." + version, 355, 20);
- g2.setFont(font2);
- runTime = System.currentTimeMillis() - startTime;
- g2.drawString("Runtime: " + formatTime(runTime), 355, 35);
- g2.drawString("Tanning: " + NAMES[index], 355, 50);
- g2.drawString("Hides tanned: " + tanned, 355, 65);
- g2.drawString("Hides tanned/h: " + (int) ((3600000.0 / (double) runTime) * tanned), 355, 80);
- g2.drawString("Profit: " + (tanned * profit), 356, 95);
- g2.drawString("Profit/h: " + (int) ((3600000.0 / (double) runTime) * (tanned * profit)), 356, 110);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement