Jump to content

First "working" script.


chrismac1991

Recommended Posts

so here it is. all it does is cut basic trees and drop after a full inventory of logs.

im not sure how to proceed from here yet but im gonna get back at it tomrrow night.

ideally i think id like to add an area so it stays within certain coordinates and making it be able to cut oaks aswell as regular trees at 15+ woodcutting.

phew. anyway there it is maybe somebody would like to point me in the right direction from here that would be splendid and very much appreciated!

am i off to a bad or worse start for just learning how to do all this stuff?

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "Chris", info = "Chops and Drops Trees Lumbridge", name = "Level3TreeKiller", version = 0.1, logo = "")
public class FuckYouTrees extends Script {

    @Override
    public void onStart() {
        log("Kill All The Trees!");
        log("Fuck The World");
        log("Dont Get Banned Get Bank");
    }

    private enum State {
        CHOPPING_LOGS, DROPPING_LOGS, SEARCH_FOR_TREE, WAIT
    };

    private State getState() {
        Entity tree = objects.closest("Tree");
        if (inventory.isFull())
            return State.DROPPING_LOGS;

        if (tree != null)
            if (!myPlayer().isAnimating())
                return State.CHOPPING_LOGS; // all good as far i know

        if (myPlayer().isAnimating())
            return State.WAIT;

        else
            return State.SEARCH_FOR_TREE;

    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case DROPPING_LOGS:
            log("Dropping Shit");
            inventory.isFull();
            inventory.deselectItem();
                log("is inventory full?");
                inventory.dropAll();
                log("decided to drop");
                break;
            
        case CHOPPING_LOGS: // time to rest
            log("Work Work");
            Entity tree = objects.closest("Tree");
            inventory.deselectItem();
            if (tree != null) {
                log("is tree there?");
                if (tree.isVisible()) {
                    log("is tree visible?");
                    if (!myPlayer().isAnimating())
                        log("am i already animating?");
                    if (myPlayer().isMoving())
                        log("Am i already moving?");
                        tree.interact("Chop Down");
                    log("actually chopping");
                    sleep (gRandom(500,750));
                    log("sleeping");
                    break;

                }
            }
        case SEARCH_FOR_TREE: // Switches to case temporarily but does nothing
                                // but spam click.
            log("Looking for a new tree");
            Entity newtree = objects.closest("Tree");
            if (newtree != null)
                camera.toEntity(newtree);
            newtree.interact("Chop Down");
            break;

        case WAIT:
            random(1000, 2500);
            log("waiting");
            if (myPlayer().isAnimating())
                break;
        }
        return random(200, 300);

    }

    @Override
    public void onExit() {
        log("Done Already?");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}  

Link to comment
Share on other sites

thanks everyone, okay so heres my newest version lol..it now sort of runs away from the Mugger behind the castle because it was aggressive so yeah no more of that!

 

so my next thing is cutting oaks once skill reaches level 15+

 

could anybody maybe show me how? biggrin.png

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;

import java.awt.*;

@ScriptManifest(author = "Chris", info = "Chops and Drops Trees Lumbridge", name = "Level3TreeKiller", version = 0.1, logo = "")
public class FuckYouTrees extends Script {
    final Area CHOPPING_AREA = new Area(3160, 3225, 3200, 3243);

    @Override
    public void onStart() {
        log("Kill All The Trees!");
        log("Fuck The World"); // /Shit the script says at the beginning
        log("Dont Get Banned Get Bank");
    }

    private enum State {
        CHOPPING_LOGS, DROPPING_LOGS, SEARCH_FOR_TREE, WAIT, RUNNINGAWAY // //"Modes"
                                                                            // my
        // character can
        // be in
    };

    private State getState() {
        NPC npc = npcs.closest("Mugger");
        Entity tree = objects.closest("Tree");
        if (inventory.isFull())
            return State.DROPPING_LOGS;

        if (npc != null)
            return State.RUNNINGAWAY;

        if (tree != null)
            if (!myPlayer().isAnimating()) // how to decide which mode to be
                return State.CHOPPING_LOGS;

        if (myPlayer().isAnimating())
            return State.WAIT;

        else
            return State.SEARCH_FOR_TREE;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case DROPPING_LOGS:
            log("Dropping Shit");
            inventory.isFull(); // what happens when in this case
            inventory.deselectItem();
            log("is inventory full?");
            inventory.dropAll();
            log("decided to drop");
            break;

        case CHOPPING_LOGS:
            log("Work Work");
            Entity tree = objects.closest("Tree");
            inventory.deselectItem();
            if (tree != null) {
                log("is tree there?");
                if (tree.isVisible()) {
                    log("is tree visible?"); // /what happens when in this case
                    if (!myPlayer().isAnimating())
                        log("am i already animating?");
                    if (myPlayer().isMoving())
                        log("Am i already moving?");
                    tree.interact("Chop Down");
                    log("actually chopping");
                    sleep(gRandom(400, 750));
                    log("sleeping");
                    break;

                }
            }
        case SEARCH_FOR_TREE:
            log("Looking for a new tree");
            Entity newtree = objects.closest("Tree");
            if (newtree != null) // what happens when in this case
                camera.toEntity(newtree);

            newtree.interact("Chop Down");
            break;

        case WAIT:
            random(1000, 2500);
            log("waiting"); // what happens when in this case
            if (myPlayer().isAnimating())
                break;

        case RUNNINGAWAY:
            NPC npc = npcs.closest("Mugger");
            if (npc != null)
                log("attempting to runaway");
                getLocalWalker().walk(CHOPPING_AREA, true);
            log("running from Mugger");
            break;

        }
        return random(200, 300);

    }

    @Override
    public void onExit() {
        log("Done Already?");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

 

i may need to add a sleep timer in the running away case, because it kinda took a while and ran back and forth sort of awkwardly..would that be the way to stop that from occuring?

Edited by chrismac1991
Link to comment
Share on other sites

thanks everyone, okay so heres my newest version lol..it now sort of runs away from the Mugger behind the castle because it was aggressive so yeah no more of that!

 

so my next thing is cutting oaks once skill reaches level 15+

 

could anybody maybe show me how? biggrin.png

 

import org.osbot.rs07.api.model.Entity;

import org.osbot.rs07.api.model.NPC;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import org.osbot.rs07.utility.Area;

import java.awt.*;

@ScriptManifest(author = "Chris", info = "Chops and Drops Trees Lumbridge", name = "Level3TreeKiller", version = 0.1, logo = "")

public class FuckYouTrees extends Script {

    final Area CHOPPING_AREA = new Area(3160, 3225, 3200, 3243);

    @Override

    public void onStart() {

        log("Kill All The Trees!");

        log("Fuck The World"); // /Shit the script says at the beginning

        log("Dont Get Banned Get Bank");

    }

    private enum State {

        CHOPPING_LOGS, DROPPING_LOGS, SEARCH_FOR_TREE, WAIT, RUNNINGAWAY // //"Modes"

                                                                            // my

        // character can

        // be in

    };

    private State getState() {

        NPC npc = npcs.closest("Mugger");

        Entity tree = objects.closest("Tree");

        if (inventory.isFull())

            return State.DROPPING_LOGS;

        if (npc != null)

            return State.RUNNINGAWAY;

        if (tree != null)

            if (!myPlayer().isAnimating()) // how to decide which mode to be

                return State.CHOPPING_LOGS;

        if (myPlayer().isAnimating())

            return State.WAIT;

        else

            return State.SEARCH_FOR_TREE;

    }

    @Override

    public int onLoop() throws InterruptedException {

        switch (getState()) {

        case DROPPING_LOGS:

            log("Dropping Shit");

            inventory.isFull(); // what happens when in this case

            inventory.deselectItem();

            log("is inventory full?");

            inventory.dropAll();

            log("decided to drop");

            break;

        case CHOPPING_LOGS:

            log("Work Work");

            Entity tree = objects.closest("Tree");

            inventory.deselectItem();

            if (tree != null) {

                log("is tree there?");

                if (tree.isVisible()) {

                    log("is tree visible?"); // /what happens when in this case

                    if (!myPlayer().isAnimating())

                        log("am i already animating?");

                    if (myPlayer().isMoving())

                        log("Am i already moving?");

                    tree.interact("Chop Down");

                    log("actually chopping");

                    sleep(gRandom(400, 750));

                    log("sleeping");

                    break;

                }

            }

        case SEARCH_FOR_TREE:

            log("Looking for a new tree");

            Entity newtree = objects.closest("Tree");

            if (newtree != null) // what happens when in this case

                camera.toEntity(newtree);

            newtree.interact("Chop Down");

            break;

        case WAIT:

            random(1000, 2500);

            log("waiting"); // what happens when in this case

            if (myPlayer().isAnimating())

                break;

        case RUNNINGAWAY:

            NPC npc = npcs.closest("Mugger");

            if (npc != null)

                log("attempting to runaway");

                getLocalWalker().walk(CHOPPING_AREA, true);

            log("running from Mugger");

            break;

        }

        return random(200, 300);

    }

    @Override

    public void onExit() {

        log("Done Already?");

    }

    @Override

    public void onPaint(Graphics2D g) {

    }

}

 

i may need to add a sleep timer in the running away case, because it kinda took a while and ran back and forth sort of awkwardly..would that be the way to stop that from occuring?

You can either have 2 different cases, CUTOAK, CUTTREE, or you can do a boolean inside your chop case. So if(oak &&oakTree!=null || tree&&regTree!=null)

 

Or for the two different cases you can do get the skill level, then check to see if it's greater than or equal to 15, and if it is, cut oaks, and if not, cut trees.

Link to comment
Share on other sites

You can either have 2 different cases, CUTOAK, CUTTREE, or you can do a boolean inside your chop case. So if(oak &&oakTree!=null || tree&&regTree!=null)

 

Or for the two different cases you can do get the skill level, then check to see if it's greater than or equal to 15, and if it is, cut oaks, and if not, cut trees.

 

ah thanks so much dude!

im going to get on this right now :D

  • Like 1
Link to comment
Share on other sites

haha well i got my buddy on skype, and so far we've inserted it into the chop case, and now hes suggesting we make a private method to decide which tree is optimal instead :s or something lol anyway it looks like this.

public void onStart() {
        log("Kill All The Trees!");
        log("Fuck The World");
        log("Dont Get Banned Get Bank");
    }

    private enum State {
        CHOPPING_LOGS, DROPPING_LOGS, WAIT, RUNNINGAWAY
    };

    private State getState() {
        NPC npc = npcs.closest("Mugger");
        Entity tree = objects.closest("Tree");
        if (inventory.isFull())
            return State.DROPPING_LOGS;

        if (npc != null)
            return State.RUNNINGAWAY;

        if (tree != null)
            if (!myPlayer().isAnimating())
                return State.CHOPPING_LOGS;

        if (myPlayer().isAnimating())
            return State.WAIT;

        else
            return null;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case DROPPING_LOGS:
            log("Dropping Shit");
            inventory.isFull();
            inventory.deselectItem();
            log("is inventory full?");
            inventory.dropAll();
            log("decided to drop");
            break;

        case CHOPPING_LOGS:
            log("Work Work");
            Entity besttree;
            Entity oakTree = objects.closest("Oak Tree");
            Entity tree = objects.closest("Tree");
            boolean oak = skills.getDynamic(Skill.WOODCUTTING) > 15;
            inventory.deselectItem();
            if (oak && oakTree != null) {
                besttree = oakTree;
            } else if (tree != null) {
                besttree = tree;
            } else {
                besttree = null;
            }
            if (besttree != null) {
                log("is tree there?");
                if (besttree.isVisible()) {
                    if (besttree != null) {
                        camera.toEntity(besttree);
                        log("is tree visible?");
                        if (!myPlayer().isAnimating()) {
                            log("am i already animating?");
                            if (myPlayer().isMoving()) {
                                log("Am i already moving?");
                                besttree.interact("Chop Down");
                                log("actually chopping");
                                sleep(gRandom(400, 750));
                                log("sleeping");
                                break;
                            }
                        }
                    }
                }
                besttree.interact("Chop Down");
            }
            break;

        case WAIT:
            random(1000, 2500);
            log("waiting");
            if (myPlayer().isAnimating()) {

            }
            break;

        case RUNNINGAWAY:
            NPC npc = npcs.closest("Mugger");
            if (npc != null) {
                log("attempting to runaway");
                getLocalWalker().walk(CHOPPING_AREA, true);
                log("running from Mugger");
            }
            break;

        }
        return random(200, 300);

    }

 

version 2.0 is almost done! tongue.png

 

Edit: currently working on changing the getstate stuff cuz yeah its not gonna work with the changes made

 

Edited by chrismac1991
Link to comment
Share on other sites

Annnd done!

version 2.0 is here for all biggrin.png

actually so proud even though i was walked trough most of it lol

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;

import java.awt.*;

@ScriptManifest(author = "ChrisFuckingMac", info = "Chops and Drops Trees Lumbridge", name = "Level3TreeKiller", version = 2.0, logo = "StonerNewb+FriendWhoSurelyGotReallyAnnoyedWithMe")
public class FuckYouTrees extends Script {
    final Area CHOPPING_AREA = new Area(3160, 3225, 3200, 3243);

    @Override
    public void onStart() {
        log("Kill All The Trees!");
        log("Fuck The World");
        log("Dont Get Banned Get Bank");
    }

    private enum State {
        CHOPPING_LOGS, DROPPING_LOGS, WAIT, RUNNINGAWAY
    };

    private Entity getbesttree() {
        Entity besttree;
        Entity oakTree = objects.closest("Oak");
        Entity tree = objects.closest("Tree");
        boolean oak = skills.getDynamic(Skill.WOODCUTTING) > 15;
        inventory.deselectItem();
        if (oak && oakTree != null) {
            besttree = oakTree;
        } else if (tree != null) {
            besttree = tree;
        } else {
            besttree = null;
        }
        return besttree;

    }

    private State getState() {
        NPC npc = npcs.closest("Mugger");
        Entity tree = getbesttree();
        if (inventory.isFull())
            return State.DROPPING_LOGS;

        if (npc != null)
            return State.RUNNINGAWAY;

        if (tree != null)
            if (!myPlayer().isAnimating())
                return State.CHOPPING_LOGS;

        if (myPlayer().isAnimating())
            return State.WAIT;

        else
            return null;
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (skills.getDynamic(Skill.WOODCUTTING) >= 30) {
            logoutTab.logOut();
        }
        switch (getState()) {
        case DROPPING_LOGS:
            log("Dropping Shit");
            inventory.isFull();
            inventory.deselectItem();
            log("is inventory full?");
            inventory.dropAll();
            log("decided to drop");
            break;

        case CHOPPING_LOGS:
            Entity besttree = getbesttree();
            if (besttree != null) {
                camera.toEntity(besttree);
                log("is tree there?");
                if (besttree.isVisible()) {
                    log("is tree visible?");
                    if (!myPlayer().isAnimating()) {
                        log("am i already animating?");
                        if (!myPlayer().isMoving()) {
                            log("Am i already moving?");
                            besttree.interact("Chop Down");
                            log("actually chopping");
                            sleep(gRandom(400, 750));
                            log("sleeping");

                        }
                    }
                }

            }
            break;

        case WAIT:
            random(1000, 2500);
            log("waiting");
            if (myPlayer().isAnimating()) {

            }
            break;

        case RUNNINGAWAY:
            NPC npc = npcs.closest("Mugger");
            if (npc != null) {
                log("attempting to runaway");
                getLocalWalker().walk(CHOPPING_AREA, true);
                log("running from Mugger");
            }
            break;

        }
        return random(200, 300);

    }

    @Override
    public void onExit() {
        log("Done Already?");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}


 

so it should...

Run away from mugger behind lumbridge castle

chop oaks over trees when available

logout at 30 woodcutting

drops everything.

if you're going to use it i recommend starting it behind the castle someplace as thats where the area i made is.

next i learn to use the paint! biggrin.png

 

 

 

Edited by chrismac1991
  • 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.
Note: Your post will require moderator approval before it will be visible.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...