Jump to content

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


Apaec

Recommended Posts

 

Replace your getState() method with this

private State getState() {
		Entity FS = npcs.closest("Fishing spot");
		if (!inventory.isEmptyExcept("Small fishing net"))
			return State.DROP;
		if (FS != null && !myPlayer.isAnimating() && !myPlayer.isMoving())
			return State.FISH;
		return State.WAIT;
	}

 

fixed

private State getState() {	
if (!inventory.isEmptyExcept("Small fishing net")) return State.DROP;
else {
Entity FS = npcs.closest("Fishing spot");
if (FS != null && !myPlayer.isAnimating() && !myPlayer.isMoving()) {
return State.FISH;
}                 
return State.WAIT;
}
Link to comment
Share on other sites

 

Replace your getState() method with this

private State getState() {
		Entity FS = npcs.closest("Fishing spot");
		if (!inventory.isEmptyExcept("Small fishing net"))
			return State.DROP;
		if (FS != null && !myPlayer.isAnimating() && !myPlayer.isMoving())
			return State.FISH;
		return State.WAIT;
	}

 

 

 

fixed

private State getState() {	
if (!inventory.isEmptyExcept("Small fishing net")) return State.DROP;
else {
Entity FS = npcs.closest("Fishing spot");
if (FS != null && !myPlayer.isAnimating() && !myPlayer.isMoving()) {
return State.FISH;
}                 
return State.WAIT;
}

Thanks both, got it working!

Link to comment
Share on other sites

Followed your guide and i really enjoyed it, i tried to make a simple lesser demon killer but i received a couple errors in eclipse as well as in OSbot (obviously)

 

Errors in eclipse were: state cannot be resolved to a type 

Errors in OSbot were: unknown source, wait and attack cannot be resolved to a variable

 

My script

import org.osbot.rs07.api.model.Entity;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
import java.awt.*;
 
@ScriptManifest(author = "You", info = "My first script", name = "aLesserDemonKiller", version = 0, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Let's kill some demons!");
    }
    
    private enum state {
    ATTACK, WAIT
    };
    
private State getState() {
NPC demon = npcs.closest("Lesser demon");
if (demon != null)
return State.ATTACK;
return State.WAIT;
}
 
    @Override
    public int onLoop() throws InterruptedException {
    switch (getstate()) {
    case ATTACK:
    NPC demon = npcs.closest("Lesser demon");
    if (demon !=null) {
    demon.interact("Attack");
    }
    break;
    case wait: 
    sleep(random(500, 700));
    break;
    }
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thank you for running my script!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

 
 
Edited by Aart1
Link to comment
Share on other sites

Followed your guide and i really enjoyed it, i tried to make a simple lesser demon killer but i received a couple errors in eclipse as well as in OSbot (obviously)

Errors in eclipse were: state cannot be resolved to a type

Errors in OSbot were: unknown source, wait and attack cannot be resolved to a variable

My script

import org.osbot.rs07.api.model.Entity;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "You", info = "My first script", name = "aLesserDemonKiller", version = 0, logo = "")

public class main extends Script {

@Override

public void onStart() {

log("Let's kill some demons!");

}

private enum state {

ATTACK, WAIT

};

private State getState() {

NPC demon = npcs.closest("Lesser demon");

if (demon != null)

return State.ATTACK;

return State.WAIT;

}

@Override

public int onLoop() throws InterruptedException {

switch (getstate()) {

case ATTACK:

NPC demon = npcs.closest("Lesser demon");

if (demon !=null) {

demon.interact("Attack");

}

break;

case wait:

sleep(random(500, 700));

break;

}

return random(200, 300);

}

@Override

public void onExit() {

log("Thank you for running my script!");

}

@Override

public void onPaint(Graphics2D g) {

}

}

Make it public enum State and not state.

Link to comment
Share on other sites

 

Followed your guide and i really enjoyed it, i tried to make a simple lesser demon killer but i received a couple errors in eclipse as well as in OSbot (obviously)

 

Errors in eclipse were: state cannot be resolved to a type 

Errors in OSbot were: unknown source, wait and attack cannot be resolved to a variable

 

 

...

    case wait: 
    sleep(random(500, 700));
    break;

 

Another thing I noticed is that in your switch block, "wait" should be "WAIT". Your private enum has entries ATTACK and WAIT, and Java is case-sensitive. Case "wait" will never trigger as is. 

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