Jump to content

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


Apaec

Recommended Posts

  • 3 weeks later...
  • 2 weeks later...

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

Great Quickstart guide, thanks!

I did have to change .entity to .RS2Object in my code for some reason - I'm sure I will work out why as I read into the API more!
Also there have been some interface changes in newer versions of eclipse (since your screenshots), adding the osbot jar file to your library is in a different interface in eclipse neon.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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