Here is the first script I've ever made. I happened to be in Port Phasmatys at the time and had gold ore in my bank lol. All feedback is very appreciated.
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import java.awt.*;
@ScriptManifest(name = "Gold Smelter", author = "Spazbau5", version = 0.1, info = "Smelts gold bars in Port Phasmatys", logo = "")
public class main extends Script {
private final Area FORGE_AREA = new Area(3689, 3481, 3682, 3477);
private final Area BANK_AREA = new Area(3691, 3471, 3686, 3466);
@Override
public void onStart() {
log(getName() + " v" + getVersion() + " has started!");
}
@Override
public void onExit() {
log(getName() + " v" + getVersion() + " has stopped!");
}
@Override
public int onLoop() throws InterruptedException {
switch (getState()) {
case SMELT:
log("Current state: SMELT");
RS2Object forge = getObjects().closest("Furnace");
if (forge != null) {
if (!myPlayer().isAnimating()) {
RS2Widget smeltButton = getWidgets().get(270, 19);
if (smeltButton != null) {
smeltButton.interact("Smelt");
getMouse().moveOutsideScreen();
} else {
sleep(1000);
if (!myPlayer().isAnimating()) {
forge.interact("Smelt");
return random(4000, 5000);
}
}
}
}
break;
case WALK_TO_FORGE:
log("Current state: WALK_TO_FORGE");
getWalking().webWalk(FORGE_AREA);
break;
case WALK_TO_BANK:
log("Current state: WALK_TO_BANK");
getWalking().webWalk(BANK_AREA);
break;
case DEPOSIT:
log("Current state: DEPOSIT");
if (bank.isOpen()) {
bank.depositAll();
} else {
RS2Object bankBooth = getObjects().closest("Bank booth");
if (bankBooth != null && bankBooth.interact("Bank")) {
new ConditionalSleep(10000) {
@Override
public boolean condition() {
return bank.isOpen();
}
}.sleep();
}
}
break;
case WITHDRAW:
log("Current state: WITHDRAW");
if (bank.isOpen()) {
bank.withdrawAll("Gold ore");
} else {
RS2Object bankBooth = getObjects().closest("Bank booth");
if (bankBooth != null && bankBooth.interact("Bank")) {
new ConditionalSleep(10000) {
@Override
public boolean condition() {
return bank.isOpen();
}
}.sleep();
}
}
break;
case IDLE:
log("Current state: IDLE");
}
return random(700, 2300);
}
@Override
public void onPaint(Graphics2D g) {
}
enum State {
WALK_TO_BANK, DEPOSIT, WITHDRAW, WALK_TO_FORGE, SMELT, IDLE
}
private State getState() {
if (!getInventory().contains("Gold ore")) {
if (getInventory().isEmpty()) {
log("Entering state: WITHDRAW");
return State.WITHDRAW;
} else {
log("Entering state: DEPOSIT");
return State.DEPOSIT;
}
}
if (getInventory().contains("Gold ore")) {
if (!FORGE_AREA.contains(myPlayer())) {
log("Entering state: WALK_TO_FORGE");
return State.WALK_TO_FORGE;
} else {
log("Entering state: SMELT");
return State.SMELT;
}
} else if (getInventory().contains("Gold bar")) {
if (!BANK_AREA.contains(myPlayer())) {
log("Entering state: WALK_TO_BANK");
return State.WALK_TO_BANK;
} else {
log("Entering state: DEPOSIT");
return State.DEPOSIT;
}
}
log("Entering state: IDLE");
return State.IDLE;
}
}