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
  • Barbariaan Village lure, cook, and drop


    thepiledriver

    Recommended Posts

    This is my first script for DreamBot. It works pretty well, though it has very little anti-ban. It uses the permanent fire near barb village fishing spot to cook any caught fish, and then just drops all of them.

    I took some snippets from other users because the javadocs were not very helpful to me. It's a bit of a mess and unorganized. I haven't messed with Java in years.

    Please let me know if there's something I could be doing better.

    package Dropper;
    
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.methods.map.Area;
    
    @ScriptManifest(author = "thepiledriver", name = "Barb Village Fish Cook", description = "Lure, cook, and drop", category = Category.FISHING, version = 0.5)
    
    public class Main extends AbstractScript {
    
    	public static final Area FISH_AREA = new Area(3105, 3433, 3110, 3438);
    
    	private void handleDialogue() {
    		sleep(Calculations.random(1500, 5000));
    		getDialogues().clickContinue();
    		sleep(Calculations.random(750, 2500));
    		if (getDialogues().inDialogue()) {
    			getDialogues().clickContinue();
    		}
    
    	}
    
    	private void walkSleep() {
    		sleepUntil(() -> getLocalPlayer().isMoving(), Calculations.random(500, 1000));
    		sleepUntil(() -> !getLocalPlayer().isMoving(), Calculations.random(1000, 2500));
    	}
    
    	private void randomCamera() {
    		int r = Calculations.random(1, 100);
    		switch (r) {
    		case 1:
    			getCamera().rotateToPitch(Calculations.random(333, 399));
    			break;
    		case 2:
    			getCamera().rotateToYaw(Calculations.random(1420, 1700));
    			break;
    		case 3:
    			getCamera().rotateToYaw(Calculations.random(455, 700));
    			break;
    		default:
    		}
    	}
    
    	private void moveCursorOffScreen() {
    		int r = Calculations.random(1, 3);
    		switch (r) {
    		case 1:
    			if (getMouse().isMouseInScreen()) {
    				getMouse().moveMouseOutsideScreen();
    			}
    			break;
    		}
    	}
    
    	private void sleepUntilCooked(String foodName) {
    		while (getInventory().contains(foodName)) {
    			try {
    				Thread.sleep(2000);
    			} catch (Exception e) {
    
    			}
    			if (getDialogues().inDialogue()) {
    				handleDialogue();
    				getInventory().get(foodName).useOn(getGameObjects().closest("Fire"));
    				sleep(1500);
    
    				getKeyboard().typeSpecialKey(32);
    
    				sleep(5000);
    			}
    		}
    	}
    
    	private void resetPlayerPosition() {
    		if (getWalking().walk(FISH_AREA.getRandomTile())) {
    			sleepUntil(
    					() -> getLocalPlayer().isMoving()
    							|| getLocalPlayer().distance(getClient().getDestination()) < Calculations.random(7, 9),
    					Calculations.random(3500, 5400));
    		}
    	}
    
    	public void onStart() {
    		resetPlayerPosition();
    	}
    
    	public void onExit() {
    
    	}
    
    	@Override
    	public int onLoop() {
    		NPC fishingSpot = getNpcs()
    				.closest(item -> item != null && item.getName().contains("Fishing spot") && item.hasAction("Lure"));
    		if (!fishingSpot.isOnScreen()) {
    			log("fishing spot is not on screen, rotating camera...");
    			sleep(Calculations.random(0, 1500));
    			getCamera().rotateToTile(fishingSpot.getTile().getRandomizedTile());
    			sleep(Calculations.random(0, 1500));
    		}
    		if (getInventory().isItemSelected()) {
    			log("Some item is selected, deselecting...");
    			getInventory().deselect();
    			sleep(Calculations.random(0, 2500));
    		}
    		if (getLocalPlayer().getAnimation() == -1 && !getInventory().isFull()) {
    			fishingSpot.interact("Lure");
    		}
    		walkSleep();
    		sleep(Calculations.random(1500, 2500));
    
    		while (getLocalPlayer().isAnimating()) {
    			if (getDialogues().inDialogue()) {
    				handleDialogue();
    			}
    			moveCursorOffScreen();
    			sleep(Calculations.random(2500, 5000));
    		}
    		if (getInventory().isFull()) {
    
    			resetPlayerPosition();
    
    			NPC fire = getNpcs().closest(item -> item != null && item.getName().contains("Fire"));
    			if (!fishingSpot.isOnScreen()) {
    				log("fire is not on screen, rotating camera...");
    				sleep(Calculations.random(0, 1500));
    				getCamera().rotateToTile(fire.getTile().getRandomizedTile());
    				sleep(Calculations.random(0, 1500));
    			}
    
    			getInventory().get("Raw Trout").useOn(getGameObjects().closest("Fire"));
    
    			walkSleep();
    			sleep(2500);
    			getKeyboard().typeSpecialKey(32);
    			sleep(5000);
    			sleepUntilCooked("Raw Trout");
    
    			getInventory().get("Raw Salmon").useOn(getGameObjects().closest("Fire"));
    			sleep(2500);
    			getKeyboard().typeSpecialKey(32);
    			sleep(5000);
    			sleepUntilCooked("Raw Salmon");
    
    			getInventory().dropAllExcept("Feather", "Fly fishing rod");
    			resetPlayerPosition();
    
    		}
    
    		randomCamera();
    		return 1;
    	}
    }

     

    Link to comment
    Share on other sites

    Hey!

    Mashing together code is fine, but learning to read the javadocs is important, since it not only helps you learn what a function does, but what it returns for certain use cases :)

    Handle dialogue is good, but we might want to make it more generic, and a little bit safer, and can move the dialogue check to here, so free up some loop markup. We can also turn it into a Boolean so that it functions just like getDialogues().inDialogue()getDialogues() but with the added functionality of doing the dialogues

        private boolean handleDialogue(){
            if(getDialogues().inDialogue()){ //move the dialogue check here to isolate dialogue logic away from script
                while(getDialogues().canContinue()){ //do a loop in case we experience unexpected dialogue for some reason
                    getDialogues().clickContinue();
                    sleep(750,2000); //personally thing two seconds is a little high
                }
                return true;
            }else{
                return false;
            }
        }

    If you are using a switch statement you should really only use it if you have 3 conditions or more, less than that, it makes more sense, and uses less markup to use if statements
     

    private void moveCursorOffScreen() {
        if(Calculations.random(1, 3) == 1) {
            if (getMouse().isMouseInScreen())
                getMouse().moveMouseOutsideScreen();
        }
    }

    sleepUntilCooked is probably your weirdest function, you use a thread.sleep instead of a normal sleep, and then you also use normal sleeps. It feels really mashed together, and should just use the sleep function provided.
     

        private void sleepUntilCooked(String foodName) {
            while (getInventory().contains(foodName)) {
                //The sleep is probably not needed, but I personally would randomize it
                sleep(2000);
                if (handleDialogue()) { //here is an instance where our new handleDialogue comes into play
                    getInventory().get(foodName).useOn(getGameObjects().closest("Fire"));
                    sleep(1500);
                    getKeyboard().typeSpecialKey(32);
                    sleep(5000);
                }
            }
        }

    I'm not 100% certain but I'm pretty sure your onStart doesn't do anything because you did not @Override it but I could be wrong

    @Override
        public void onStart() {
            resetPlayerPosition();
        }

    Here is what a slightly modified loop would look like
     

        @Override
        public int onLoop() {
            NPC fishingSpot = getNpcs()
                    .closest(item -> item != null && item.getName().contains("Fishing spot") && item.hasAction("Lure"));
            if (!fishingSpot.isOnScreen()) {
                log("fishing spot is not on screen, rotating camera...");
                sleep(Calculations.random(0, 1500));
                getCamera().rotateToTile(fishingSpot.getTile().getRandomizedTile());
                sleep(Calculations.random(0, 1500));
            }
            if (getInventory().isItemSelected()) {
                log("Some item is selected, deselecting... (" + getInventory().getSelectedItemName() + ")");
                getInventory().deselect();
                sleep(Calculations.random(0, 2500));
            }
            if (getLocalPlayer().getAnimation() == -1 && !getInventory().isFull()) {
                fishingSpot.interact("Lure");
                walkSleep(); //this was outside of the loop scope for some reason, causing uneeded waits
                sleep(Calculations.random(1500, 2500));
            }
            
            while (getLocalPlayer().isAnimating()) {
                handleDialogue();
                moveCursorOffScreen();
                sleep(Calculations.random(2500, 5000));
            }
            if (getInventory().isFull()) {
                resetPlayerPosition();
                NPC fire = getNpcs().closest(item -> item != null && item.getName().contains("Fire"));
                if (!fishingSpot.isOnScreen()) {
                    log("fire is not on screen, rotating camera...");
                    sleep(Calculations.random(0, 1500));
                    getCamera().rotateToTile(fire.getTile().getRandomizedTile());
                    sleep(Calculations.random(0, 1500));
                }
                //Personally I would isolate this into another function called "cook" or something
                getInventory().get("Raw Trout").useOn(getGameObjects().closest("Fire"));
                
                walkSleep();
                sleep(2500); //Id also randomize some of these waits if it were me
                getKeyboard().typeSpecialKey(32);
                sleep(5000);
                sleepUntilCooked("Raw Trout");
    
                getInventory().get("Raw Salmon").useOn(getGameObjects().closest("Fire"));
                sleep(2500);
                getKeyboard().typeSpecialKey(32);
                sleep(5000);
                sleepUntilCooked("Raw Salmon");
    
                getInventory().dropAllExcept("Feather", "Fly fishing rod");
              	// End of where that "cook" function could be
                resetPlayerPosition();
                
    
            }
            randomCamera();
            return Calculations.random(400,600); //this is the rate of your script we dont need it to run every millisecond because rs doesn't run that quickly
        }

    this is what your cook method could look like as well to avoid repeating the same logic for each food item

        public void cookFood(){
            List<String> foodNames = Arrays.asList("Trout", "Salmon");
            for(String food: foodNames){
                if(getInventory().contains("Raw " + food)){
                    getInventory().get("Raw " + food).useOn(getGameObjects().closest("Fire"));
                    walkSleep();
                    sleep(2500);
                    getKeyboard().typeSpecialKey(32);
                    sleep(5000);
                    sleepUntilCooked("Raw " + food);
                }
            }
            getInventory().dropAllExcept("Feather", "Fly fishing rod");
        }

     

     

    Also im not 100% sure, since I don't have an account avail to test the script, but it looks like sleep until cooked, also has the logic for cooking? rather than just waiting. you might want to pull the cook functionality out of that :)

    Link to comment
    Share on other sites

    The only other thing I can recommend is to look into nodes, its a fantastic way to organize different big tasks such as "Fish" and "Cook" in this script
    there's a fantastic video on it in this thread, that explains it, and then does a basic woodcutting bot with it to showcase exactly how to use nodes

    (Nodes are part 4)
     

     

    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.