Jump to content

smile

Recommended Posts

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

//Script Manifest stuff for your script selector
@ScriptManifest(name = "sCowKiller", gameType = GameType.OS)
public class main extends LoopScript {
    //instantiate variable to be used later.
    private Player local_Player;
    private long startTime;
    private State state;
    private String playerState;
    private int strengthLevel;
    private int percentTNL;
    private NPC cowNPC;

    @Override
    public boolean onStart(String... strings) {
        //when the script starts, startTime is set equal to the current millisecond which is used for the runtime later on.
        startTime = System.currentTimeMillis();
        System.out.println("Starting sCowKiller!");
        return true;
    }
    @Override
    protected void onPause() {
        playerState = "Script is paused";
        getAPIContext().mouse().moveOffScreen();
    }
    //An enum of all the States
    private enum State {
        QUERYING,
        FIGHTING,
        ENABLING_RUN
    }
    // A getter for the player's state and defining what causes the state to change
    private State getPlayerState() {

        if (getAPIContext().client().isLoggedIn() && getAPIContext().localPlayer().get() != null) {
            local_Player = getAPIContext().localPlayer().get();
            if (local_Player.getAnimation() != -1) {
                state = State.FIGHTING;
            } else if (local_Player.getAnimation() == -1) {
                state = State.QUERYING;
            } else if (!getAPIContext().walking().isRunEnabled()) {
                state = State.ENABLING_RUN;
            }
        }
        return state;
    }
    private NPC getCowNPC() {
        return getAPIContext().npcs().query()
                //what we're querying for
                .nameMatches("Cow")
                .notInCombat()
                .animation(-1)
                .reachable()
                .results()
                .nearest();
    }
    private void attack() {
        cowNPC.click();
        getAPIContext().mouse().moveOffScreen();
    }
    // The actual loop method
    @Override
    protected int loop() {
        if (!getAPIContext().client().isLoggedIn()) {
            return 500;
        }
        switch (getPlayerState()) { // switch case for setting player state
            case FIGHTING:
                playerState = "Fighting";
                break;
            case QUERYING:
                playerState = "Querying";
                break;
            case ENABLING_RUN:
                playerState = "Enabling run";
            default:
                playerState = "ERROR";
                break;
        }
        //shit for determining skill XP/Time to level/etc
        strengthLevel = getAPIContext().skills().strength().getCurrentLevel();
        percentTNL = getAPIContext().skills().strength().getPercentToNextLevel();

        if (getAPIContext().localPlayer().getInteracting() == null) {
            cowNPC = getCowNPC();
            // if the local player is not interacting
            if (cowNPC != null && !cowNPC.isDead()) { //if the cow npc query is not dead

                attack(); // do the attack method
                if (local_Player.getInteracting() != null) { // if our player is interacting
                    Time.sleep(6000, () -> cowNPC.isDead()); // sleep until cow npc is dead
                }
                if (local_Player.isMoving() || cowNPC.isInteractingWithMe() || local_Player.getInteracting() == null) {
                    if (!getAPIContext().walking().isRunEnabled()) {
                        if (getAPIContext().walking().getRunEnergy() >= Random.nextInt(55,100)) {
                            getAPIContext().walking().setRun(true);
                        }
                    } else if (getAPIContext().walking().isRunEnabled()) {
                        if (getAPIContext().walking().getRunEnergy() <= Random.nextInt(10,15)) {
                            getAPIContext().walking().setRun(false);
                        }
                    }
                }
            }
        }
        return 200;
    }
    // paint shit.
    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        if (!getAPIContext().client().isLoggedIn()) {
            Time.sleep(15_000, () -> getAPIContext().client().isLoggedIn());
        }
        if (getAPIContext().client().isLoggedIn()) {
            PaintFrame frame = new PaintFrame();
            frame.setTitle("sCowKiller");
            frame.addLine("Runtime: ", Time.getFormattedRuntime(startTime)); // we use startTime here from the very beginning
            frame.addLine("State: ", playerState); //we get whatever the player's state is equal to and print it onto the paint.
            frame.addLine("", "");
            frame.addLine("Current Strength level: ", strengthLevel);
            frame.addLine("% to next level", percentTNL);
            frame.draw(g, 0, 90, ctx); //drawing the actual frame.
            g.setColor(new Color(208, 189, 155, 255));
            g.fillRect(11, 468, 120, 15); //name covering stuff, honestly might remove it cuz kinda pointless? Dunno
        }
    }
}
Edited by smile
Rewrite of script v2 +making it look nicer + cleaning up stuff
  • Thanks 2
  • Haha 1
  • Sad 3
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 months later...
  • 1 month later...

copy paste it into a projekt (there is a video how to setup intelliJ for it) and then just click on build tab and click on build. After this you have to make a "Script" folder in the epicbot folder with the settings and copy paste the compiled file/files into the script folder.

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