Jump to content

(Open Source) ELeetHillGiants


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 killing Hill Giants / Banking. *NOTE* This is probably my favorite script I've made.

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.*;
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 = "ELeetHillGiants", gameType = GameType.OS)
public class ELeetHillGiants extends LoopScript {

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

    private final Timer runTimer = new Timer(0);
    private static String status = "Starting";
    private double experienceGained, startExperience = 0;
    private Skill.Skills trainedSkill = Skill.Skills.ATTACK;
    private int bigBonesInBank = 0;
    private int totalKills = 0;
    private int totalBones = 0;
    private double xpPerKill = 144.0;
    private Tile giantArea = new Tile(3122,9842);
    private Tile bankArea = new Tile(3185,3444);
    private String[] pickupItems = {"Giant key", "Big bones",
                                    "Limpwurt root", "Law rune",
                                    "Nature rune", "Death rune",
                                    "Chaos rune", "Fire rune",
                                    "Uncut sapphire", "Uncut emerald",
                                    "Uncut ruby"};

    private ILocalPlayerAPI player()       { return getAPIContext().localPlayer(); }
    private IInventoryAPI   inventory()    { return getAPIContext().inventory();   }
    private IMouseAPI       mouse()        { return getAPIContext().mouse();       }
    private ICameraAPI      camera()       { return getAPIContext().camera();      }
    private ITabsAPI        tabs()         { return getAPIContext().tabs();        }
    private IWebWalkingAPI  webWalking()   { return getAPIContext().webWalking();  }
    private IWalkingAPI     walking()      { return getAPIContext().walking();     }
    private IGroundItemsAPI groundItems()  { return getAPIContext().groundItems(); }
    private INPCsAPI        npcs()         { return getAPIContext().npcs();        }
    private IObjectsAPI     objects()      { return getAPIContext().objects();     }
    private IBankAPI        bank()         { return getAPIContext().bank();        }
    private ISkillsAPI      skills()       { return getAPIContext().skills();      }
    private IEquipmentAPI   equipment()    { return getAPIContext().equipment();   }
    private IWidgetsAPI     widgets()      { return getAPIContext().widgets();     }

    @Override
    protected int loop() {
        handleCalculations();

        eatFood();

        if(inventory().isFull()) {
            rotateCamera();
            moveMouse();
            teleportToVarrock();
            rotateCamera();
            walkToBank();
            takeABreak();
            rotateCamera();
            bankLootItems();
        }

        if(groundContainsLoot()) {
            rotateCamera();
            pickupLoot();
        }

        if(!player().isAttacking() && !player().isMoving() && player().getInteracting() == null) {

            rotateCamera();

            if(player().getLocation().getY() < 9800 && !inventory().isFull()) {
                equipSword();
                walkToHillGiantArea();
            }

            attackNpc();

            moveMouse();
        } else {
            rotateCamera();
            moveMouse();
            Time.sleep(getSleepTime());
        }

        return 3;
    }

    private void takeABreak() {
        status = "Taking a break";

        if(Random.nextInt(1, 10) == 1) {
            Time.sleep(210000);
        }
    }

    private void bankLootItems() {
        status = "Banking loot items";

        GameEntity bank = objects().query().named("Bank booth").results().nearest();
        bank.interact("Bank");
        Time.sleep(getSleepTime());

        for(int i = 0; i < pickupItems.length; i++) {
            bank().depositAll(pickupItems[i]);
            Time.sleep(getShortSleepTime());
        }

        bigBonesInBank = bank().getCount("Big bones");

        //restock food
        String foodType = "Swordfish";
        if(inventory().getCount(foodType) < 4) {
            int amountInInvy = inventory().getCount(foodType);
            bank().withdraw((4 - amountInInvy), foodType);
        }

        //Withdraw Brass key if absent
        Time.sleep(getShortSleepTime());
        if(!inventory().contains("Brass key")) {
           bank().withdraw(1, "Brass key");
        }

        bank().close();
        Time.sleep(getSleepTime());
    }

    private void handleCalculations() {
        if (startExperience == 0) {
            startExperience = skills().get(trainedSkill).getExperience();
        } else {
            experienceGained = skills().get(trainedSkill).getExperience() - startExperience;
        }

        totalKills = (int)(experienceGained / xpPerKill);
    }

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

    public static int getShortSleepTime() {
        int sleepMin = 733;
        int sleepMax = 1123;
        return Random.nextInt(sleepMin, sleepMax);
    }
    public static int getSleepTime() {
        int sleepMin = 3750;
        int sleepMax = 5530;
        return Random.nextInt(sleepMin, sleepMax);
    }
    public static int getAmountToTurnCamera() {
        return Random.nextInt(-322, 363);
    }
    public void attackNpc() {
        if(player().getInteracting() != null || player().isMoving() || player().isAnimating()) {
            return;
        }

        String npc = "Hill Giant";
        NPC entity = npcs().query().named(npc).distance(5.0).reachable().results().nearest();
        status = "Attacking " + npc;

        if(!entity.isAttacking() && !entity.isInCombat()) {
            entity.interact("Attack");
            Time.sleep(getShortSleepTime());
        }
    }

    public void rotateCamera() {
        if(Random.nextInt(1, 25) == 1) {
            int currentYaw = camera().getY();
            camera().setYaw(currentYaw + getAmountToTurnCamera());
        }
    }

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

    public void eatFood() {
        //Check Inventory For Food
        String food = "Swordfish";
        if(!inventory().contains(food)) {
            System.out.println("No food left to eat.");
            walkToBank();
        }

        //Click food if health is < 50%
        int currentHealth = player().getHealthPercent();
        if(currentHealth < 75) {
            status = "Eating Food";

            //Swap to Inventory Tab if it's not open
            if(!tabs().isOpen(ITabsAPI.Tabs.INVENTORY)) {
                tabs().open(ITabsAPI.Tabs.INVENTORY);
            }

            int foodX = inventory().getItem(food).getX();
            int foodY = inventory().getItem(food).getY();
            mouse().click(foodX, foodY);
        }
    }

    public void walkToBank() {
        status = "Walking to bank";

        webWalking().walkTo(getBankTile());
        if(!walking().isRunEnabled() && walking().getRunEnergy() > 50) {
            walking().setRun(true);
        }
        Time.sleep(getShortSleepTime());
    }
    public void walkToHillGiantArea() {
        status = "Walking to Hill Giants";

        webWalking().walkTo(getHillTile());
        if(!walking().isRunEnabled() && walking().getRunEnergy() > 50) {
            walking().setRun(true);
        }
        Time.sleep(getShortSleepTime());
    }

    public Tile getBankTile() {
        int x = bankArea.getX();
        int y = bankArea.getY();
        int randomness = 1;

        int randomX = Random.nextInt(x - randomness, x + randomness);
        int randomY = Random.nextInt(y - randomness, y + randomness);

        return new Tile(randomX, randomY);
    }

    public Tile getHillTile() {
        int x = giantArea.getX();
        int y = giantArea.getY();
        int randomness = 2;

        int randomX = Random.nextInt(x - randomness, x + randomness);
        int randomY = Random.nextInt(y - randomness, y + randomness);

        return new Tile(randomX, randomY);
    }

    public boolean groundContainsLoot() {
        boolean loot = false;

        for(int i = 0; i < pickupItems.length; i++) {
            GroundItem item = groundItems().query().named(pickupItems[i]).distance(1.0).reachable().results().nearest();
            if(item != null || !inventory().isFull()) {
                loot = true;
            }
        }

        return loot;
    }

    public void equipSword() {
        status = "Equipping sword";

        String sword = "Rune scimitar";
        if(equipment().getItem(IEquipmentAPI.Slot.WEAPON).getName().equals(sword)) {
            return;
        }

        ItemWidget item = inventory().getItem(sword);
        if(!equipment().getItem(IEquipmentAPI.Slot.WEAPON).getName().equals(sword)) {
            mouse().click(item);
        }
    }

    public void pickupLoot() {
        status = "Picking up loot";

        for(int i = 0; i < pickupItems.length; i++) {
            GameEntity loot = groundItems().query().named(pickupItems[i]).distance(4.0).reachable().results().nearest();
            if(loot != null) {

                if(loot.getId() == 532) {
                    totalBones++;
                }

                loot.interact("Take");
                Time.sleep(getShortSleepTime());
            }
        }

        rotateCamera();
    }

    public void teleportToVarrock() {
        if(tabs().isOpen(ITabsAPI.Tabs.MAGIC)) {
            tabs().open(ITabsAPI.Tabs.MAGIC);
        }

        WidgetChild varrockButton = widgets().get(218).getChild(21);
        varrockButton.interact("Cast");
    }

    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 + "";
    }

    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame("ELeetHillGiants");
        frame.addLine("[Time running]:", runTimer.toElapsedString());
        frame.addLine("[Status]:", status);
        frame.addLine("", "");

        frame.addLine("[Xp Gained]", experienceGained);
        frame.addLine("[Xp Per Hour]", rsFormat(getHourlyRate((int)experienceGained)));
        frame.addLine("", "");

        frame.addLine("[Kills]:", (int)(experienceGained / xpPerKill));
        frame.addLine("[Kills Per Hour]:", rsFormat(getHourlyRate(totalKills)));
        frame.addLine("", "");

        frame.addLine("[Bones Collected]:", totalBones);
        frame.addLine("[Bones Per Hour]:", rsFormat(getHourlyRate(totalBones)));
        frame.addLine("", "");

        frame.addLine("[Big Bones Banked]:", bigBonesInBank);
        frame.addLine("[Big Bones Evaluation]:", bigBonesInBank * 235);
        frame.draw(g, 0, 130, ctx);
    }
}

 

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...