Jump to content

[Version 1.0.0] [Open Source] Edgeville Red Spider Egg Collector by Zynava


Zynava
 Share

Recommended Posts

Second script release! 🥳🎉Woo! Do you like my free scripts? Please show your support and Buy Me a Coffee!  

TIPS FOR RUNNING THIS SCRIPT:
- Adjust your camera for top-down view.
- Disable roofs
- Zoom your camera out as far as possible
- Start with an empty inventory (although the bot will deposit for you if you have anything in your inventory that is NOT a red spider egg).
- If you have a weak defense and don't regen HP quicker than the red spiders can hit you for, do not wear what you can't lose. ☠️This bot will not save you from death. ☠️

- Does this bot support pouches and glory teleporting?
Not at this time. This is Version 1 of this bot. Call it the beta. Future versions will have support for these, and there is currently no ETA for the next version as this was just released. As of 10/31/2021, this version of the script was finished & production of Version 2 is not in progress.


CODE:
This script will run from anywhere. It will take you to Edgeville, it will bank when needed, and it will take you to the Red Spiders' Egg spot in the Edgeville dungeon. It will collect until your inventory is full (28), bank, rinse, and repeat. 

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.GroundItem;
import com.epicbot.api.shared.entity.SceneObject;
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 java.awt.*;

@ScriptManifest(name = "Edgevville Red Spider Egg Collector by Zynava", gameType = GameType.OS)
public class RedSpiderEggCollector extends LoopScript {

    /***START VARIABLES***/
    public boolean botIsNotInDungeon = true;
    IWebWalkingAPI webWalking() { return getAPIContext().webWalking(); }
    ILocalPlayerAPI localPosition() { return getAPIContext().localPlayer(); }
    IInventoryAPI myInventory() { return getAPIContext().inventory(); }
    IBankAPI myBank() { return getAPIContext().bank(); }
    IObjectsAPI localObject() { return getAPIContext().objects(); }
    IGroundItemsAPI groundItem() { return getAPIContext().groundItems(); }
    Area edgeBank = new Area(3092, 3493, 3094, 3491);
    Area dungeonEntrance = new Area(3093, 3471, 3095, 3469);
    Area redSpiderEggArea = new Area(3118, 9949, 3127, 9956); // BLOCKER
    /***END VARIABLES***/

    public boolean inventoryIsEmpty() {
        return myInventory().isEmpty();
    }

    public boolean needsToGoToBank() {
        return myInventory().isFull() || (!myInventory().onlyContains("Red spiders' eggs") && !edgeBank.contains(localPosition().get()));

    }

    public boolean bankIsOpen() {
        return myBank().isOpen();
    }

    public boolean botNotAtDungeonEntrance() {
        return !dungeonEntrance.contains(localPosition().get());
    }

    public boolean botIsAtDungeonEntrance() {
        return dungeonEntrance.contains(localPosition().get());
    }

    public void goToBank() {
        if(!edgeBank.contains(localPosition().get())) {
            System.out.println("Walking to bank.");
            webWalking().walkTo(edgeBank.getRandomTile());
            myBank().open();
        }
    }


    public SceneObject getEntranceDoor() {
       return localObject().query().nameMatches("Trapdoor").actions("Open").results().nearest();
    }
    public SceneObject getEntranceLadder() {
        return localObject().query().nameMatches("Trapdoor").actions("Climb-down").results().nearest();
    }
    public void goToDungeonEntrance() {
        webWalking().walkTo(dungeonEntrance.getRandomTile());
    }
    public void goToRedSpiderEggArea() {
        webWalking().walkTo(redSpiderEggArea.getRandomTile());
    }
    public GroundItem getNearestEggs() {
        return groundItem().query().nameMatches("Red spiders' eggs").results().nearest();
    }



    @Override
    public boolean onStart(String... strings) {
        return true;
    }

    @Override
    protected int loop() {
        if(needsToGoToBank()) {
            goToBank();
        }

        if(bankIsOpen() && !inventoryIsEmpty()) {
            myBank().depositInventory();
        } else {
            myBank().close();
        }

        if(!myInventory().isFull() && botNotAtDungeonEntrance() && botIsNotInDungeon) {
            goToDungeonEntrance();
        }

        if(botIsAtDungeonEntrance() && !myInventory().isFull()) {
            SceneObject trapdoorClosed;
            SceneObject trapdoorOpen;
            trapdoorClosed = getEntranceDoor();
            trapdoorOpen = getEntranceLadder();

            if(trapdoorClosed != null) {
                trapdoorClosed.interact("Open");
                return 100;
            }

            if(trapdoorOpen != null) {
                trapdoorOpen.interact("Climb-down");
                botIsNotInDungeon = false;
                return 100;
            }
        }

        if(!myInventory().isFull() && botIsNotInDungeon == false && !redSpiderEggArea.contains(localPosition().get())) {
            goToRedSpiderEggArea();
            return 100;
        }

        if(redSpiderEggArea.contains(localPosition().get())) {
            if(myInventory().getCount("Red spiders' eggs") < 28) {
                GroundItem eggs = getNearestEggs();
                System.out.println(eggs);
                if(eggs != null) {
                    eggs.interact("Take");
                    Time.sleep(1000);
                }
                return 100;
            }
        }

        if(myInventory().getCount("Red spiders' eggs") == 28) {
            botIsNotInDungeon = true;
        }

        return 100;
    }

    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame("Red Spider Egg Collector by Zynava");
        frame.draw(g, 0, 170, ctx);
    }
}

 

Edited by Zynava
  • Like 2
Link to comment
Share on other sites

  • Developers

Very nice release. I've been meaning to get more code examples out, so I thought I'd show my general coding style. 

 

The primary things are

  1. Simplicity - Ensuring that the logical flow controls behavior where possible.
    1. Ex. when moving. You don't need to do anything if you're moving. So if you have a check at the top that sleeps if you're moving, you can perform an action and then the method up top will prevent additional unnecessary interactions.
  2. One action per loop - for every loop, do one thing or do nothing.
    1. If you try and do multiple things per loop, you can introduce more bugs due to flow, an interaction failure, etc. You'll see I heavily use if, if else, and else statements. They're no state the script is in where it will ever do multiple things in a loop.

 

Quote
import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.GroundItem;
import com.epicbot.api.shared.model.Tile;
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.*;

@ScriptManifest(name = "Red Spider Eggs", gameType = GameType.OS)
public class RedSpiderEggCollector extends LoopScript {

    private String status = "Starting";
    private final Tile EGGS_POS = new Tile(3121,9954,0);

    @Override
    public boolean onStart(String... strings) {
        return true;
    }

    @Override
    protected int loop() {
        // if inventory is full, bank
        if(getAPIContext().inventory().isFull()) {
            setStatus("Banking");
            bank();
        // if we're moving, we don't need to be doing anything else!
        } else if(getAPIContext().localPlayer().isMoving()) {
            Time.sleep(1000, () -> !getAPIContext().localPlayer().isMoving());
        // if we're out of run and we have some to use, enable run
        } else if(!getAPIContext().walking().isRunEnabled() && getAPIContext().walking().getRunEnergy() > 15){
            if(getAPIContext().walking().setRun(true)){
                Time.sleep(2000, () -> getAPIContext().walking().isRunEnabled());
            }
        } else {
            GroundItem eggs = getAPIContext().groundItems().query().named("Red spiders' eggs").reachable().results().nearest();
            if(eggs != null){
                setStatus("Collecting");
                if (eggs.isVisible()) {
                    if (eggs.interact("Take")){
                        Time.sleep(1000, () -> getAPIContext().localPlayer().isMoving());
                    }
                } else {
                    getAPIContext().walking().walkTo(eggs);
                }
            } else {
                // if we're too far away, reset back
                if(EGGS_POS.distanceTo(getAPIContext()) > 10) {
                    setStatus("Walking back");
                    getAPIContext().webWalking().walkTo(EGGS_POS);
                } else {
                    //no eggs and we're near the spot - need to wait for spawn
                    setStatus("Waiting");
                    return 2000;
                }
            }
        }
        return 500;
    }

    private void setStatus(String status){
        this.status = status;
    }

    private void bank() {
        if(getAPIContext().bank().isOpen()){
            if(getAPIContext().bank().depositInventory()){
                Time.sleep(2000, () -> getAPIContext().inventory().isEmpty());
            }
        } else {
            if(getAPIContext().bank().isVisible()){
                if(getAPIContext().bank().open()){
                    Time.sleep(5000, () -> getAPIContext().bank().isOpen());
                }
            } else {
               getAPIContext().webWalking().walkTo(RSBank.EDGEVILLE.getTile());
            }
        }
    }

    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame("Red Spider Eggs");
        frame.addLine("Status", status);
        frame.draw(g, 0, 170, ctx);
    }
}

Hope this helps some of the new scripters and lurkers 🙂

  • Like 1
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.

 Share

×
×
  • Create New...