Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.Graphics2D;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JSeparator;
- import javax.swing.JTextField;
- import org.osbot.rs07.api.Bank;
- import org.osbot.rs07.api.Dialogues;
- import org.osbot.rs07.api.GrandExchange;
- import org.osbot.rs07.api.GrandExchange.Box;
- import org.osbot.rs07.api.GrandExchange.Status;
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.api.model.Entity;
- import org.osbot.rs07.api.ui.RS2Widget;
- import org.osbot.rs07.api.ui.Tab;
- import org.osbot.rs07.canvas.paint.Painter;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- @ScriptManifest(author = "Castro_", info = "Creates planks in your PoH.", logo = "", name = ">C< House Planks", version = 0)
- public class Main extends Script implements Painter{
- private long startTime;
- public String status = "";
- public boolean gui_COMPLETE = false;
- public long log_counter = 26;
- public boolean in_house = false;
- public String planks_to_make = "";
- public int plank_id = 0;
- public int log_id = 0;
- public int planks_made = 0;
- // ge
- public boolean should_restock = false;
- public boolean should_Ge = false;
- public int buy_logs_price = 0;
- public int buy_logs_amount = 0;
- public int sell_planks_price = 0;
- Area GRAND_EXCHANGE_AREA = new Area(3161, 3485, 3169, 3492);
- Area LUMBRIDGE_PVP_BANK_AREA = new Area(3220, 3214, 3225, 3222);
- Area VARROCK_TELEPORT_AREA = new Area(3207, 3420, 3219, 3428);
- private static int getPrice(final int id) {
- try {
- URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id);
- URLConnection con = url.openConnection();
- con.setUseCaches(true);
- BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String[] data = br.readLine().replace("{", "").replace("}", "").split(",");
- return Integer.parseInt(data[0].split(":")[1]);
- } catch (Exception e) {
- }
- return -1;
- }
- public final String formatTime(final long ms) {
- long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
- s %= 60;
- m %= 60;
- h %= 24;
- return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s)
- : h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s);
- }
- public void onStart() {
- status = "Waiting for GUI";
- log(status);
- GUI gui = new GUI();
- Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
- int screenW = screensize.width / 2;
- int screenH = screensize.height / 2;
- gui.frmc.setVisible(true);
- gui.frmc.setLocation(screenW / 2, screenH / 2);
- while (!this.gui_COMPLETE) {
- try {
- sleep(300L);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- gui.frmc.setVisible(false);
- status = "GUI completed";
- log(status);
- startTime = System.currentTimeMillis();
- }
- @Override
- public int onLoop() throws InterruptedException {
- if (getInventory().getAmount("Coins") > 50000 && getInventory().getAmount("Teleport to house") > 1
- && getInventory().getAmount("Teleport to Lumbridge") > 1) {
- if (LUMBRIDGE_PVP_BANK_AREA.contains(myPlayer().getPosition()) && !getInventory().isFull()
- && log_counter >= 25) {
- status = "Withdrawing "+planks_to_make+" logs";
- withdraw_logs();
- } else {
- if (getInventory().contains(planks_to_make + " logs") && in_house == false) {
- status = "Teleporting to House";
- teleport_to_house();
- } else {
- if (in_house == true && getInventory().contains(planks_to_make + " logs")) {
- status = "Creating planks";
- create_planks();
- } else {
- if (getWorlds().getCurrentWorld() == 325 && should_Ge == true) {
- status = "Hopping to non-PvP world";
- hop_to_non_pvp();
- } else {
- if (should_Ge == true && should_restock == true) {
- if (should_Ge == true && LUMBRIDGE_PVP_BANK_AREA.contains(myPlayer().getPosition())
- && getWorlds().getCurrentWorld() != 325) {
- status = "Teleporting to Varrock";
- teleport_to_varrock();
- } else {
- if (VARROCK_TELEPORT_AREA.contains(myPlayer().getPosition())) {
- status = "Walking to Grand Exchange";
- to_grand_exchange();
- } else {
- if (GRAND_EXCHANGE_AREA.contains(myPlayer().getPosition())
- && getInventory().contains(planks_to_make + " plank")
- && should_Ge == true) {
- status = "Selling "+planks_to_make+" planks";
- sell_planks();
- } else {
- if (GRAND_EXCHANGE_AREA.contains(myPlayer().getPosition())
- && !getInventory().contains(planks_to_make + " plank")
- && should_Ge == true) {
- status = "Buying "+buy_logs_amount+" "+planks_to_make +" logs";
- buy_logs();
- } else {
- if (getWorlds().getCurrentWorld() != 325 && should_Ge == false) {
- status = "Hopping to PvP world";
- hop_to_pvp();
- } else {
- if (GRAND_EXCHANGE_AREA.contains(myPlayer().getPosition())
- && !getInventory().isFull() && log_counter >= 25) {
- status = "Withdrawing "+planks_to_make+" logs";
- withdraw_logs_grand_exchange();
- } else {
- if (in_house == true
- && !getInventory().contains(planks_to_make + " logs")) {
- status = "Teleporting to Lumbridge";
- teleport_to_lumbrdge();
- }
- }
- }
- }
- }
- }
- }
- } else {
- if (should_Ge == true && should_restock == false) {
- status = "Out of "+planks_to_make+" logs; stopping script.";
- log("Out of logs; restock mode off.");
- stop();
- }
- }
- }
- }
- }
- }
- }else {
- if (getInventory().getAmount("Coins") < 50000 || getInventory().getAmount("Teleport to house") < 1
- || getInventory().getAmount("Teleport to Lumbridge") < 1) {
- status = "Out of supplies; stopping script.";
- log("Out of supplies; stopping script.");
- stop();
- }
- }
- return random(20, 40);
- }
- public void teleport_to_lumbrdge() {
- getInventory().interact("Break", "Lumbridge teleport");
- in_house = false;
- planks_made = planks_made+25;
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return LUMBRIDGE_PVP_BANK_AREA.contains(myPlayer().getPosition());
- }
- }.sleep();
- }
- public void create_planks() {
- getTabs().open(Tab.SETTINGS);
- if (getTabs().getOpen().equals(Tab.SETTINGS)) {
- RS2Widget house_options = getWidgets().get(261, 81);
- RS2Widget call_servant = getWidgets().get(370, 19, 0);
- if (house_options != null) {
- house_options.interact("View House Options");
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return call_servant != null;
- }
- }.sleep();
- if (call_servant != null) {
- Entity demon_butler = getNpcs().closest("Demon butler");
- call_servant.interact("Call Servant");
- new ConditionalSleep(random(10000, 12000)) {
- @Override
- public boolean condition() {
- return getDialogues().inDialogue() == true;
- }
- }.sleep();
- if (getDialogues().inDialogue() == false) {
- getWalking().walk(demon_butler);
- demon_butler.interact("Talk-to");
- } else {
- if (getDialogues().toString().contains(
- "Master, if thou desirest my continued service thou must render unto me the 10,000 coins that are due to me!")) {
- try {
- getDialogues().completeDialogue("Click here to continue", "Okay, here's 10,000 coins.",
- "Click here to continue");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else {
- try {
- getDialogues().completeDialogue("Okay, here's 10,000 coins.", "Take to sawmill:",
- "Click here to continue", "Yes", "Click here to continue");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
- }
- public void teleport_to_house() {
- Entity house_portal = getObjects().closest("Portal");
- if (LUMBRIDGE_PVP_BANK_AREA.contains(myPlayer().getPosition())
- || GRAND_EXCHANGE_AREA.contains(myPlayer().getPosition())) {
- getInventory().interact("Break", "Teleport to house");
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return house_portal != null && house_portal.isOnScreen();
- }
- }.sleep();
- }
- if (house_portal != null && house_portal.isOnScreen()) {
- in_house = true;
- }
- }
- public void hop_to_pvp() {
- if (getWorlds().getCurrentWorld() != 325 && should_Ge == false) {
- getWorlds().hop(325);
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return getDialogues().inDialogue();
- }
- }.sleep();
- if (getDialogues().inDialogue()) {
- try {
- getDialogues().completeDialogue("Switch to the PvP world.");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- public void hop_to_non_pvp() {
- if (getWorlds().getCurrentWorld() == 325 && should_Ge == true) {
- getWorlds().hopToP2PWorld();
- }
- }
- public void teleport_to_varrock() {
- if (should_Ge == true && LUMBRIDGE_PVP_BANK_AREA.contains(myPlayer().getPosition())
- && getWorlds().getCurrentWorld() != 325) {
- status = "Teleporting to Varrock";
- getInventory().interact("Break", "Varrock teleport");
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return VARROCK_TELEPORT_AREA.contains(myPlayer().getPosition());
- }
- }.sleep();
- }
- }
- public void to_grand_exchange() {
- if (VARROCK_TELEPORT_AREA.contains(myPlayer().getPosition())) {
- status = "Walking to Grand Exchange";
- getWalking().webWalk(GRAND_EXCHANGE_AREA);
- }
- }
- public void withdraw_logs() {
- status = "Withdrawing logs";
- if (getBank().isOpen() == false) {
- try {
- getBank().open();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (getBank().isOpen() && getBank().contains(planks_to_make + " logs")) {
- log_counter = getBank().getAmount(planks_to_make + " logs");
- if (log_counter >= 25) {
- getBank().withdraw(planks_to_make + " logs", 25);
- getBank().close();
- } else {
- if (log_counter < 25) {
- getBank().withdraw("Varrock teleport", 1);
- if (getBank().getWithdrawMode().equals(Bank.BankMode.WITHDRAW_NOTE) == true) {
- getBank().withdrawAll(planks_to_make + " plank");
- getBank().enableMode(Bank.BankMode.WITHDRAW_ITEM);
- } else {
- if (getBank().getWithdrawMode().equals(Bank.BankMode.WITHDRAW_NOTE) == false) {
- getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
- getBank().withdrawAll(planks_to_make + " plank");
- getBank().enableMode(Bank.BankMode.WITHDRAW_ITEM);
- }
- }
- getBank().close();
- try {
- sleep(random(750, 1250));
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- should_Ge = true;
- }
- }
- }
- }
- }
- public void withdraw_logs_grand_exchange() {
- status = "Withdrawing logs";
- if (getBank().isOpen() == false) {
- try {
- getBank().open();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (getBank().isOpen() && getBank().contains(planks_to_make + " logs")) {
- log_counter = getBank().getAmount(planks_to_make + " logs");
- if (log_counter >= 25) {
- getBank().withdraw(planks_to_make + " logs", 25);
- getBank().close();
- } else {
- if (log_counter < 25) {
- getBank().withdraw("Varrock teleport", 1);
- if (getBank().getWithdrawMode().equals(Bank.BankMode.WITHDRAW_NOTE) == true) {
- getBank().withdrawAll(planks_to_make + " plank");
- getBank().enableMode(Bank.BankMode.WITHDRAW_ITEM);
- } else {
- if (getBank().getWithdrawMode().equals(Bank.BankMode.WITHDRAW_NOTE) == false) {
- getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
- getBank().withdrawAll(planks_to_make + " plank");
- getBank().enableMode(Bank.BankMode.WITHDRAW_ITEM);
- }
- }
- getBank().close();
- should_Ge = true;
- }
- }
- }
- }
- }
- public void sell_planks() {
- Entity GE_BOOTH = getObjects().closest(GRAND_EXCHANGE_AREA, "Grand Exchange booth");
- if (getGrandExchange().isOpen() == false) {
- if (GE_BOOTH.interact("Exchange")) {
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return getGrandExchange().isOpen() == true;
- }
- }.sleep();
- }
- if (getGrandExchange().isOpen() == true) {
- getGrandExchange().sellItem(plank_id, sell_planks_price,
- Integer.valueOf((int) getInventory().getAmount(planks_to_make + " plank")));
- new ConditionalSleep(random(30000, 45000)) {
- @Override
- public boolean condition() {
- return grandExchange.getStatus(Box.BOX_1) == Status.FINISHED_SALE;
- }
- }.sleep();
- }
- if (grandExchange.getStatus(Box.BOX_1) == Status.FINISHED_SALE) {
- getGrandExchange().collect();
- log(">C< House Planker: Planks sold");
- getGrandExchange().close();
- } else {
- if (grandExchange.getStatus(Box.BOX_1) == Status.PENDING_SALE) {
- log(">C< House Planker: Planks taking too long to sell... stopping script");
- stop();
- }
- }
- }
- }
- public void buy_logs() {
- Entity GE_BOOTH = getObjects().closest(GRAND_EXCHANGE_AREA, "Grand Exchange booth");
- if (getGrandExchange().isOpen() == false) {
- if (GE_BOOTH.interact("Exchange")) {
- new ConditionalSleep(random(5000, 7000)) {
- @Override
- public boolean condition() {
- return getGrandExchange().isOpen() == true;
- }
- }.sleep();
- }
- if (getGrandExchange().isOpen() == true) {
- getGrandExchange().buyItem(log_id, planks_to_make + " logs", buy_logs_price, buy_logs_amount);
- new ConditionalSleep(random(30000, 45000)) {
- @Override
- public boolean condition() {
- return grandExchange.getStatus(Box.BOX_1) == Status.FINISHED_BUY;
- }
- }.sleep();
- }
- if (grandExchange.getStatus(Box.BOX_1) == Status.FINISHED_BUY) {
- getGrandExchange().collect(true);
- log(">C< House Planker: Logs bought");
- log_counter = buy_logs_amount;
- should_Ge = false;
- } else {
- if (grandExchange.getStatus(Box.BOX_1) == Status.PENDING_BUY) {
- log(">C< House Planker: Logs taking too long to buy... stopping script");
- stop();
- }
- }
- }
- }
- @Override
- public void onPaint(final Graphics2D g) {
- final long runTime = System.currentTimeMillis() - startTime;
- g.setColor(Color.WHITE);
- Font font = new Font("Verdana", Font.PLAIN, 17);
- g.setFont(font);
- g.drawString(">C< House Planker - v0.1", 29, 204);
- Font font2 = new Font("Verdana", Font.PLAIN, 12);
- g.setFont(font2);
- g.drawString("Time running: " + formatTime(runTime), 29, 224);
- g.drawString("Status: " + status, 29, 244);
- g.drawString("Planks made: "+planks_made, 29, 264);
- }
- public class GUI {
- private JFrame frmc;
- private JTextField textField;
- private JTextField textField_1;
- private JTextField textField_2;
- private JTextField textField_3;
- public GUI() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmc = new JFrame();
- frmc.setResizable(false);
- frmc.setTitle(">C< House Plank Maker");
- frmc.setBounds(100, 100, 314, 277);
- frmc.getContentPane().setLayout(null);
- JLabel lblPlankSettings = new JLabel("Plank settings:");
- lblPlankSettings.setForeground(Color.GRAY);
- lblPlankSettings.setBounds(10, 11, 81, 14);
- frmc.getContentPane().add(lblPlankSettings);
- JComboBox comboBox = new JComboBox();
- comboBox.setModel(new DefaultComboBoxModel(new String[] { "Oak", "Teak", "Mahogany" }));
- comboBox.setBounds(92, 36, 206, 20);
- frmc.getContentPane().add(comboBox);
- JLabel lblPlanksToMake = new JLabel("Planks to make:");
- lblPlanksToMake.setBounds(10, 39, 81, 14);
- frmc.getContentPane().add(lblPlanksToMake);
- JSeparator separator = new JSeparator();
- separator.setBounds(0, 67, 311, 2);
- frmc.getContentPane().add(separator);
- JLabel lblGrandExchangeSettings = new JLabel("Grand Exchange settings:");
- lblGrandExchangeSettings.setForeground(Color.GRAY);
- lblGrandExchangeSettings.setBounds(10, 79, 169, 14);
- frmc.getContentPane().add(lblGrandExchangeSettings);
- JCheckBox chckbxRestockLogs = new JCheckBox("Restock?");
- chckbxRestockLogs.setBounds(140, 72, 91, 29);
- frmc.getContentPane().add(chckbxRestockLogs);
- textField = new JTextField();
- textField.setBounds(195, 123, 103, 20);
- textField.setText("0");
- frmc.getContentPane().add(textField);
- textField.setColumns(10);
- textField_1 = new JTextField();
- textField_1.setColumns(10);
- textField_1.setBounds(54, 123, 81, 20);
- textField_1.setText("0");
- frmc.getContentPane().add(textField_1);
- JLabel lblAmount = new JLabel("Amount:");
- lblAmount.setBounds(10, 126, 46, 14);
- frmc.getContentPane().add(lblAmount);
- JLabel lblBuyPrice = new JLabel("Buy price:");
- lblBuyPrice.setBounds(144, 126, 55, 14);
- frmc.getContentPane().add(lblBuyPrice);
- JSeparator separator_1 = new JSeparator();
- separator_1.setBounds(0, 201, 311, 2);
- frmc.getContentPane().add(separator_1);
- JButton btnStart = new JButton("Start");
- btnStart.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- planks_to_make = comboBox.getSelectedItem().toString();
- buy_logs_price = Integer.parseInt(textField.getText());
- buy_logs_amount = Integer.parseInt(textField_1.getText());
- sell_planks_price = Integer.parseInt(textField_3.getText());
- if(planks_to_make == "Oak") {
- plank_id = 1521;
- log_id = 8779;
- }else {
- if(planks_to_make == "Teak") {
- plank_id = 6333;
- log_id = 8781;
- }else {
- if(planks_to_make == "Mahogany") {
- plank_id = 6332;
- log_id = 8783;
- }
- }
- }
- if (chckbxRestockLogs.isSelected()) {
- should_restock = true;
- } else {
- buy_logs_price = 0;
- buy_logs_amount = 0;
- sell_planks_price = 0;
- should_restock = false;
- }
- log("Making: "+planks_to_make+" planks");
- log("Plank id: "+plank_id);
- log("Log id: "+log_id);
- log("Restocking: "+should_restock);
- log("Buying logs for: "+buy_logs_price);
- log("Buying "+buy_logs_amount+" logs");
- log("Selling planks for: "+sell_planks_price+"gp");
- gui_COMPLETE = true;
- }
- });
- btnStart.setBounds(10, 214, 288, 23);
- frmc.getContentPane().add(btnStart);
- JLabel lblLogs = new JLabel("Logs:");
- lblLogs.setForeground(Color.GRAY);
- lblLogs.setBounds(10, 104, 46, 20);
- frmc.getContentPane().add(lblLogs);
- JLabel lblPlanks = new JLabel("Planks:");
- lblPlanks.setForeground(Color.GRAY);
- lblPlanks.setBounds(10, 151, 46, 20);
- frmc.getContentPane().add(lblPlanks);
- JLabel label_1 = new JLabel("Amount:");
- label_1.setBounds(10, 173, 46, 14);
- frmc.getContentPane().add(label_1);
- textField_2 = new JTextField();
- textField_2.setColumns(10);
- textField_2.setBounds(54, 170, 81, 20);
- textField_2.setText("All");
- textField_2.setEditable(false);
- frmc.getContentPane().add(textField_2);
- JLabel lblSellPrice = new JLabel("Sell price:");
- lblSellPrice.setBounds(144, 173, 55, 14);
- frmc.getContentPane().add(lblSellPrice);
- textField_3 = new JTextField();
- textField_3.setColumns(10);
- textField_3.setBounds(195, 170, 103, 20);
- textField_3.setText("0");
- frmc.getContentPane().add(textField_3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment