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
  • How do i get my script to loop correctly after hopping worlds? also how do i detect players nearby?


    Recommended Posts

    package mainpkg;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.dialogues.Dialogues;
    import org.dreambot.api.methods.input.Camera;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.methods.magic.Magic;
    import org.dreambot.api.methods.magic.Normal;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.methods.widget.Widgets;
    import org.dreambot.api.methods.world.Worlds;
    import org.dreambot.api.methods.worldhopper.WorldHopper;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.utilities.Timer;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.wrappers.items.GroundItem;
    import java.awt.*;
    @ScriptManifest(author = "Kobesmind", name = "Kobe's Wildy Natgrabber", version = 0.1, description = "Telegrabs nature runes and hops, logs out if people are nearby", category = Category.MONEYMAKING)
    public class main extends AbstractScript {
        String status = "BEGINNING SCRIPT";
        enum taskState {
        taskState currentTask = taskState.SEARCH;
        Player otherPlayer;
        GroundItem natRune1 = null;
        GroundItem natRune2 = null;
        Timer timer = new Timer(100000);
        public void onStart() {
        public void onExit() {
        public int onLoop() {
            otherPlayer = Players.closest(plr -> plr != null && !plr.equals(getLocalPlayer()) && plr.distance() > 1);
            if(otherPlayer != null) {
                status = "PLAYER NEARBY. LOGGING OUT...";
            if(Dialogues.canContinue()) {
                currentTask = taskState.SEARCH;
            switch(getState()) {
                case TELEGRAB:
                    status = "TELEGRABBING..";
                    if(natRune1 != null) {
                        Magic.castSpellOn(Normal.TELEKINETIC_GRAB, natRune1);
                        sleepUntil(() -> Magic.canCast(Normal.TELEKINETIC_GRAB), 1000000);
                    if(natRune2 != null) {
                        Magic.castSpellOn(Normal.TELEKINETIC_GRAB, natRune2);
                        sleepUntil(() -> Magic.canCast(Normal.TELEKINETIC_GRAB), 1000000);
                    currentTask = taskState.HOP;
                case SEARCH:
                    natRune1 = GroundItems.closest(item -> item != null && item.getAmount() == 4);
                    natRune2 = GroundItems.closest(item -> item != null && !item.equals(natRune1));
                    if(natRune1 != null || natRune2 != null) {
                        status = "FOUND";
                        currentTask = taskState.TELEGRAB;
                case IDLE:
                    status = "IDLE";
                    sleepUntil(() -> getLocalPlayer().exists(), 10000000);
                    currentTask = taskState.SEARCH;
                case HOP:
                    status = "HOPPING";
                    WorldHopper.hopWorld(Worlds.getRandomWorld(wld -> wld != null && wld.isF2P() && !wld.isPVP() && wld.getMinimumLevel() == 0));
                    currentTask = taskState.IDLE;
            return Calculations.random(500, 600);
        public taskState getState() {
            return currentTask;
        public void onPaint(Graphics g) {
            Color gCol = new Color(180, 180, 180, 180);
            g.fillRect(Widgets.getWidgetChild(162, 0).getX(), Widgets.getWidgetChild(162, 0).getY(), Widgets.getWidgetChild(162, 0).getWidth(), Widgets.getWidgetChild(162, 0).getHeight());
            g.drawString("Status: " + status, 10, Widgets.getWidgetChild(162, 0).getY()+20);
            g.drawString(timer.formatTime(), 10, Widgets.getWidgetChild(162, 0).getY()+40);


    there are two problems here:


    1. after it hops worlds, the script stops working properly.

    2.it wont check for players, i tried many different methods and looked on forum posts for solutions

    Link to comment
    Share on other sites

    if (!getLocalPlayer().exists() || !Client.isLoggedIn()) {
        log("Not logged in");
        return Calculations.random(3000, 6000);

    also you posted in the wrong section

    Link to comment
    Share on other sites

    You should add a `MethodProvider.log("State: " + stateYouAreIn)` log statement to help you debug in each switch statement. This will help you figure out where the script gets stuck.

    For #1: If I had to guess, your code probably gets stuck here: sleepUntil(() -> getLocalPlayer().exists(), 10000000); . Maybe you can try a different condition to check, like Client.isLoggedIn(). But not completely sure, I would double check that your code doesn't get stuck in any sleepUntil.

    For #2: You can follow Fjiddi's advice about Players.all(). Look at the Players API for how to get the number of players around you: https://dreambot.org/javadocs/org/dreambot/api/methods/interactive/Players.html


    Link to comment
    Share on other sites

    Hey! thanks for the advice regarding the player problem, it fixed it

    although, i still have issues with checking if the world loads

    i have a money making scripts that hops worlds after it does what it has to do, and checking if client is logged in, if local player exists, or other usual conditions, i use sleep(7000), but that breaks randomly, how can i fix it?


    if i try to use "Client.isLoggedIn()", for example, it resumes the script even if the world hasn't finished loading, i tried very many alternatives, looked at other scripts on github, and using their methods yields the same result.

    Link to comment
    Share on other sites


    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.