Jump to content
Theorems

Bolt tip cutter (source)

Recommended Posts

I was trying to bot some diamond bolt tips because I saw they have a nice profit margin but osfletcher doesn't seem to have that, and acerds fletcher seemed to be broken when I used it for that purpose. Change the RAW_MATERIAL variable to a different type of gem to cut that instead, but note that it is case sensitive: 

package boltTips;

import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Message.MessageType;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "theorems", info = "t", logo = "", name = "bolt tips", version = 0.1)
public class Main extends Script {

	private String RAW_MATERIAL = "Diamond";
	private int KEYCODE_SPACE = 32;
	private String FINISHED_MATERIAL = RAW_MATERIAL + " bolt tips";
	private String[] boltTip = { "Chisel", FINISHED_MATERIAL };
	private String[] unfBoltTip = { "Chisel", RAW_MATERIAL };
	private String[] makingBolt = { "Chisel", RAW_MATERIAL, FINISHED_MATERIAL };
	private String lastMsg = "";

	@Override
	public int onLoop() throws InterruptedException {
		if (getDialogues().isPendingContinuation()) {
			// when level up
			getKeyboard().pressKey(KEYCODE_SPACE);
		} else {
			if (getWidgets().isVisible(270, 14, 38)) {
				getKeyboard().pressKey(KEYCODE_SPACE); // this returns void
				sleep(random(500, 1000));
				getMouse().moveOutsideScreen();
				new ConditionalSleep(100000, 5000) {
					@Override
					public boolean condition() throws InterruptedException {
						return !getInventory().contains(RAW_MATERIAL) && !myPlayer().isAnimating();
					}

				}.sleep();
			} else if (getInventory().contains("Chisel") && getInventory().contains(RAW_MATERIAL)) {
				if (getBank().isOpen()) {
					getBank().close();
				} else {
					if (getInventory().isItemSelected()) {
						if (getInventory().getSelectedItemName().equals("Chisel")) {
							if (getInventory().interact("Use", RAW_MATERIAL)) {
								sleep(500);
							}
						} else {
							getInventory().deselectItem();
						}
					} else {
						getInventory().interact("Use", "Chisel");
					}
				}
			} else if (getInventory().contains("Chisel") && getInventory().contains(FINISHED_MATERIAL)
					&& !getInventory().contains(RAW_MATERIAL)) {
				bank();
				if (!getInventory().onlyContains(makingBolt)) {
					getBank().depositAllExcept(makingBolt);
				} else {
					getBank().depositAll(FINISHED_MATERIAL);
				}
			} else if (getInventory().contains("Chisel")) {
				log("only chisel");
				bank();
				getBank().withdrawAll(RAW_MATERIAL);
			} else {
				setup();
			}
		}
		return 500;
	}

	public void setup() {
		if (!getBank().isOpen()) {
			bank();
		} else {
			if (getInventory().isEmpty()) {
				getBank().withdraw("Chisel", 1);
			} else {
				getBank().depositAll();
			}
		}
	}

	public void bank() {
		if (getInventory().isItemSelected()) {
			getInventory().deselectItem();
		}
		if (!getBank().isOpen()) {
			try {
				if (getBank().open()) {
					new ConditionalSleep(2500) {
						@Override
						public boolean condition() throws InterruptedException {
							return getBank().isOpen();
						}

					}.sleep();
				}
			} catch (InterruptedException e) {
				log("Error banking: " + e.getMessage());
				e.printStackTrace();
			}
		}
	}

	@Override
	public void onMessage(Message message) throws java.lang.InterruptedException {
		if (message.getType() == MessageType.GAME) {
			String msg = message.getMessage().toLowerCase();
			String er = "you don't have enough inventory space.";
			if (msg.equals(er) && lastMsg.equals(er)) {
				log("Shutting down for safety");
				stop();
			}
			lastMsg = msg;
		}
	}
}

EDIT: completely rewrote the script except for the msg failsafe. It is now quite robust, I tried to break it in every way I could think of and was unable to do so.

Edited by Theorems
Complete rewrite
Link to comment
Share on other sites

8 minutes ago, Alek said:

Lots of tinfoil and stuff that will break within 2 weeks :/ 

Edit: Not a bad try though

The thing I know that might break after 2 weeks is the widget ID which will probably change when rs updates. Anything else you see which could break easily so I know for the next script I make?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...