Saw a post by @faintdrugs and decided to make something because I had a moment.
Don't know if anything's wrong with it, if anyone sees a mistake feel free to call me out.
Some Example Code:
import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.PolygonArea;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
/**
* Created by ~Anon on 31/03/2015.
*/
@ScriptManifest(author = "~Anon", name = "Ash Picker", version = 0.1, info = "Picks Up And Banks Ashes!", logo = "")
public class Ashes extends Script{
final PolygonArea ZONE = new PolygonArea(/*tiles boardering area*/);
String lastLoggedStatus = " ";
String Status = " ";
private enum States{
PICK, BANK;
}
@Override
public void onStart() throws InterruptedException {
log("Welcome To "+getAuthor()+"'s Ash Picker!");
if(!ZONE.contains(myPlayer())){
log("Please Start in ZONE!");
stop(false);
}
}
@Override
public int onLoop() throws InterruptedException {
printStatus();
switch (getState()){
case BANK:
Status = "Banking.";
doBanking();
break;
case PICK:
Status = "Picking.";
doPicking();
break;
}
return random(250, 500);
}
private States getState(){
if(inventory.isFull()){
return States.BANK;
}else{
return States.PICK;
}
}
private void doBanking() throws InterruptedException {
if(!bank.isOpen()){
Status = "Banking: Opening Bank.";
NPC banker = npcs.closest("Banker");
if(banker != null) {
if (banker.isOnScreen()) {
Status = "Banking: Interacting Banker.";
banker.interact("Bank");
sleep(random(500, 900));
} else {
Status = "Banking: Locating Banker.";
if (banker.getPosition().distance(myPosition()) > 6) {
localWalker.walk(banker);
} else {
camera.toEntity(banker);
}
}
}
}else{
Status = "Banking: Depositing.";
bank.depositAll();
sleep(random(250, 450));
}
}
private void doPicking() throws InterruptedException {
if(bank.isOpen()){
Status = "Picking: Closing Bank.";
bank.close();
}else{
GroundItem ashes = groundItems.closest(new Filter<GroundItem>() {
@Override
public boolean match(GroundItem groundItem) {
return groundItem != null && groundItem.getName().equals("Ashes") && ZONE.contains(groundItem);
}
});
if(ashes != null){
if(ashes.isOnScreen()){
Status = "Picking: Picking Up Ashes.";
ashes.interact("Take");
sleep(random(500, 900));
}else{
Status = "Picking: Locating Ashes.";
if(ashes.getPosition().distance(myPosition())> 6){
localWalker.walk(ashes);
}else{
camera.toEntity(ashes);
}
}
}
}
}
private void printStatus(){
if(lastLoggedStatus != Status){
log("Current Status: " + Status);
lastLoggedStatus = Status;
}
}
}
Note: I'm used to coding everything in the main loop and did my best to convert the code to a more manageable style for newer people