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.

Fishing Script Help

Featured Replies



import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Let's get started!");
    }
    
    private enum State {
        FISH, COOK, DROP
    }
    
    private State getState() {
        if(inventory.isEmptyExcept(310, 17794, 309, 17795, 123, 17796) && !myPlayer().isAnimating())
            return State.FISH;
        if(inventory.isFull())
            return State.COOK;
        return State.DROP;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
        switch(getState()) {
            case FISH:
                //Entity fishingSpot = objects.closest("Fishing Spot"); Wrong. Fishing spots are tied to NPCs

                //You meant to do:
                NPC fishingSpot = getNpcs().closest("Fishing Spot");
                if (fishingSpot != null) { //ALWAYS NULL CHECK BEFORE INTERACTING..Keep this in mind.   logic: if it exists -> interact
                    fishingSpot.interact("Lure");
                    //sleep
                }
                break;
            case COOK:
                //Entity fire = objects.closest("fire"); This is okay to do since Object,NPC,etc extend Entity
                //but should do it like this.
                RS2Object fire = getObjects().closest("Fire");
                RS2Widget cookMenu = widgets.get(307, 4);

                //I am going to throw some code in here for you. It will be your job to find it in the API docs and understand the methods I am implementing.
                if (cookMenu != null && cookMenu.isVisible()) {
                    cookMenu.interact("Cook All");
                    //sleep
                } else {
                    if (getInventory().isItemSelected()) {
                        if (fire != null) {
                            fire.interact("Use");
                            //sleep...look into ConditionalSleep
                        }
                    } else {
                        //item is not selected..select something
                        inventory.interact("Use", "Trout");
                        //sleep
                    }
                }
                break;
            case DROP:
                inventory.dropAll(331, 332, 333, 334, 25976);
                break;
        }
        return 600; //just return a server tick 600ms
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

 

I wanted to make a script for OSBot, and decided that I wanted to make a script that fished at barbarian village and also cook the fish before dropping them. When I got to making the cooking part, I got stuck because I couldn't use interact on the fire like I could the fishing spots. Any help or touchups of what I have done are gladly welcomed!

 

 

 

Try this

Edited by Christopher

  • Author


import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Let's get started!");
    }
    
    private enum State {
        FISH, COOK, DROP
    }
    
    private State getState() {
        if(inventory.isEmptyExcept(310, 17794, 309, 17795, 123, 17796) && !myPlayer().isAnimating())
            return State.FISH;
        if(inventory.isFull())
            return State.COOK;
        return State.DROP;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
        switch(getState()) {
            case FISH:
                //Entity fishingSpot = objects.closest("Fishing Spot"); Wrong. Fishing spots are tied to NPCs

                //You meant to do:
                NPC fishingSpot = getNpcs().closest("Fishing Spot");
                if (fishingSpot != null) { //ALWAYS NULL CHECK BEFORE INTERACTING..Keep this in mind.   logic: if it exists -> interact
                    fishingSpot.interact("Lure");
                    //sleep
                }
                break;
            case COOK:
                //Entity fire = objects.closest("fire"); This is okay to do since Object,NPC,etc extend Entity
                //but should do it like this.
                RS2Object fire = getObjects().closest("Fire");
                RS2Widget cookMenu = widgets.get(307, 4);

                //I am going to throw some code in here for you. It will be your job to find it in the API docs and understand the methods I am implementing.
                if (cookMenu != null && cookMenu.isVisible()) {
                    cookMenu.interact("Cook All");
                    //sleep
                } else {
                    if (getInventory().isItemSelected()) {
                        if (fire != null) {
                            fire.interact("Use");
                            //sleep...look into ConditionalSleep
                        }
                    } else {
                        //item is not selected..select something
                        inventory.interact("Use", "Trout");
                        //sleep
                    }
                }
                break;
            case DROP:
                inventory.dropAll(331, 332, 333, 334, 25976);
                break;
        }
        return 600; //just return a server tick 600ms
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

Try this

 

Holy crap. Thank you so much. I kinda rushed into scripting, and this helps a lot. Thanks for all the comments you left in it, I'll have a much better grasp next time I decide to write- and some more Java under my belt.

 

EDIT:

I went through and checked the ID's, and they were incorrect, which was why the script wasn't working. I had the wrong ID for the fishing rod, so it wasn't starting the FISH state.

Edited by Popymon24

Holy crap. Thank you so much. I kinda rushed into scripting, and this helps a lot. Thanks for all the comments you left in it, I'll have a much better grasp next time I decide to write- and some more Java under my belt.

 

EDIT:

I went through and checked the ID's, and they were incorrect, which was why the script wasn't working. I had the wrong ID for the fishing rod, so it wasn't starting the FISH state.

Use names , no need to use IDs.

1) Few problems in your script, it will keep clicking the fishing spot bc you aren't checking if you are fishing. Check if your player is animating or not for this.

2) YOu don't check if you've done the previous steps, you will just keep looping non stop. 

3) You're missing brackets on your widgets

4) Why are you dropping 4 items?

5) Your script literally is just linear right now. Look into conditional sleeps and using if/else statements to check if you're doing an action.

6) Do the first few modules Code Academy to learn the basics of Java first. It will help you in the long wrong.

7) Use pastebin, code is ugly on OsBot and not formatted 

8) Shouldn't "fire" be capitalized? 

 

Brackets are good form for if/elses but they're not necessary if theres only like 1 line in code.

 

if (a == b) {

     ~~~~~;

}

 

is effectively the same as

 

if(a ==b)

  ~~~~~~~;

Edited by Imateamcape

Brackets are good form for if/elses but they're not necessary if theres only like 1 line in code.

 

if (a == b) {

     ~~~~~;

}

 

is effectively the same as

 

if(a ==b)

  ~~~~~~~;

 

I prefer brackets.

Create an account or sign in to comment

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.