Jump to content

(Open Source) ELeetWoodcutter


LeetyPoo

Recommended Posts

Hello everyone. I am releasing all of the custom scripts that I've made. They are probably not super great but they worked for me just messing around. Might be able to find some useful stuff I suppose. I am a java game developer and just took these on for fun. I don't really play anymore though so I thought I'd release it all for everyone else to hopefully get some use out of. If you want a custom script feel free to message me. I don't mind helping out where I can. This is just a basic script for Woodcutting/banking. Hope you can find it useful. *NOTE* I don't believe I ever got the random event to work.

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.GameEntity;
import com.epicbot.api.shared.entity.NPC;
import com.epicbot.api.shared.entity.WidgetChild;
import com.epicbot.api.shared.methods.IInventoryAPI;
import com.epicbot.api.shared.model.Skill;
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.Random;
import com.epicbot.api.shared.util.paint.frame.PaintFrame;
import com.epicbot.api.shared.util.time.Time;

import com.epicbot.api.shared.methods.*;
import com.epicbot.api.shared.util.time.Timer;

import java.awt.*;

@ScriptManifest(name = "ELeetWoodcutter", gameType = GameType.OS)
public class eLeetWoodcutter extends LoopScript {

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

    private int logsDropped = 0;
    private int logsBanked = 0;
    private double xpGained = 0.0;
    private static String status = "STARTING";
    private final Timer runTimer = new Timer(0);
    private int logsInBank;

    private Tile bankArea = new Tile(2569,2864);
    private Tile treeArea = new Tile(2475,2888);
    private boolean scriptBanksLogs = true;
    private String logType = "Yew logs";
    private String treeType = "Yew";

    private double experienceGained, startExperience = 0;
    private double xpPerLog = 175.0;
    private int logsChopped = 0;

    public IInventoryAPI   inventory() { return getAPIContext().inventory(); }
    public IWidgetsAPI     widgets()   { return getAPIContext().widgets(); }
    public IMouseAPI       mouse()     { return getAPIContext().mouse(); }
    public ILocalPlayerAPI player()  { return getAPIContext().localPlayer(); }

    @Override
    protected int loop() {

        handleCalculations();
        handleRandomEvent();

        moveMouse();
        Time.sleep(getShortSleepTime());

        if(!player().isAnimating()) {
            if (inventory().isFull()) {

                if(!scriptBanksLogs) {
                    dropLogs();
                } else {
                    walkToBank();
                    bankLogs();
                }

                moveMouse();
            }

            if(!APIContext.get().inventory().contains(logType)) {
                walkToTreeLocation();
            }

            clickTree();
            moveMouse();
            Time.sleep(getShortSleepTime());
            moveMouse();
            rotateCamera();

        }

        return 60;
    }

    public static int getSleepTime() {
        int sleepMin = 1500;
        int sleepMax = 3000;
        return Random.nextInt(sleepMin, sleepMax);
    }
    public static int getShortSleepTime() {
        int sleepMin = 750;
        int sleepMax = 1799;
        return Random.nextInt(sleepMin, sleepMax);
    }
    public static int getAmountToTurnCamera() {
        return Random.nextInt(-224, 779);
    }

    public void bankLogs() {
        status = "Banking Logs";

        int amountInInventory = APIContext.get().inventory().getCount(logType);
        rotateCamera();
        GameEntity bankBooth = APIContext.get().objects().query().named("Bank booth").results().nearest();

        bankBooth.interact("Bank");

        Time.sleep(getShortSleepTime());

        clickBankAll();
        logsInBank = APIContext.get().bank().getCount(logType);
        APIContext.get().bank().close();

        logsBanked += amountInInventory;
    }

    public void dropLogs() {
        status = "Dropping Logs";
        int amount = inventory().getCount(logType);
        logsDropped += amount;
        inventory().dropAll(logType);
    }

    public void clickTree() {
        status = "Chopping Logs";

        rotateCamera();

        GameEntity entity = APIContext.get().objects().query().named(treeType).distance(9.0).results().nearest();

        //Checks to see if the entity to click is null. If its valid entity != null
        if(entity.isValid()) {
            entity.interact("Chop down");
        } else {
            System.out.println("Couldn't find a tree to cut.");
        }

        moveMouse();

        if (!widgets().isInterfaceOpen()) {
            xpGained += 67.5;
        } else {
            widgets().closeInterface();
            rotateCamera();
        }
    }

    public void moveMouse() {
        if(Random.nextInt(1, 35) < 3) {
            APIContext.get().mouse().moveRandomly();
        }
    }

    public void rotateCamera() {
        if(Random.nextInt(1, 20) < 3) {
            return;
        }

        int currentYaw = APIContext.get().camera().getY();
        APIContext.get().camera().setYaw(currentYaw + getAmountToTurnCamera());
    }

    public void clickBankAll() {
        status = "Clicking Bank all";

        APIContext.get().bank().open();
        Time.sleep(getShortSleepTime());

        WidgetChild bankAllButton = APIContext.get().widgets().get(12).getChild(42);
        mouse().click(bankAllButton);
    }

    public Tile getTreeAreaTile() {
        int areaX = treeArea.getX();
        int areaY = treeArea.getY();
        int randomness = 2;

        int randomX = Random.nextInt(areaX - randomness, areaX + randomness);
        int randomY = Random.nextInt(areaY - randomness, areaY + randomness);

        return new Tile(randomX, randomY);
    }

    public void toggleRunEnergy() {
        if(APIContext.get().walking().getRunEnergy() > 50 && !APIContext.get().walking().isRunEnabled()) {
            APIContext.get().walking().setRun(true);
        }
    }

    public void walkToBank() {
        status = "Walking to Bank";
        toggleRunEnergy();
        APIContext.get().webWalking().walkTo(bankArea);
        Time.sleep(getSleepTime());
    }

    public void walkToTreeLocation() {
        status = "Walking to Tree Location";
        toggleRunEnergy();
        APIContext.get().webWalking().walkTo(getTreeAreaTile());
        Time.sleep(getShortSleepTime());
    }

    private void handleCalculations() {
        if (startExperience == 0) {
            startExperience = getAPIContext().skills().get(Skill.Skills.WOODCUTTING).getExperience();
        } else {
            experienceGained = getAPIContext().skills().get(Skill.Skills.WOODCUTTING).getExperience() - startExperience;
        }

        logsChopped = (int)(experienceGained / xpPerLog);
    }

    public boolean handleRandomEvent() {
        NPC randomNpc = APIContext.get().npcs().query().interactingWithMe().results().nearest();

        if(randomNpc == null || !randomNpc.getInteracting().hasAction("Dismiss")) {
            return false;
        }

        System.out.println("[Logging Handle Random Event Npc]" +randomNpc.getName());

        if(randomNpc.isInteractingWithMe()) {

            status = "Handling Random Event Npc";
            System.out.println("[Logging Handle Random Event Npc]" +randomNpc.getName());

            if(randomNpc.getName().equals("Genie") && !APIContext.get().inventory().isFull()) {
                randomNpc.interact("Talk-to");
                return true;
            }

            Time.sleep(getSleepTime());

            if(randomNpc.getInteracting().hasAction("Dismiss")) {
                randomNpc.interact("Dismiss");
                return true;
            }
        }
        return false;
    }

    private String rsFormat(Integer number) {
        String[] suffix = new String[]{"K", "M", "B", "T"};
        int size = (number != 0) ? (int) Math.log10(number) : 0;
        if (size >= 3) {
            while (size % 3 != 0) {
                size = size - 1;
            }
        }
        return (size >= 3) ? +(Math.round((number / Math.pow(10, size)) * 10) / 10d)
                + suffix[(size / 3) - 1]
                : +number + "";
    }

    private int getHourlyRate(int i) {
        return (int) (i / (runTimer.getElapsed() / 3600000.0D));
    }

    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame scriptDetails = new PaintFrame("ELeetWoodcutter");
        scriptDetails.addLine("[Timer]:", runTimer.toElapsedString());
        scriptDetails.addLine("[Status]:", status);

        scriptDetails.addLine("", "");

        scriptDetails.addLine("[Logs Per Hour]:", getHourlyRate(logsChopped));
        scriptDetails.addLine("[Xp Per Hour]:", rsFormat(getHourlyRate((int)experienceGained)));

        scriptDetails.addLine("", "");

        scriptDetails.addLine("[Xp Gained]:", experienceGained);
        scriptDetails.addLine("[Logs Chopped]:", logsChopped);
        if(!scriptBanksLogs) {
            scriptDetails.addLine("[Logs Dropped]:", logsDropped);
        } else {
            scriptDetails.addLine("[Logs Banked]:", logsBanked);
        }
        scriptDetails.addLine("[Logs In Bank]:", logsInBank);
        scriptDetails.addLine("", "");
        scriptDetails.addLine("[Total Logs Evaluation]:", (logsInBank * 289) + "gp");

        scriptDetails.draw(g, 0, 0, ctx);
    }
}

 

Edited by LeetyPoo
Link to comment
Share on other sites

  • 1 month later...

Hey, amazing work! However, whenever I try to run the script, I get the following error: 

[04:13:52.862][ERROR][ScriptTaskContainer][485] Error during executing task: 'com.epicbot.api.shared.script.LoopScript$LoopTask'
java.lang.NullPointerException
	at ELeetWoodcutter.clickTree(ELeetWoodcutter.java:134)
	at ELeetWoodcutter.loop(ELeetWoodcutter.java:76)
	at com.epicbot.api.shared.script.LoopScript$LoopTask.run(qfa:136)
	at com.epicbot.api.shared.script.ScriptTaskContainer.runTask(qha:23)
	at com.epicbot.api.shared.script.ScriptTaskContainer.run(qha:20)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Any idea what might be the cause? Much appriciate it! 

 *********************** SOLVED IT ************************************************************

All I had to do was to change the code in line 134 to: 

if(entity != null && entity.isValid()) {
    entity.interact("Chop down");
} else {
    System.out.println("Couldn't find a tree to cut.");
}

Your code tried to access or invoke a method on an object that was null.  

!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!! 

Change the type of the tree to ---> "Yew tree" instead of just "Yew"  

Other than that it works flawlessly, big + for the camera rotations and random clicks i suspect lower detection rates thanks to that feature! 

Hope it helps someone! 

 

 

Edited by olexander
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.

×
×
  • Create New...