nebusoku 0 Share Posted December 28, 2023 (edited) Sup everyone, first post here so lemme know if this is the wrong place or anything. So basically I am writing a super basic tinderbox looter, and I feel like there might be a better way to do things. Basically I need to loot a tinderbox, drop it, and continue that until there are 28 on the ground. Then I want to change state to start looting until my inventory is full, then bank yadda yadda. My first instinct was to create a boolean, and just set it to true when there's 28 boxes on the ground. Then use this in my state checks. Is there a better way to do this? Essentially I need PICKUP_BOXES to persist until my inventory is full. I might just be totally blanking, here's my code for reference since my explanation probably sucked. Any other advice is appreciated, I'm sure some of this looks fried lol but I am still figuring out the ins and outs of the api. Thanks guys. Spoiler public class Tinderboxes extends AbstractScript { State state; Area boxArea = new Area(3088, 3254, 3092, 3254, 0); Area bankArea = new Area(3092, 3241, 3095, 3245, 0); GameObject shelf = GameObjects.getTopObjectOnTile(new Tile(3091, 3255, 0)); GameObject door = GameObjects.closest(1535); GroundItem tinderbox; List<GroundItem> tinderboxes; boolean stopLooting = false; @Override public void onStart() { log("started"); } @Override public int onLoop() { tinderboxes = GroundItems.all("Tinderbox"); if (tinderboxes.size() == 28) { stopLooting = true; } if (Walking.getRunEnergy() > 50 && !Walking.isRunEnabled()) { Walking.toggleRun(); } switch (getState()) { case GET_BOXES: if (!Players.getLocal().isMoving()) { shelf.interact("Search"); Sleep.sleepUntil(() -> Inventory.contains("Tinderbox"), 400); } break; case DROP_BOX: if (!Players.getLocal().isAnimating()) { Inventory.drop("Tinderbox"); Sleep.sleepUntil(Inventory::isEmpty, 4000); } break; case PICKUP_BOXES: tinderbox = GroundItems.closest("Tinderbox"); if (!Inventory.isFull() && tinderbox != null) { tinderbox.interact("Take"); sleep(Calculations.random(50, 300)); } break; case WALKING_TO_AREA: if (!boxArea.canReach()) { door.interact("Open"); Sleep.sleepUntil(() -> boxArea.canReach(), 4000); } if (!Players.getLocal().isMoving()) { Walking.walk(boxArea.getRandomTile()); } break; case WALKING_TO_BANK: if (!bankArea.canReach()) { door.interact("Open"); Sleep.sleepUntil(() -> bankArea.canReach(), 4000); } else if (!Players.getLocal().isMoving()) { Walking.walk(bankArea.getRandomTile()); } break; case USE_BANK: if (!Players.getLocal().isMoving()) { NPC banker = NPCs.closest(npc -> npc != null && npc.hasAction("Bank")); banker.interact("Bank"); Sleep.sleepUntil(Bank::isOpen, 4000); } break; case BANKING: Bank.depositAllItems(); Sleep.sleepUntil(() -> !Inventory.isFull(), 4000); if (!Inventory.contains("Tinderbox")) { Sleep.sleepUntil(Bank::close, 4000); stopLooting = false; } break; } return 600; } @Override public void onExit() { } @Override public void onPaint(Graphics graphics) { } private State getState() { if (!Inventory.isFull() && boxArea.contains(Players.getLocal()) && !stopLooting && Inventory.isEmpty()) { return State.GET_BOXES; } else if (!Inventory.isFull() && boxArea.contains(Players.getLocal()) && Inventory.contains("Tinderbox") && !stopLooting) { return State.DROP_BOX; } else if (!Inventory.isFull() && boxArea.contains(Players.getLocal()) && stopLooting) { return State.PICKUP_BOXES; } else if (Inventory.isFull() && !bankArea.contains(Players.getLocal())) { return State.WALKING_TO_BANK; } else if (Inventory.isFull() && bankArea.contains(Players.getLocal()) && !Bank.isOpen()) { return State.USE_BANK; } else if (Inventory.isFull() && Bank.isOpen()) { return State.BANKING; } else if (!Inventory.isFull() && !boxArea.contains(Players.getLocal())) { return State.WALKING_TO_AREA; } return state; } } Edited December 28, 2023 by nebusoku Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now