Jump to content

xkalibur13

Members
  • Posts

    3
  • Joined

  • Last visited

  • Days Won

    1

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

xkalibur13's Achievements

Bronze Member

Bronze Member (1/10)

  1. This is an improvement to Zynava's open source project at this link I hope that this code helps people who are somewhat new to java and the EB API understand an easy way to complete tasks in succession, while practicing good coding style and readability import com.epicbot.api.shared.APIContext; import com.epicbot.api.shared.GameType; import com.epicbot.api.shared.entity.GroundItem; import com.epicbot.api.shared.methods.*; import com.epicbot.api.shared.model.Area; import com.epicbot.api.shared.script.LoopScript; import com.epicbot.api.shared.script.ScriptManifest; import com.epicbot.api.shared.util.paint.frame.PaintFrame; import com.epicbot.api.shared.util.time.Time; import com.epicbot.api.shared.webwalking.model.RSBank; import java.awt.Graphics2D; import java.util.concurrent.ThreadLocalRandom; @ScriptManifest(name = "Cowhide Collector FSM", gameType = GameType.OS) public class TestScript extends LoopScript { /** CONSTANTS **/ private static final Area COW_AREA = new Area(3244, 3295, 3262, 3277); private static final RSBank BANK = RSBank.LUMBRIDGE_TOP; /** VARIABLES **/ private Status status = Status.LOGGING_IN; /** UTIL **/ private int random(int min, int max) {return ThreadLocalRandom.current().nextInt(min, max + 1);} public IInventoryAPI myInventory() {return getAPIContext().inventory();} public ILocalPlayerAPI myPlayer() {return getAPIContext().localPlayer();} public IGroundItemsAPI groundItems() {return getAPIContext().groundItems();} public IWebWalkingAPI webWalking() {return getAPIContext().webWalking();} public ICalculationsAPI calculations() {return getAPIContext().calculations();} public IWalkingAPI walking() {return getAPIContext().walking();} public IBankAPI bank() {return getAPIContext().bank();} public ICameraAPI camera() {return getAPIContext().camera();} /** SCRIPT OBJECTS **/ private enum Status { LOGGING_IN("Logging in"), WALKING_TO_COW_FIELD("Walking to cow field"), GATHERING_COW_HIDES("Gathering cow hides"), WALKING_TO_BANK("Walking to bank"), OPENING_BANK("Opening bank"), DEPOSITING_INVENTORY("Depositing inventory"), CLOSING_BANK("Closing bank"); private final String msg; Status(String msg) { this.msg = msg; } @Override public String toString() { return this.msg; } } /** SCRIPT METHODS **/ @Override public boolean onStart(String... strings) { System.out.println("Starting " + getManifest().name()); return true; } @Override protected void onPaint(Graphics2D g, APIContext ctx) { PaintFrame frame = new PaintFrame(getManifest().name()); frame.addLine("Status", status.toString()); frame.draw(g, 0, 170, ctx); } @Override protected int loop() { doTasks(); return random(50,100); } /** IMPLEMENTATION **/ private void doTasks() { switch (status) { case LOGGING_IN: if (getAPIContext().client().isLoggedIn()) status = myInventory().isFull() ? Status.WALKING_TO_BANK : Status.WALKING_TO_COW_FIELD; break; case WALKING_TO_COW_FIELD: doWalkToCowField(); break; case GATHERING_COW_HIDES: doGatherCowHides(); break; case WALKING_TO_BANK: doWalkToBank(); break; case OPENING_BANK: doOpenBank(); break; case DEPOSITING_INVENTORY: doDepositInventory(); break; case CLOSING_BANK: doCloseBank(); break; default: break; } } /** * Walks to cow field */ private void doWalkToCowField() { if(COW_AREA.contains(myPlayer().getLocation())) { // WALKING_TO_COW_FIELD -> GATHERING_COW_HIDES status = Status.GATHERING_COW_HIDES; return; } webWalking().walkTo(COW_AREA.getRandomTile()); } /** * Gathers cow hides, potentially enabling run energy */ private void doGatherCowHides() { if(myInventory().isFull()) { // GATHERING_COW_HIDES -> WALKING_TO_BANK status = Status.WALKING_TO_BANK; return; } if (myPlayer().isMoving()) return; GroundItem cowHide = groundItems().query().named("Cowhide").results().nearest(); if (cowHide == null) return; if (!cowHide.isVisible()) camera().turnTo(cowHide.getLocation()); if (!walking().isRunEnabled() && walking().getRunEnergy() > 10) walking().setRun(true); cowHide.interact("Take"); Time.sleep(random(600,1800)); } /** * Walks to bank */ private void doWalkToBank() { if(calculations().distanceBetween(BANK.getTile(), myPlayer().getLocation()) < 3) { // WALKING_TO_BANK -> OPENING_BANK status = Status.OPENING_BANK; return; } webWalking().walkToBank(BANK); } /** * Opens bank */ private void doOpenBank() { if(bank().isOpen()) { // OPENING_BANK -> DEPOSITING_INVENTORY status = Status.DEPOSITING_INVENTORY; return; } bank().open(); } /** * Deposits inventory */ private void doDepositInventory() { if (myInventory().isEmpty()) { // DEPOSITING_INVENTORY -> CLOSING_BANK status = Status.CLOSING_BANK; return; } bank().depositInventory(); } /** * Closes bank */ private void doCloseBank() { if (!bank().isOpen()) { // CLOSING_BANK -> WALKING_TO_COW_FIELD (completes the cycle) status = Status.WALKING_TO_COW_FIELD; return; } bank().close(); } } There is one instance of Time.sleep(int a) to reduce the number of times the cowhide is clicked. Please drop your suggestions for improvements as though I'm familiar with java I am also somewhat new to using the EB API 🙂
  2. I've tested this and it works private void dealWithRandomEvent() { NPC npc = npcs().query().results().nearest(); if (npc == null) return; if (!npc.hasAction("Dismiss")) return; mouse().moveRandomly(random(500,4000)); npc.interact("Dismiss"); System.out.println(npc.getName() + " dismissed"); mouse().moveOffScreen(); }
  3. I haven't been able to test this, nor have I looked into handling randomevents until now. but this would be my first stab at it: private boolean handleRandomEvent() { LocatableEntityQueryResult<NPC> results = getAPIContext().npcs().query().actions("Dismiss").results(); if(results.isEmpty()) return false; try { results.nearest().interact("Dismiss"); } catch (Exception e) { // print message for debugging purposes getLogger().debug("Caught error: " + e.getMessage()); } return true; } } lmk if you make any progress
×
×
  • Create New...