Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Looking for feedback as well as help on first script


    KingBO

    Recommended Posts

    Hello, this is my first time making a script and am looking for ways to improve it as well as help on a few problems i have with it.

    it is a simple script that telegrabs the 2 nature runes in deep wildy, hops between two worlds then teleports to varrock where it will bank once it reaches a certain amount.

    My first question involves the counter, whenever the script grabs a nature rune it takes a long time before it updated in the counter. I believe this is due to it having to go through the entire script before it is updated. Is there a better method for the counter so that it is updated as soon as the rune is grabbed or at least a quicker way for it to be displayed?

    My second question involves the timer, the timer works perfectly fine. However, when the script is paused the timer continues to count up. Is there a way for the timer to be paused at the same time the script is paused?

    My third question involves the telegrab, currently the speed for it to detect the rune then move over to the rune and use telegrab on it is way too slow. Is there a way for this part to be quicker so that the detection and telegrabbing section is faster?

    Any other feedback and improvements are welcome and i apologise for the spaghetti code.

    public class Main extends AbstractScript {
        public static final int NATURE = id;
        private int NatureCount = 0;
        private int prevInvCount = 0;
    
        Timer timer = new Timer();
        public void onStart() {
            timer = new Timer();
            prevInvCount = getInventory().count("Nature rune");
        }
    
        @Override
        public void onPaint(Graphics g) {
            g.drawString("Timer: " + timer.formatTime(), 5, 13);
            g.drawString("Natures collected: " + NatureCount, 5, 26);
        }
    
        @Override
        public int onLoop() {
            Area grabArea = new Area(1, 1, 1, 1, 0);
            if (getInventory().count("Nature rune") >= 200) {
                if (getBank().isOpen()) {
                    getBank().depositAllExcept(NATURE);
                } else if (!getBank().getClosestBankLocation().getArea(40).contains(getLocalPlayer())) {
                    getMagic().castSpell(Normal.VARROCK_TELEPORT);
                    sleep(Calculations.random(4000, 6000));
                }
                getBank().open(BankLocation.VARROCK_WEST);
            } else if (!grabArea.contains(getLocalPlayer())) {
                getWalking().walk(grabArea.getRandomTile());
                sleep(Calculations.random(500, 1500));
            } else if (grabArea.contains(getLocalPlayer())) {
                GroundItem nature = getGroundItems().closest("Nature rune");
                Tile tile = new Tile(1, 1, 0);
    
                if (!getLocalPlayer().isAnimating()) {
                    if (getMagic().isSpellSelected()) {
                        getMouse().move(tile);
                    }   else {
                        getMagic().castSpell(Normal.TELEKINETIC_GRAB);
                    }
                }
                if (nature.exists() && nature != null) {
                    getMagic().castSpellOn(Normal.TELEKINETIC_GRAB, nature);
                    int invcount = getInventory().count("Nature runes");
                    if(invcount > prevInvCount) NatureCount += (invcount - prevInvCount);
                    prevInvCount = invcount;
                    sleep(Calculations.random(2000, 4000));
                    log("Attempting Telegrab");
                    if (getClient().getCurrentWorld() == 1) {
                        getWorldHopper().hopWorld(2);
                        log("Hopping worlds");
                    } else if (getClient().getCurrentWorld() == 2) {
                        getWorldHopper().hopWorld(1);
                        log("Hopping worlds");
                    }
                }
            }
            return 1000;
        }
    }

    I also realise that the area ids and tile ids have not been added, i will get to that soon.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.