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
  • Notification when certain item drops


    zorichy

    Recommended Posts

    Hey Dreambotcrew!

    I'm afk-ing some stuff and want to have a notification in my debug log or an audio notification when a certain item is dropped. Is that possible in a way? I'm not that skilled in Java, but do know how to set up a script.

    I'm trying to integrate it in the following script:

            package Main;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.ScriptManifest;
    
    @ScriptManifest(category = Category.MISC, name = "LJS Logout", author = "LJS", version = 0.1)
    
    public class Main extends AbstractScript {
    
        @Override
        public void onStart() {
            log("LJS Logout started");
        }
    
        Area chickArea = new Area(3160, 3870, 3211, 3817); // Chicken Area
    
        @Override
        public int onLoop() {
            //search for a player using closest method and a lambda expression. First, make sure the player isn't your own player. Then check if it's in the area.
            Player player = getPlayers().closest(p -> p != null && !p.equals(getLocalPlayer()) && chickArea.contains(p));
            //if a player was found
            if (player != null) {
                log("Someone is there!");
                getMouse().setAlwaysHop(true);
                //logout
                getTabs().logout();
            }
            return 10;
        }
    
        @Override
        public void onExit() {
            log("LJS Logout ended");
    
        }
    }
    Link to comment
    Share on other sites

    Not tested this but I threw this together based off a listening class I have already have, you can edit the foreach method to make a noise or do another action.

    import org.dreambot.api.methods.MethodContext;
    import org.dreambot.api.script.AbstractScript;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class ItemListener implements Runnable {
    
        private final MethodContext mc;
        private boolean running = false;
        private long interval = 50;
        private List<Integer> itemInts;
    
        public ItemListener(MethodContext mc) {
            this.mc = mc;
            itemInts = new ArrayList();
        }
    
        @Override
        public void run() {
            try {
                while (running) {
                    mc.getGroundItems().all().stream()
                            .filter(item-> itemInts.contains((Integer)item.getID()))
                            .forEach(item -> AbstractScript.log(String.format("Item: %s has been dropped.", item.getName())));
                    Thread.sleep(interval);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        public boolean removeItem(int id) {
            return itemInts.remove((Integer)id);
        }
    
        public boolean addItem(int id) {
            return itemInts.add(id);
        }
    
        public long getInterval() {
            return interval;
        }
    
        public boolean isRunning() {
            return running;
        }
    
        public void start() {
            AbstractScript.log("ConfigListener started");
            running = true;
        }
    
        public void stop() {
            AbstractScript.log("ConfigListener stopped");
            running = false;
        }
    }

     

    Link to comment
    Share on other sites

    Can't I modify my first script like this and make it search for any dropped items in the 'dropArea'?

     

            package Main;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    
    @ScriptManifest(category = Category.MISC, name = "LJS Logout", author = "LJS", version = 0.1)
    
    public class Main extends AbstractScript {
    
        @Override
        public void onStart() {
            log("LJS Logout started");
        }
    
        Area chickArea = new Area(3160, 3870, 3211, 3817); // Chicken Area
        Area dropArea = new Area(1, 1, 1, 1) // Drop Area
    
        @Override
        public int onLoop() {
            //search for a player using closest method and a lambda expression. First, make sure the player isn't your own player. Then check if it's in the area.
            Player player = getPlayers().closest(p -> p != null && !p.equals(getLocalPlayer()) && chickArea.contains(p));
            //if a player was found
            if (player != null) {
                log("Someone is there!");
                getMouse().setAlwaysHop(true);
                //logout
                getTabs().logout();
                GroundItem bones = getGroundItems().closest(p -> p != null && !p.equals(getLocalPlayer() && dropArea.contains(p)));
                //if any item drop in chickArea
                if (bones != null) {
                    log("DROP!");
                }
            }
            //checks for players every 5ms, you might want to change that.
            return 10;
        }
    
        @Override
        public void onExit() {
            log("LJS Logout ended");
    
        }
    }

    I do get these two error's which I can't seem to get rid of:

    Error:(23, 5) java: illegal start of expression
    Error:(23, 14) java: ';' expected

    Link to comment
    Share on other sites

    I may have over complicated this and misunderstood what you wanted.

    One of the errors is you are missing a semicolon after the last ) in this part of the code.

    Area dropArea = new Area(1, 1, 1, 1) // Drop Area
    

     As far as detecting the bones on the floor you should do this, I can see you tried to adapt the check that you did for players to the ground item you unnecessarily checked if a ground item was your player which it wouldn't be. Instead we will check if your player can reach the bones on the floor. I have also added in the interaction to pick up the bones off of the floor as well. With this interact action and most of the actions in the api it will return true if it is successful and false if not, so it is good practice to put it as the condition of an if statement and then perform a sleep function if this is true to wait until you have picked up the item otherwise your script will spam click the bones over and over.

    GroundItem bones = getGroundItems().closest(item -> item != null && getMap().canReach(item) && dropArea.contains(item));
    //if any item drop in chickArea
    if (bones != null) {
      log("DROP!");
      if(bones.interact("Take")) {
        sleepUntil(()-> !getLocalPlayer().isMoving(), 5000);
      }
    }

     

    Link to comment
    Share on other sites

    Thanks for the reply! I've got it to compile without any problems, but it doesn't show anything in the log and doesn't pick up the bones either.

    This is my total script now:
     

    package Main;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.ScriptManifest;
    
    @ScriptManifest(category = Category.MISC, name = "LJS Logout", author = "LJS", version = 0.1)
    
    public class Main extends AbstractScript {
    
        @Override
        public void onStart() {
            log("LJS Logout started");
        }
    
        Area chickArea = new Area(3160, 3870, 3211, 3817); // Chicken Area
        Area dropArea = new Area(3173, 3850 , 3186, 3830); // Drop Area
    
        @Override
        public int onLoop() {
            //search for a player using closest method and a lambda expression. First, make sure the player isn't your own player. Then check if it's in the area.
            Player player = getPlayers().closest(p -> p != null && !p.equals(getLocalPlayer()) && chickArea.contains(p));
            //if a player was found
            if (player != null) {
                log("Someone is there!");
                getMouse().setAlwaysHop(true);
                //logout
                getTabs().logout();
                GroundItem bones = getGroundItems().closest(item -> item != null && getMap().canReach(item) && dropArea.contains(item));
    //if any item drop in chickArea
                if (bones != null) {
                    log("DROP!");
                    getMouse().setAlwaysHop(false);
                    if(bones.interact("Take Lava")) {
                        sleepUntil(()-> !getLocalPlayer().isMoving(), 5000);
                    }
                }
            }
            return 10;
        }
    
        @Override
        public void onExit() {
            log("LJS Logout ended");
    
        }
    }
    
    Link to comment
    Share on other sites

    You have nested the check for the bones within the bit that activates when there is a player nearby so it will only perform that check if there is a player nearby but you have already logged out by that point.

    26 minutes ago, zorichy said:

    Thanks for the reply! I've got it to compile without any problems, but it doesn't show anything in the log and doesn't pick up the bones either.

    This is my total script now:
     

    
    package Main;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.ScriptManifest;
    
    @ScriptManifest(category = Category.MISC, name = "LJS Logout", author = "LJS", version = 0.1)
    
    public class Main extends AbstractScript {
    
        @Override
        public void onStart() {
            log("LJS Logout started");
        }
    
        Area chickArea = new Area(3160, 3870, 3211, 3817); // Chicken Area
        Area dropArea = new Area(3173, 3850 , 3186, 3830); // Drop Area
    
        @Override
        public int onLoop() {
            //search for a player using closest method and a lambda expression. First, make sure the player isn't your own player. Then check if it's in the area.
            Player player = getPlayers().closest(p -> p != null && !p.equals(getLocalPlayer()) && chickArea.contains(p));
            //if a player was found
            if (player != null) {
                log("Someone is there!");
                getMouse().setAlwaysHop(true);
                //logout
                getTabs().logout();
                GroundItem bones = getGroundItems().closest(item -> item != null && getMap().canReach(item) && dropArea.contains(item));
    //if any item drop in chickArea
                if (bones != null) {
                    log("DROP!");
                    getMouse().setAlwaysHop(false);
                    if(bones.interact("Take Lava")) {
                        sleepUntil(()-> !getLocalPlayer().isMoving(), 5000);
                    }
                }
            }
            return 10;
        }
    
        @Override
        public void onExit() {
            log("LJS Logout ended");
    
        }
    }
    

     

    Link to comment
    Share on other sites

    you'd add a check in that area where you do the canReach(item) you'd add in something like item.getName().equals("Your Item here")

    eg: item.getName().equals("Dragon bones")

    if there's more than one item, then you'll probably want to do it a bit differently.

    But if you plan on continuing with scripting, I would suggest you continue first with Java tutorials so you can understand more of the essentials on what you're trying to do.

    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.