Jump to content

aHopper - add basic world hopping utilities to your script


Solzhenitsyn

Recommended Posts

Probably not very useful, but I needed a way to manage my world jumps so I wrote this. Maybe someone will find this helpful. Modify world list to suit your needs.
 
Usage:

aHopper.jumpTo(301) // These two instructions do the same thing.
aHopper.jumpTo(1)   // aHopper is agnostic to the real server number vs. the used server number.

// Now we are on world 301. aHopper handles boundary worlds.
aHopper.jumpToPrev() // Now we will jump to 394.
aHopper.jumpToNext() // Now we will jump to 301.

// aHopper keeps track of how many times we have jumped during this runtime.
aHopper.isNextHopMultipleOf(5) // returns true

// aHopper will update when it begins to try jumping, the following instruction will complete.
aHopper.jumpTo(hopTarget);
new cSleep(() -> getWorlds().getCurrentWorld() == aHopper.getCurrWorld(), 2500).sleep(); // cSleep not included, go look at Explv's explanation of lambda expressions.

 

import org.osbot.rs07.script.MethodProvider;

public final class aHopper {

    private int[] rsbFree = {
            1, 8,
            16,
            26,
            35,
            81, 82, 83, 84, 85,
            93, 94};
    private int[] f2pWorlds = rsbFree;

    private int baseWorldIndex, currWorldIndex;
    private int totalJumps = 0;

    protected MethodProvider methods;

    public aHopper(MethodProvider methods) {
        this.methods = methods;
        for (int i = 0; i < rsbFree.length - 1; i++) {
            f2pWorlds[i] += 300;
        }
        baseWorldIndex = currWorldIndex = getWorldIndex(methods.getWorlds().getCurrentWorld());
    }

    // Private methods
    private int getWorldIndex(int world) {
        if (world > 300) {
            for (int i = 0; i < f2pWorlds.length; i++) {
                if (world == f2pWorlds[i]) {
                    return i;
                }
            }
        } else if (world > 0) {
            for (int i = 0; i < f2pWorlds.length; i++) {
                if (world == rsbFree[i]) {
                    return i;
                }
            }
        }
        return -1;
    }

    private int getNextWorldIndex() {
        currWorldIndex = getWorldIndex(methods.getWorlds().getCurrentWorld());
        if (++currWorldIndex - baseWorldIndex == rsbFree.length - 1)
            currWorldIndex = 0;
        return currWorldIndex;
    }

    private int getPrevWorldIndex() {
        currWorldIndex = getWorldIndex(methods.getWorlds().getCurrentWorld());
        if (currWorldIndex == 0) {
            currWorldIndex = rsbFree[rsbFree.length - 1];
        } else {
            currWorldIndex--;
        }
        return currWorldIndex;
    }

    // Accessors
    public int getCurrWorld() {
        return f2pWorlds[currWorldIndex];
    }
    public int getTotalJumps() {
        return totalJumps;
    }

    // Status
    boolean isNextHopMultipleOf(int n) {
        if ((totalJumps + 1) % n == 0) {
            return true;
        }
        return false;
    }

    // World Hopping
    void jumpToNext() {
        methods.getWorlds().hop(rsbFree[getNextWorldIndex()]);
        totalJumps++;
        methods.log("Attempting jump to next world...");
    }
    void jumpToPrev() {
        methods.getWorlds().hop(rsbFree[getPrevWorldIndex()]);
        totalJumps++;
        methods.log("Attempting to jump to previous world...");
    }
    boolean jumpTo(int n) {
        if (getWorldIndex(n) != -1) {
            methods.getWorlds().hop(n);
            currWorldIndex = getWorldIndex(n);
            return true;
        }
        return false;
    }
}
Edited by Solzhenitsyn
Link to comment
Share on other sites

Tried to use it like this but it just skyrocketed my CPU and made OSBOT unusable.

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

import static org.osbot.rs07.script.MethodProvider.random;

/**import org.osbot.rs07.api.map.Area;
 import org.osbot.rs07.api.map.constants.Banks;
 import org.osbot.rs07.api.model.Entity;
 import org.osbot.rs07.api.model.NPC;
 import org.osbot.rs07.script.Script;
 import org.osbot.rs07.utility.ConditionalSleep;

 import static org.osbot.rs07.script.MethodProvider.random;

 /**
 * Created by tek on 8/14/2016.
 */
public class WorldHopTask extends Task {
    private aHopper aHopper;







    public WorldHopTask(Script script) {
        super(script);
    }

    @[member=Override]
    public boolean verify() {
        return !script.getInventory().contains("Trout");
    }

    @[member=Override]
    public int execute() {
        script.log("No trout in inventory, hopping worlds");

        aHopper.jumpTo(316);




        return random(1200,6400);
    }

    @[member=Override]
    public String describe() {
        return "Mining bro";
    }
}



import org.osbot.rs07.script.Script;

public abstract class Task {
    // The script instance
    protected Script script;

    public Task(Script script) {
        this.script = script;
    }

    /**
     * @return if this Task should execute.
     */
    public abstract boolean verify();

    /**
     * Executes this Task.
     *
     * @return sleep time after this task ends.
     */
    public abstract int execute() throws InterruptedException;

    /**
     * @return a description of the current Task.
     */
    public abstract String describe();
}

Anything I may be doing wrong?

 

 

Link to comment
Share on other sites

  • 1 month later...

Then you create a new class that when it hops to a PVP/DMM world that it instantly log out and connect to another world smile.png.

 

You could avoid it from joining one of those types of world.

Leechers will copy code and be surprised when they find themselves dead in a PVP world boge.png

 

Also i do have a snippet on here that handles it look it up.

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