Jump to content

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


Apaec

Recommended Posts

37 minutes ago, osrs_pvm said:

Thanks for the guide, this will probably be me

To answer your previous question, you will see that our script extends Script. This is an abstract class in the OSBot API and since we are extending it, we have access to all of its attributes. An example of an attribute is inventory, whereby we are calling the super inventory object attribute and using the methods that it provides. As for the stall, you will find that that is initialised just above the snippet you quoted, we're creating an instance of an RS2Object which is an API object describing an ingame object. 

Hope that makes sense, let me know if you're still unsure. Since you edited the post I would assume you figured this out yourself but I just thought i'd drop a quick reply in to clear it up if you didn't!

-Apa

Link to comment
Share on other sites

  • 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

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...