Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

F2P Fisher / Source Code / Lots Of Comments!

Featured Replies

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(name = "Ted_Fisher", author = "Ted", version = 1.0, info = "", logo = "") 

public class Main extends Script {
	
	private JFrame gui;   
	private boolean started = false;//For GUI, will be set true once start button is pressed ON GUI; NOT the start button in the OSBOT client.
	
	//All set by the GUI;
	private String selectedFishingMethod = "Salmon/Trout"; //We initialize the variable because unless the user opens the GUI selection box and physically  clicks a selection, the selection will be null regardless of whether a selection appears in the section window.
    private boolean powerFishingMode = true;
    
    //Paint
    private long startTime;//Long because it is in milliseconds.
    private int numFishCaught;
    
    AreaObject areaObject;//Stores our bank location and fishing location.

    
    
    private void createGUI(){//Code for GUI.
    	 gui = new JFrame("GUI");//Instantiates (good word to know) a new JFrame Object whose memory address is stored in the variable gui. If you don't understand don't worry.

    	 final int GUI_WIDTH = 350, GUI_HEIGHT = 100;//Dimensions for the GUI window.
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//Gets the screen size.
              
         final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);// Calculates x and y coordinates
         final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
           
         gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT); // Set the x coordinate, y coordinate, width and height of the GUI
         gui.setResizable(false); //Makes user unable to resize GUI.
         
         JPanel panel = new JPanel();// Create a sub container JPanel
         gui.add(panel);// Add it to the GUI
         
         JLabel label_1 = new JLabel("What would you like to fish?:");// Create a label
         label_1.setForeground(Color.white);// Set text color to white
         panel.add(label_1); // Add it to the JPanel
         
         JComboBox<String> fishSelecter = new JComboBox<>(new String[]{"Salmon/Trout", "Lobster", "Swordfish/Tuna"});// Create a select box for fish options
         fishSelecter.addActionListener(e -> selectedFishingMethod = fishSelecter.getSelectedItem().toString());// Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection.         
         panel.add(fishSelecter);// Add the select box to the JPanel
         
         JCheckBox powerFishingCheckBox = new JCheckBox("Power Fishing Mode Enabled");
 		 powerFishingCheckBox.setSelected(true);
 		 panel.add(powerFishingCheckBox);
         
         JButton startButton = new JButton("Start");// Add an action listener to the button
         startButton.addActionListener(e -> { // This code is called when the user clicks the start button.
             started  = true;// Set the boolean variable started to true so that the onLoop() method can run.
             
             if(!powerFishingCheckBox.isSelected())//Sets powerfishing mode to false if box isn't selected.
            	 powerFishingMode = false;
             
            setFishingMethod();//Sets the fishing method and fishing location based on the fish you choose
            areaObject = new AreaObject(selectedFishingMethod,powerFishingMode);//An object that stores our fishing area and bankarea if we aren't powerfishing.
            	 
             gui.setVisible(false); // Hide the GUI
         });
         panel.add(startButton); // Add the button to the panel 
         gui.setVisible(true);//Makes the GUI visible.
    }

    
    
    public void setFishingMethod(){//This method changes selectedFishingMethod from the name of a fish to the method which said fish is fished. This method is only for the purpose of reusing variables and to save memory usage. Memory usage isn't much of a concern in this script but it is good programming practice to be efficient.
    	if(selectedFishingMethod.equals("Salmon/Trout")){//Because Strings are objects we can not compare them with the == operator. we must use String.equals().
    		selectedFishingMethod = "Lure";
    		
    	} else if(selectedFishingMethod.equals("Lobster")){
    			selectedFishingMethod = "Cage";
    			
    	} else if(selectedFishingMethod.equals("Swordfish/Tuna")){
    		selectedFishingMethod = "Harpoon";
    	}
    }

   
    
    @[member=Override]
    public void onStart() {//Code here will execute before the loop is started, only executed once that is why we can set instance class variables to 0;
		createGUI();//Here because we only create the GUI once.
		startTime = System.currentTimeMillis();//Gets time in milliseconds and stores it in a variable.
		numFishCaught = 0;//Initialize these variables at 0 so that they can later be incremented.
		getExperienceTracker().start(Skill.FISHING);//Starts Experience Tracker. Used for paid, allows use to easily calculate progress.
    }

    
    
    @[member=Override]
    public void onExit() {//Only executes once; when the program exits
    	long runTime = System.currentTimeMillis() - startTime;//Basic math, System.currentTimeMillis() will return the time when the program stopped, therefore we subtract the time it started from it to obtain the total time ran.
    	log("The script ran for" + formatTime(runTime) + ".");
    	log("You gained " + getExperienceTracker().getGainedLevels(Skill.FISHING) + " fishing levels.");
    	log("You gained " + getExperienceTracker().getGainedXP(Skill.FISHING) + " fishing experience.");
        
    	if(gui != null) { // If the JFrame has been created
            gui.setVisible(false); //Hides GUI. Keep in mind GUI is still there after start button is pressed its just not visable.
            gui.dispose(); //Dispose of GUI.
        }
    }

    
    
    private enum State {//Fishing States
		FISH, DROP, WAIT, BANKING, WALK_TO_BANK, WALK_TO_FISHING_SPOT, STOP
	}

    
    
    private State getState(){
		if(!neededSuppliesInInventory())//If correct supplies are in inventory continues and doesn't return anything.
			return State.STOP;
		if(!inventory.isFull() && !myPlayer().isAnimating() && areaObject.getFishingArea().contains(myPlayer()))//If inventory isn't full AND player isn't animating it returns the fish enumeration.
			return State.FISH;
		if(inventory.isFull() && powerFishingMode)//If inventory is full and power fishing mode is enabled it returns the Drop enumeration.
			return State.DROP;
		if(inventory.isFull() && !powerFishingMode && !areaObject.getBankArea().contains(myPlayer()))//If the inventory is full and powerFishing mode is disabled it will walk to the bank.
			return State.WALK_TO_BANK;
		if(!inventory.isFull() && areaObject.getBankArea().contains(myPlayer()))//If the inventory isn't full and the player is in the bank it will walk to the fishing spot.
			return State.WALK_TO_FISHING_SPOT;
		if(inventory.isFull() && areaObject.getBankArea().contains(myPlayer()))//If the inventory is full and the player is in the bank it will bank.
			return State.BANKING;
		return State.WAIT;//If none are true it waits.
	}

    
    
    @[member=Override]
    public int onLoop() throws InterruptedException {
    	if(started){//Will only run once the start button on the paint is pressed.
    		switch (getState()) {//Try and put minimal code in switch statements to keep it from becoming a cluster fuck. Break up methods it'll not only make the code easier to read, it'll be easier to debug.
    		case FISH:
    			fish();//Example of not writing code in the switch, and instead writing in blocks.
    			break;
    		case DROP:
    			drop();
    			break;
    		case WALK_TO_BANK:
    			walkToBank();
    			break;
    		case WALK_TO_FISHING_SPOT:
    			walkToFishingSpot();
    			break;
    		case BANKING:
    			bank();
    			break;
    		case WAIT:
    			doAntiBan();//Will only preform antiban when script is waiting
    			sleep(random(200, 300));//Sleeps before breaking from the switch and restarting the loop.
    			break;
    		case STOP:
    			this.stop();//Exits script.
    		}
		return random(200, 300);//The amount of time in milliseconds before the loop starts over
    	}
    return random(200,300);	
    }
   
    
    
    private void walk(boolean toBank) throws InterruptedException {//The boolean argument allows us to determine if we are walking to the bank or to the fishing spot. Lets use reuse the method.
    	if(toBank){ 
    		getWalking().webWalk(areaObject.getBankArea());
    	}else{
    		getWalking().webWalk(areaObject.getFishingArea());
    	}
    }
    
    
    
    public void walkToBank() throws InterruptedException{
    	walk(true);
	}

    
    
    public void walkToFishingSpot() throws InterruptedException{
    	walk(false);
	}

    
    
    public void bank() throws InterruptedException{
    	openBank();
    	depositBank();
    	closeBank();
	}
    
    
    
    public void openBank() throws InterruptedException{
    	NPC closestBanker = getNpcs().closest("Banker");
    	Entity closestBankBooth = objects.closest("Bank Booth");
    	if(!bank.isOpen()){
    		int rand = random(3);//This makes it so it will sometimes open the bank via banker and other times via bank booth.
    		if (rand == 1){
    			closestBankBooth.interact("Bank");
    		}else{
    			closestBanker.interact("Bank");
    		}
    		sleep(random(1500,5000));
    		log("opening bank");
    	}
    }
    
    
    
    public void depositBank() throws InterruptedException{
    	if(bank.isOpen()){
    	bank.depositAllExcept("Feather","Fly Fishing Rod","Harpoon","Lobster Pot");
    	sleep(random(400,1000));
    	}
    	log("Depositing");
    }
    
    
    
    public void closeBank(){
    	if(bank.isOpen())
    	bank.close();
    	log("Closing bank");
    }
    
    
    
    public void fish() throws InterruptedException{	
    	NPC closestFishingSpot = getNpcs().closest("Fishing spot");
		closestFishingSpot.interact(selectedFishingMethod);
		sleep(random(1000,5000));
		log("Fishing");
    }

    
    
    public void drop(){//drops all items except fly fishing rod and feathers
    	inventory.dropAllExcept("Fly fishing rod","Feather","Harpoon","Lobster Cage","Coins");
    	log("dropping");
    }

    
    
    public boolean neededSuppliesInInventory(){//Another example of breaking up code.
    	if(selectedFishingMethod.equals("Lure")){//If we selected Lure in the GUI.
    		return inventory.contains("Feather") && inventory.contains("Fly Fishing Rod");//Must be separate because it returns true if it finds one. An example of why you must ALWAYS check the API. 	
    	}
    	if(selectedFishingMethod.equals("Cage")){
    		return inventory.contains("Lobster Pot","Coins");	
    	}
    	if(selectedFishingMethod.equals("Harpoon")){
    		return inventory.contains("Harpoon", "Coins");	
    	}
    	return false;
    }

    
    
	public void doAntiBan() throws InterruptedException {
		switch (random(1, 50)) {//Will do a certain antiban depending on the random number.
		case 1:
			 getTabs().open(Tab.SKILLS);
			 sleep(random(500, 5000));
			 log("Antiban Case 1");
			break;
		case 2:
			 getTabs().open(Tab.SKILLS);
			 sleep(random(500, 5000));
			 getSkills().hoverSkill(Skill.FISHING);
			 sleep(random(100, 8000));
			 getMouse().moveRandomly();
			 log("Antiban Case 2");
			break;
		case 3:
			getMouse().moveRandomly();
			log("Antiban Case 3");
			break;
		case 4:
			this.camera.movePitch(random(0, 360));
			this.camera.moveYaw(random(0, 360));
			log("Antiban Case 4");
			break;
		case 5:
			 this.camera.movePitch(random(0, 360));
			 log("Antiban Case 5");
			break;
		case 6:
			this.camera.moveYaw(random(0, 360));
			log("Antiban Case 6");
			break;
		}
		sleep(random(700, 1800));
		getTabs().open(Tab.INVENTORY); //Returns to inventory whether the antiban runs or not.
	}
    
    
    
    @[member=Override]
    public void onPaint(Graphics2D g) {//Remember (0,0) is the top left corner of the screen.
    	if(started){//Will only run once the start button on the paint is pressed.
    		long runTime = System.currentTimeMillis() - startTime;
    
    		Font font = new Font("TimesRoman", Font.BOLD, 18);//Font to be used for the painting
    		g.setFont(font);
    		g.setColor(Color.green);//Sets paintbrush color to green.
    	
    		g.drawString("Run Time - " + formatTime(runTime), 10, 220);
    		g.drawString("Experience Gained - " + getExperienceTracker().getGainedXP(Skill.FISHING),300,220);
    	
    		g.drawString("Current Fishing Level - " + getSkills().getStatic(Skill.FISHING), 10, 240);
    		g.drawString("Fishing Levels Gained - " + getExperienceTracker().getGainedLevels(Skill.FISHING), 300, 240);
    	
    		g.drawString("EXP Until Level - " + getSkills().experienceToLevel(Skill.FISHING), 10, 260);
    		g.drawString("EXP Per Hour - " + getExperienceTracker().getGainedXPPerHour(Skill.FISHING), 300, 260);
    	
    		g.drawString("Time Until Next Level - " + formatTime(getExperienceTracker().getTimeToLevel(Skill.FISHING)), 10, 280);
    		g.drawString("Current State - " + getState(), 300, 280);
    	
    		g.drawString("Fish Caught - " + numFishCaught, 10, 300);
    	}
    }

    
    
    public void onMessage(Message message) throws java.lang.InterruptedException {//Increments the numFishCaught by reading from the chatbox.
		String txt = message.getMessage().toLowerCase();
		if (txt.contains("you catch"))//Not perfect will increment if a player writes "you catch"
			numFishCaught++;
	}

    
    
    public final String formatTime(final long ms){//Converts milliseconds to hh:mm:ss. It will also leave out hh if its is 0.
        long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
        s %= 60; m %= 60; h %= 24;

        return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
               h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
               String.format("%02d:%02d", m, s);
    }
}
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;

public class AreaObject {//Basic class to store areas.
    
    private Area bankArea;
    private Area fishingArea;

    public final Area barbarianVillage = new Area(3100, 3436, 3112, 3421); 
    public final Area karamja = new Area(2922, 3175, 2927, 3183);
    
    
    
    public AreaObject(String selectedFishingMethod, boolean powerFishingMode) {//Constructor
    	setBankArea(selectedFishingMethod, powerFishingMode);
    	setFishingArea(selectedFishingMethod);
  	}
 

    
	public Area getBankArea() {
		return bankArea;
	}



	public void setBankArea(String selectedFishingMethod, Boolean powerFishingMode) {
		
		if(powerFishingMode == true){	
			bankArea = null;
		}

    	if(selectedFishingMethod == "Lure" && powerFishingMode == false){
    		bankArea = Banks.EDGEVILLE;
    	}
    			

F2P fisher that I have been working on. Any comments questions concerns or issues with my code feel free to address. Have not tested anything other than barbarian village which has been running flawlessly thus far.

Hi, I got a dumb question - can you please link me to the AreaObject in the API? I can't seem it find it...

 

I am referring to the line "AreaObject areaObject;//Stores our bank location and fishing location."

 

Thanks!

 

EDIT: nvm, I see that you defined AreaObject yourself at the bottom. Thanks for sharing your script btw!

Edited by sakodo

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.