Jump to content

A Beginners Guide to Writing OSBot Scripts (where to get started!) by Apaec


Recommended Posts

  • 3 weeks later...
  • 2 weeks later...
Posted (edited)

Hey i can't for the life of me figure out why this is not working >.>

I tried to modify ur script to be the start of a fishing script but i can get it to work. Currently when ran it will just be in the WAIT state. Most likely because it cant find the fishing spot is what i am assuming (even tho i am right by it). I have tried changing some things such as "Entity -> RS2Object" and "objects -> getObjects()"

import org.osbot.rs07.api.model.*;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;
 
@ScriptManifest(author = "CanCo", info = "shrimper fisher", name = "CanFish", version = 0, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("My fisher v1");
    }
    
    private enum State {
        FISH, WAIT
    }
    private State getState() {
		Entity spot = objects.closest("Fishing spot");
		if (spot != null && !myPlayer().isAnimating())
			return State.FISH;
		return State.WAIT;
	}
  
    @Override
    public int onLoop() throws InterruptedException {
 switch (getState()) {
		case FISH:
                    log("going fishing..");
			Entity spot = objects.closest("Fishing spot");
			if (spot != null && !myPlayer().isAnimating()) 
                                spot.interact("Net-from");
                            break;	
		case WAIT:
                        log("waiting..");
			sleep(random(500, 800));
			break;
		}
		return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("STOPPED");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
       
    }
 
}

 

Edited by CanCo
Posted
6 hours ago, CanCo said:

Hey i can't for the life of me figure out why this is not working >.>

I tried to modify ur script to be the start of a fishing script but i can get it to work. Currently when ran it will just be in the WAIT state. Most likely because it cant find the fishing spot is what i am assuming (even tho i am right by it). I have tried changing some things such as "Entity -> RS2Object" and "objects -> getObjects()"


import org.osbot.rs07.api.model.*;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;
 
@ScriptManifest(author = "CanCo", info = "shrimper fisher", name = "CanFish", version = 0, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("My fisher v1");
    }
    
    private enum State {
        FISH, WAIT
    }
    private State getState() {
		Entity spot = objects.closest("Fishing spot");
		if (spot != null && !myPlayer().isAnimating())
			return State.FISH;
		return State.WAIT;
	}
  
    @Override
    public int onLoop() throws InterruptedException {
 switch (getState()) {
		case FISH:
                    log("going fishing..");
			Entity spot = objects.closest("Fishing spot");
			if (spot != null && !myPlayer().isAnimating()) 
                                spot.interact("Net-from");
                            break;	
		case WAIT:
                        log("waiting..");
			sleep(random(500, 800));
			break;
		}
		return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("STOPPED");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
       
    }
 
}

 

As dreameo stated, they are indeed NPCS. Use:

NPC fishingSpot = getNpcs().closest("Fishing spot");

Apa

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...