Jump to content

Noob needs some help


Scorncial

Recommended Posts

Hi, so I'm getting into Java scripting (but I know a decent amount of PHP) and as always, I learn best by actually doing stuff. So therefore I'd like to learn some really basic stuff by making a very simple script. The script I'd like to make should talk against Wyson the gardener at the Falador garden and buy Woad leaves from him.  This is what I have so far:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "Luigi", info = "Buys Woad leaves from Wyson the gardener in Falador Park", name = "Woad Leaf Buyer", version = 0.1, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Woad Leaf Buyer has started.");
    }
    
	private enum State {
		TALK, WAIT
	};
	
	private State getState() {
		if (condition 1 is true)
			return State.TALK;
		return State.WAIT;
	}

 
    @Override
    public int onLoop() throws InterruptedException {
    	switch (getState()) {
		case TALK:
			NPC gardener = objects.closest("Wyson the gardener");
			if (stall != null) {
				stall.interact("Talk-to");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script");
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

I'm making this script based upon this beginners tutorial. Eclipse gives me an error on line 20, 30, 31 and 32. What am I doing wrong? Also how can I check if the user has more than 20 coins in his inventory and exit the script, if that ain't the case?

 

Thanks for helping a starting noob like me smile.png

Edited by Scorncial
Link to comment
Share on other sites

Hi, so I'm getting into Java scripting (but I know a decent amount of PHP) and as always, I learn best by actually doing stuff. So therefore I'd like to learn some really basic stuff by making a very simple script. The script I'd like to make should talk against Wyson the gardener at the Falador garden and buy Woad leaves from him.  This is what I have so far:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "Luigi", info = "Buys Woad leaves from Wyson the gardener in Falador Park", name = "Woad Leaf Buyer", version = 0.1, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Woad Leaf Buyer has started.");
    }
    
	private enum State {
		TALK, WAIT
	};
	
	private State getState() {
		if (condition 1 is true)
			return State.TALK;
		return State.WAIT;
	}

 
    @Override
    public int onLoop() throws InterruptedException {
    	switch (getState()) {
		case TALK:
			NPC gardener = objects.closest("Wyson the gardener");
			if (stall != null) {
				stall.interact("Talk-to");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script");
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

I'm making this script based upon this beginners tutorial. Eclipse gives me an error on line 20, 30, 31 and 32. What am I doing wrong? Also how can I check if the user has more than 20 coins in his inventory and exit the script, if that ain't the case?

 

Thanks for helping a starting noob like me smile.png

Line 30: You want to get to the NPC but you try to define it as an object.

Line 31: You try to interact with a variable called stall but that's never made.

Line 32: Same as 31.

 

For the coin thing:

		if(!(inventory.getAmount(COINID) < 20)) {
			stop();
		}
Edited by Rudie
Link to comment
Share on other sites

 

Line 30: You want to get to the NPC but you try to define it as an object.

Line 31: You try to interact with a variable called stall but that's never made.

Line 32: Same as 31.

 

For the coin thing:

		if(!(inventory.getAmount(COINID) < 20)) {
			stop();
		}

 

Thanks, your comments helped a lot :) Would you have an idea on how to solve the error on line 20? Also, if I can't define the NPC as an object as what should I define it? The coin thing should this be put between line 27 and 28?

Link to comment
Share on other sites

Thanks, your comments helped a lot smile.png Would you have an idea on how to solve the error on line 20? Also, if I can't define the NPC as an object as what should I define it? The coin thing should this be put between line 27 and 28?

Yes put the coin thing at the beginning of your loop.

To define the npc:

		NPC gardener = npcs.closest("Wyson the gardener");

(Also make sure you import NPC).

Line 20 you forgot the brackets at the if statement it should be:

if(code here) {

 

}

Link to comment
Share on other sites

Yes put the coin thing at the beginning of your loop.

To define the npc:

		NPC gardener = npcs.closest("Wyson the gardener");

(Also make sure you import NPC).

Line 20 you forgot the brackets at the if statement it should be:

if(code here) {

 

}

 

Thanks a lot, but I'm still getting an error on line 21, Eclipse says the following:

 

Multiple markers at this line:

- condition cannot be resolved to a variable

- syntax error on tokens, delete these tokens

 

And how can I find the Id for coins?

 

This is my script now:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "Luigi", info = "Buys Woad leaves from Wyson the gardener in Falador Park", name = "Woad Leaf Buyer", version = 0.1, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Woad Leaf Buyer has started.");
    }
    
	private enum State {
		TALK, WAIT
	};
	
	private State getState() {
		if (condition 1 is true) {
			return State.TALK;
		} else {
		return State.WAIT;
		}
	}

 
    @Override
    public int onLoop() throws InterruptedException {
    	
    	if(!(inventory.getAmount(COINID) < 20)) {
			stop();
		}
    	
    	switch (getState()) {
		case TALK:
			NPC gardener = npcs.closest("Wyson the gardener");
			if (gardener != null) {
				gardener.interact("Talk-to");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}
Edited by Scorncial
Link to comment
Share on other sites

 

Thanks a lot, but I'm still getting an error on line 21, Eclipse says the following:

 

 

And how can I find the Id for coins?

 

This is my script now:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
 
@ScriptManifest(author = "Luigi", info = "Buys Woad leaves from Wyson the gardener in Falador Park", name = "Woad Leaf Buyer", version = 0.1, logo = "")
public class main extends Script {
 
    @Override
    public void onStart() {
        log("Woad Leaf Buyer has started.");
    }
    
	private enum State {
		TALK, WAIT
	};
	
	private State getState() {
		if (condition 1 is true) {
			return State.TALK;
		} else {
		return State.WAIT;
		}
	}

 
    @Override
    public int onLoop() throws InterruptedException {
    	
    	if(!(inventory.getAmount(COINID) < 20)) {
			stop();
		}
    	
    	switch (getState()) {
		case TALK:
			NPC gardener = npcs.closest("Wyson the gardener");
			if (gardener != null) {
				gardener.interact("Talk-to");
			}
			break;
		case WAIT:
			sleep(random(500, 700));
			break;
		}
        return random(200, 300);
    }
 
    @Override
    public void onExit() {
        log("Thanks for running my first script");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
}

Well you try to see if a boolean is true but you dont check a variable, when programming you can't just put plain text like you have in line 20 in the if statement.

 

And for the coin id it should be 995 if I remember correctly :)

Link to comment
Share on other sites

Well you try to see if a boolean is true but you dont check a variable, when programming you can't just put plain text like you have in line 20 in the if statement.

 

And for the coin id it should be 995 if I remember correctly smile.png

 

Thanks :) I see, that was very stupid of me :D Do you have any idea how I can check if the player is currently talking to the gardener?

Link to comment
Share on other sites

		if(myPlayer().isInteracting(gardener)) {
			
		}

Kan je dat proberen, geen idee of het werkt heb het snel even gemaakt tongue.png

 

 

Super bedankt :) But I'll keep writing in english so other people can still understand ;) So I did look a bit into the api and when talking to the gardener I'll need to use the "dialogues" class and use "clickContinue()" to talk to him, but how can I make the bot chose a specific option when he gets offered one? for example the gardener will ask how much he wants to pay for the Woad leaf, and you have 4 options: 5, 10, 15 and 20 gp, how do I make the bot to chose for the 20 gp option?

Link to comment
Share on other sites

Super bedankt :) But I'll keep writing in english so other people can still understand ;) So I did look a bit into the api and when talking to the gardener I'll need to use the "dialogues" class and use "clickContinue()" to talk to him, but how can I make the bot chose a specific option when he gets offered one? for example the gardener will ask how much he wants to pay for the Woad leaf, and you have 4 options: 5, 10, 15 and 20 gp, how do I make the bot to chose for the 20 gp option?

Isn't there a method in the API to select a specific option? I can't make an example method right now cause I shut down my PC cause I'm going to bed in a few minutes. Edited by Rudie
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...