Jump to content

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


Apaec

Recommended Posts

14 hours ago, Glaciation96 said:

List<Position> myPositionName = new ArrayList<>();
Position[] lobSpotToPos1 = { new Position(2922,3166,0), new Position(2915,3153,0) };
Position[] lobSpotToPos2 = { new Position(0,0,0), new Position(1,1,1) };
Position[] lobSpotToPos3 = { new Position(0,0,0), new Position(1,1,1) };
Position[] lobSpotToPos4 = { new Position(0,0,0), new Position(1,1,1) };

getWalking().walkPath(Arrays.asList(lobSpotToPos1));

I've been doing some research into arrays and the fundamentals of how to write out code correctly, or try to... If I wanted to have multiple paths, then to call them whenever I see fit, I would have something similar to the above right?

But when I type this into Eclipse, it's saying 'Arrays cannot be resolved' on the 'getWalking...' line of code when I try to call it. What am I doing wrong? Could it be a syntax fail?

Also, I have another question, assuming that the code was able to run and I chose the journey 'lobSpotToPos1' would the bot be selecting those exact tiles via the map, traversing in chronological order until it reaches the ferrymen? Or do the tiles need to be visible within the game window...

 

Thanks!

Have you imported java.utils.Arrays? You will need this for the static asList method. Other than that, your code should work fine.

The bot would click those tiles, yes. But not necessarily all of the tiles in the path. I like to have my paths with a very small tile interval (I use a script to record paths for me) to guarentee that the next tile will always be reachable.

You can always try and experiment with the method and see how it behaves / notice its limitations - i'd suggest this!

Good luck

Apa

  • Like 1
Link to comment
Share on other sites

thanks for guide apaec, 

I followed it all the way but having troubles finding like click commands trying make simple magic script to curse on a rat or whatever high lvl alch and repeat 

is it best to find the mouse position for the magic spells, use hover click? (curse) then to the rat for eg. then to high level alch and loop?

how would you begin 

Link to comment
Share on other sites

2 hours ago, kushad said:

thanks for guide apaec, 

I followed it all the way but having troubles finding like click commands trying make simple magic script to curse on a rat or whatever high lvl alch and repeat 

is it best to find the mouse position for the magic spells, use hover click? (curse) then to the rat for eg. then to high level alch and loop?

how would you begin 

I'd first start with just the cursing, then you can add alching later. Starting with both at the same time might be a little complicated for now.

The benefit of the API is it abstracts away all the specific mouse movement and co-ordinate stuff, so you should take full advantage of this. You're going to want to use the Magic API and the Interaction API.

Off the top of my head, it will be something along these lines:

getMagic().castSpell(NormalSpells.CURSE);

Remeber to check that you have the required runes etc.

Good luck!

Apa

  • Like 1
Link to comment
Share on other sites

Thanks! What a rookie error, importing java.utils.Arrays is what fixed it! 

Sorry if I'm a broken record, but hopefully other scripting scrubs like myself could benefit from my rookie questions if they read through the comments. Seeing as most questions are being asked by people who already know what they're doing to a degree so even the answer can be too difficult to understand lol. 

That said, I have another problem... I want to test my script but can't seem to get it to show up in the client.

 

I've been looking around and the most common solution that fixes it for people who have the same problem as me is that they didn't include the @ScriptManifest info. I have it in my script but it still doesn't work. I saved it as you shown: Users>"Name">OSBot>Scripts, as a Jar file, not a runnable. I go back to the client, refresh, but all I can see are my SDN scripts. What am I doing wrong?

http://prntscr.com/kzklon

Below is my script. Am I missing anything that could cause my script to not appear?

Spoiler

package rsLobstersPack;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Glaciation96", info = "FirstAttempt", name = "KaramajaLobs", version = 0, logo = "")

public class Klobsters extends Script {

	private NPC fishingSpot;

	// private final int[] Essentials = { 995, 301 };

	List<Position> myPositionName = new ArrayList<>();
	Position[] lobSpotToPos1 = { new Position(2922, 3172, 0), new Position(2919, 3168, 0), new Position(2916, 3163, 0),
			new Position(2916, 3153, 0), new Position(2922, 3151, 0), new Position(2930, 3149, 0),
			new Position(2939, 3146, 0), new Position(2947, 3146, 0) };
	Position[] lobSpotToPos2 = { new Position(0, 0, 0), new Position(1, 1, 1) };
	Position[] lobSpotToPos3 = { new Position(0, 0, 0), new Position(1, 1, 1) };
	Position[] lobSpotToPos4 = { new Position(0, 0, 0), new Position(1, 1, 1) };

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		fishingSpot = this.getNpcs().closest("Fishing Spot");
		if (getInventory().isFull()) {

			getWalking().walkPath(Arrays.asList(lobSpotToPos1));

		} else if (fishingSpot != null && fishingSpot.exists() && !myPlayer().isAnimating()) {
			fishingSpot.interact("Cage");
		}
		return random(200, 300);
	}

	/*
	 * public int onLoop() throws InterruptedException { RS2Object stall =
	 * getObjects().closest("Tea Stall"); if (getInventory().contains("Cup of tea"))
	 * { getInventory().drop("Cup of tea"); } else if (stall != null &&
	 * !myPlayer().isAnimating()) { stall.interact("Steal-from"); } return
	 * random(200, 300); }
	 */

	@Override
	public void onExit() {
		log("Doubt it worked...");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

 

 

Thanks again.

Link to comment
Share on other sites

10 hours ago, Glaciation96 said:

Thanks! What a rookie error, importing java.utils.Arrays is what fixed it! 

Sorry if I'm a broken record, but hopefully other scripting scrubs like myself could benefit from my rookie questions if they read through the comments. Seeing as most questions are being asked by people who already know what they're doing to a degree so even the answer can be too difficult to understand lol. 

That said, I have another problem... I want to test my script but can't seem to get it to show up in the client.

 

I've been looking around and the most common solution that fixes it for people who have the same problem as me is that they didn't include the @ScriptManifest info. I have it in my script but it still doesn't work. I saved it as you shown: Users>"Name">OSBot>Scripts, as a Jar file, not a runnable. I go back to the client, refresh, but all I can see are my SDN scripts. What am I doing wrong?

http://prntscr.com/kzklon

Below is my script. Am I missing anything that could cause my script to not appear?

  Reveal hidden contents


package rsLobstersPack;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Glaciation96", info = "FirstAttempt", name = "KaramajaLobs", version = 0, logo = "")

public class Klobsters extends Script {

	private NPC fishingSpot;

	// private final int[] Essentials = { 995, 301 };

	List<Position> myPositionName = new ArrayList<>();
	Position[] lobSpotToPos1 = { new Position(2922, 3172, 0), new Position(2919, 3168, 0), new Position(2916, 3163, 0),
			new Position(2916, 3153, 0), new Position(2922, 3151, 0), new Position(2930, 3149, 0),
			new Position(2939, 3146, 0), new Position(2947, 3146, 0) };
	Position[] lobSpotToPos2 = { new Position(0, 0, 0), new Position(1, 1, 1) };
	Position[] lobSpotToPos3 = { new Position(0, 0, 0), new Position(1, 1, 1) };
	Position[] lobSpotToPos4 = { new Position(0, 0, 0), new Position(1, 1, 1) };

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		fishingSpot = this.getNpcs().closest("Fishing Spot");
		if (getInventory().isFull()) {

			getWalking().walkPath(Arrays.asList(lobSpotToPos1));

		} else if (fishingSpot != null && fishingSpot.exists() && !myPlayer().isAnimating()) {
			fishingSpot.interact("Cage");
		}
		return random(200, 300);
	}

	/*
	 * public int onLoop() throws InterruptedException { RS2Object stall =
	 * getObjects().closest("Tea Stall"); if (getInventory().contains("Cup of tea"))
	 * { getInventory().drop("Cup of tea"); } else if (stall != null &&
	 * !myPlayer().isAnimating()) { stall.interact("Steal-from"); } return
	 * random(200, 300); }
	 */

	@Override
	public void onExit() {
		log("Doubt it worked...");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

 

 

Thanks again.

If you have multiple scripts in that directory with the same manifest name, you can expect some weird behaviour - try removing (albeit temporarily) all other scripts from the folder, so that you are just left with this script. Then try - this will allow you to further pinpoint where the issue lies.

Let me know how it goes :)

Apa

  • Like 1
Link to comment
Share on other sites

Just to give insight into the steps that I'm taking, I've created a series of screenshots to show how I'm exporting my script. Though it's really no different to how it was shown in the tutorial!

https://prnt.sc/kzzqge

https://prnt.sc/kzzqt3

https://prnt.sc/kzzr5z

https://prnt.sc/kzzrdt

Here is a screenshot of my script(top half) inside the IDE, easier to spot if anything looks 'off'.

http://prntscr.com/kzzupm

I only see SDN scripts in the client, in both mirror and stealth injection mode. 

Thanks again.

Edited by Glaciation96
Link to comment
Share on other sites

12 hours ago, Glaciation96 said:

Just to give insight into the steps that I'm taking, I've created a series of screenshots to show how I'm exporting my script. Though it's really no different to how it was shown in the tutorial!

https://prnt.sc/kzzqge

https://prnt.sc/kzzqt3

https://prnt.sc/kzzr5z

https://prnt.sc/kzzrdt

Here is a screenshot of my script(top half) inside the IDE, easier to spot if anything looks 'off'.

http://prntscr.com/kzzupm

I only see SDN scripts in the client, in both mirror and stealth injection mode. 

Thanks again.

Looks like you're exporting it right, but it looks like you are compiling the script with Java 10. OSBot does not support this version of java. You will need to install Java-SE 1.8 and configure the project to compile with this. Hopefully after making this change, everything will work as expected :)

Apa

  • Like 1
Link to comment
Share on other sites

On 9/29/2018 at 12:05 PM, Apaec said:

Looks like you're exporting it right, but it looks like you are compiling the script with Java 10. OSBot does not support this version of java. You will need to install Java-SE 1.8 and configure the project to compile with this. Hopefully after making this change, everything will work as expected :)

Apa

Your solution was perfect, thanks. Changed versions as suggested and saw my script straight away:)

That said, I've run into another issue which has left me confused. I looked around and couldn't find a solution. Below is a snippet of my code.

Position myPos = myPosition();

public final Area[] KaramFishingSpot = { new Area(2922, 3180, 2927, 3174) };
public final Area[] KaramHarbour = { new Area(2950, 3147, 2957, 3146) };	
public final Area[] PortSarim = { new Area(3026, 3222, 3029, 3213) };
public final Area[] DepositBox = { new Area(3044, 3237, 3052, 3234) };

public void gottaBank() {
		if(!DepositBox.contains(myPos) && !this.myPlayer().isMoving()) {
			getWalking().walkPath(Arrays.asList(lobSpotToPos1));
		}
	}

The "(DepositBox.contains(myPos)" is underlined in red and the error states: "Cannot invoke contains(Position) on the array type Area[]".  I'm not sure why this is, as I've seen other people do this with areas? Such as a predefined area from the API like so:

private void getFromBank(){
        if(!closestBank.contains(this.myPosition()) && !this.myPlayer().isMoving()){
            if(getWalking().webWalk(closestBank)){ //etc, etc

Do I have to use positions instead of areas unless it's from the API? Is making my own area the issue here?

Thanks!

Link to comment
Share on other sites

4 hours ago, Glaciation96 said:

Your solution was perfect, thanks. Changed versions as suggested and saw my script straight away:)

That said, I've run into another issue which has left me confused. I looked around and couldn't find a solution. Below is a snippet of my code.


Position myPos = myPosition();

public final Area[] KaramFishingSpot = { new Area(2922, 3180, 2927, 3174) };
public final Area[] KaramHarbour = { new Area(2950, 3147, 2957, 3146) };	
public final Area[] PortSarim = { new Area(3026, 3222, 3029, 3213) };
public final Area[] DepositBox = { new Area(3044, 3237, 3052, 3234) };

public void gottaBank() {
		if(!DepositBox.contains(myPos) && !this.myPlayer().isMoving()) {
			getWalking().walkPath(Arrays.asList(lobSpotToPos1));
		}
	}

The "(DepositBox.contains(myPos)" is underlined in red and the error states: "Cannot invoke contains(Position) on the array type Area[]".  I'm not sure why this is, as I've seen other people do this with areas? Such as a predefined area from the API like so:


private void getFromBank(){
        if(!closestBank.contains(this.myPosition()) && !this.myPlayer().isMoving()){
            if(getWalking().webWalk(closestBank)){ //etc, etc

Do I have to use positions instead of areas unless it's from the API? Is making my own area the issue here?

Thanks!

Glad you got the first issue sorted, I understand setup issues can be annoying and tedious to resolve.

As for your second issue, the reason is types. For some reason (?) you're defining your areas as single element arrays. Not sure why! As a result, when you call '.contains' on the array, java doesn't know what to do as arrays do not have a .contains method in this context. You'll either need to unwrap the value and then call contains, or even simpler: change your area definition to an Area rather than an Area[].

Good luck!

Apa

  • Like 1
Link to comment
Share on other sites

First off, I wanna thank you for the solution to the previous issue. From this, I was able to move on, just to hit another brick wall though lol. As you have suggested previously, I went for a pathwalking approach to my first script instead of doing the webwalk. This way I think I am able to learn more too.

The issue this time is that the script won't start. I open the client in mirror mode, login to my bot, press the green play button, select my script and it just stops dead there. Doesn't even attempt to run and nothing shows up in the log. Again, most people with this problem seems to have missed out the manifest stuff or had an issue with defining something. Mine is probably from the latter, but how would I even begin to, or find out what it is I'm looking for? If you(or someone!) could help me diagnose my problem that would be amazing, I'll share the code here! :)

I have made two scripts., both aims to do the same thing. With the pathwalking version not working, I've decided to create another which is solely based on webwalking and it works! I'll share both, hopefully that'll make it easier to see what's breaking?

 

This is the original (Pathwalking, doesn't work)

Spoiler

package klobstersPack;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Glaciation96", info = "FirstAttempt", name = "Klobster1", version = 0, logo = "")

public class KlobMain extends Script {

	private NPC fishingSpot;

	private enum BotState {
		Fishing, Banking
	};

	public final String[] Essentials = { "Coins", "Lobster cage" };
	public final String[] SeamenOption = { "Yes please." };
	public final String[] CustomsOptions = { "Can I journey on this ship?", "Search away, I have nothing to hide.",
			"Ok." };

	public final Area KaramFishingSpot = new Area(2922, 3180, 2927, 3174);
	public final Area KaramHarbour = new Area(2950, 3147, 2957, 3146);
	public final Area PortSarim = new Area(3026, 3222, 3029, 3213);
	public final Area DepositBox = new Area(3044, 3237, 3052, 3234);
	public final Area boatAtKaramja = new Area(2964, 3143, 2952, 3139);
	public final Area boatAtPortSarim = new Area(3032, 3225, 3036, 3213);

	RS2Object gangplank = getObjects().closest("Gangplank");

	List<Position> myPositionName = new ArrayList<>();
	Position[] lobToKaramHarbour = { new Position(2922, 3172, 0), new Position(2919, 3168, 0),
			new Position(2916, 3163, 0), new Position(2916, 3153, 0), new Position(2922, 3151, 0),
			new Position(2930, 3149, 0), new Position(2939, 3146, 0), new Position(2947, 3146, 0),
			new Position(2954, 3147, 0) };
	Position[] SarimHtoDbox = { new Position(3028, 3220, 0), new Position(3027, 3227, 1), new Position(3028, 3230, 1),
			new Position(3028, 3236, 1), new Position(3032, 3235, 1), new Position(3038, 3236, 1),
			new Position(3044, 3235, 1), new Position(3048, 3235, 1) };
	Position[] DboxToSarimH = { new Position(3044, 3235, 0), new Position(3040, 3235, 1), new Position(3037, 3236, 1),
			new Position(3033, 3235, 1), new Position(3029, 3236, 1), new Position(3027, 3232, 1),
			new Position(3028, 3228, 1), new Position(3027, 3223, 1), new Position(3027, 3218, 1) };
	Position[] KarimHtoLobs = { new Position(2955, 3147, 0), new Position(2951, 3146, 1), new Position(2947, 3147, 1),
			new Position(2943, 3145, 1), new Position(2939, 3145, 1), new Position(2934, 3148, 1),
			new Position(2929, 3151, 1), new Position(2924, 3151, 1), new Position(2919, 3152, 1),
			new Position(2915, 3153, 1), new Position(2917, 3156, 1), new Position(2920, 3161, 1),
			new Position(2923, 3165, 1), new Position(2924, 3170, 1), new Position(2924, 3174, 1) };

	@Override
	public void onStart() {
		log("Let's get glitched out!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (GetState()) {
		case Fishing:
			fish();
			break;
		case Banking:
			gotoBank();
			break;
		}
		return random(200, 300);
	}

	private void fish() {
		if (!KaramFishingSpot.contains(this.myPosition()) && !this.myPlayer().isMoving()
				&& getWalking().webWalk(KaramFishingSpot)) {
			new ConditionalSleep(900000, (int) (Math.random() * 498 + 303)) {
				@Override
				public boolean condition() throws InterruptedException {
					return KaramFishingSpot.contains(myPosition());
				}
			}.sleep();
		} else if (!this.myPlayer().isAnimating() && !this.myPlayer().isMoving()) {
			fishingSpot = this.getNpcs().closest("Fishing Spot");
			if (fishingSpot != null && fishingSpot.exists()) {
				if (fishingSpot.interact("Cage")) {
					new ConditionalSleep(30000, (int) (Math.random() * 502 + 296)) {
						@Override
						public boolean condition() throws InterruptedException {
							return myPlayer().isAnimating();
						}
					}.sleep();
				}
			}
		}
	}

	public void gotoBank() throws InterruptedException {
		if (!KaramHarbour.contains(this.myPosition()) && !this.myPlayer().isMoving() && inventory.isFull()) {
			if (getWalking().walkPath(Arrays.asList(lobToKaramHarbour))) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return KaramHarbour.contains(myPosition());
					}
				}.sleep();
			}
		} // Talk to Customs officer & off da boat
		else if (KaramHarbour.contains(myPosition())) {
			talkToOfficer();
		} else if (PortSarim.contains(this.myPosition()) && !this.myPlayer().isMoving() && inventory.isFull()) {
			if (getWalking().walkPath(Arrays.asList(SarimHtoDbox))) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return DepositBox.contains(myPosition());
					}
				}.sleep();
			}
		} else if (DepositBox.contains(this.myPosition()) && !this.myPlayer().isMoving() && !depositBox.isOpen()) {
			RS2Object Dbox = getObjects().closest("Bank deposit box");
			if (Dbox != null && Dbox.exists()) {
				if (Dbox.interact("Deposit")) {
					new ConditionalSleep(30000, (int) (Math.random() * 493 + 312)) {
						@Override
						public boolean condition() throws InterruptedException {
							return depositBox.isOpen();
						}
					}.sleep();
				}
			}
		} else if (this.depositBox.isOpen()) {
			this.depositBox.depositAllExcept("Essentials");
			new ConditionalSleep(9000, (int) (Math.random() * 248 + 127)) {
				@Override
				public boolean condition() throws InterruptedException {
					return inventory.isEmptyExcept("Essentials");
				}
			}.sleep();
			this.depositBox.close();
		} else if (!PortSarim.contains(this.myPosition()) && !this.myPlayer().isMoving()) {
			if (getWalking().walkPath(Arrays.asList(DboxToSarimH))) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return PortSarim.contains(myPosition());
					}
				}.sleep();
			}
		} // Talk to sea man fella & get off da boat
		else if (PortSarim.contains(this.myPosition())) {
			talkToSeamen();
		} else if (KaramHarbour.contains(this.myPosition()) && !this.myPlayer().isMoving()) {
			if (getWalking().walkPath(Arrays.asList(KarimHtoLobs))) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return KaramFishingSpot.contains(myPosition());
					}
				}.sleep();
			}
		}
	}

	public void talkToSeamen() throws InterruptedException {
		Entity sailor = npcs.closest("Seaman Thresnor", "Seaman Lorris", "Captain Tobias");
		if (sailor != null && !dialogues.inDialogue()) {
			if (sailor.interact("Talk to")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return getDialogues().inDialogue();
					}
				}.sleep();
			}
		} else {
			if (dialogues.completeDialogue("SeamenOption")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return !getDialogues().inDialogue();
					}
				}.sleep();
			}
		}
		new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
			@Override
			public boolean condition() throws InterruptedException {
				return boatAtKaramja.contains(myPosition()) && gangplank != null;
			}
		}.sleep();
		sleep(random(1500, 2500)); // Is this needed? Boat anim could play over character who's already at
									// gangplank!
		if (boatAtKaramja.contains(myPosition()) && gangplank != null) {
			gangplank.interact("Cross");
			new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
				@Override
				public boolean condition() throws InterruptedException {
					return !myPlayer().isAnimating() && KaramHarbour.contains(myPosition());
				}
			}.sleep();
		}
	}

	public void talkToOfficer() throws InterruptedException {
		Entity sailor = npcs.closest("Customs officer");
		if (sailor != null && !dialogues.inDialogue()) {
			if (sailor.interact("Talk to")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return getDialogues().inDialogue();
					}
				}.sleep();
			}
		} else {
			if (dialogues.completeDialogue("CustomsOptions")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return !getDialogues().inDialogue();
					}
				}.sleep();
			}
		}
		new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
			@Override
			public boolean condition() throws InterruptedException {
				return boatAtPortSarim.contains(myPosition()) && gangplank != null;
			}
		}.sleep();
		sleep(random(1500, 2500)); // Is this needed? Boat anim could play over character who's already at
									// gangplank!
		if (boatAtPortSarim.contains(myPosition()) && gangplank != null) {
			gangplank.interact("Cross");
			new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
				@Override
				public boolean condition() throws InterruptedException {
					return !myPlayer().isAnimating() && PortSarim.contains(myPosition());
				}
			}.sleep();
		}
	}

	private BotState GetState() {
		if (getInventory().isFull()) {
			return BotState.Banking;
		}
		return BotState.Fishing;
	}

	@Override
	public void onExit() {
		log("Houston, we have a problem...");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}
}

 

 

 

This is the same script but all pathwalking has been changed to webwalking (runs in client successfully) 

Spoiler

package klobWebPack;

import java.awt.Graphics2D;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Glaciation96", info = "FirstAttempt", name = "KlobsterWebWalk", version = 0, logo = "")

public class LobsterWebWalk extends Script {

	private NPC fishingSpot;

	private enum BotState {
		Fishing, Banking
	};

	public final Area KaramFishingSpot = new Area(2922, 3180, 2927, 3174);
	public final Area DepositBox = new Area(3044, 3237, 3052, 3234);
	public final String[] Essentials = { "Coins", "Lobster cage" };

	@Override
	public void onStart() {
		log("Let's get glitched out!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (GetState()) {
		case Fishing:
			fish();
			break;
		case Banking:
			gotoBank();
			break;
		}
		return random(200, 300);
	}

	private void fish() {
		if (!KaramFishingSpot.contains(this.myPosition()) && !this.myPlayer().isMoving()
				&& getWalking().webWalk(KaramFishingSpot)) {
			new ConditionalSleep(900000, (int) (Math.random() * 498 + 303)) {
				@Override
				public boolean condition() throws InterruptedException {
					return KaramFishingSpot.contains(myPosition());
				}
			}.sleep();
		} else if (!this.myPlayer().isAnimating() && !this.myPlayer().isMoving()) {
			fishingSpot = this.getNpcs().closest("Fishing Spot");
			if (fishingSpot != null && fishingSpot.exists()) {
				if (fishingSpot.interact("Cage")) {
					new ConditionalSleep(30000, (int) (Math.random() * 502 + 296)) {
						@Override
						public boolean condition() throws InterruptedException {
							return myPlayer().isAnimating();
						}
					}.sleep();
				}
			}
		}
	}

	public void gotoBank() throws InterruptedException {
		if (!DepositBox.contains(this.myPosition()) && !this.myPlayer().isMoving() && inventory.isFull()) {
			if (getWalking().webWalk(DepositBox)) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return DepositBox.contains(myPosition());
					}
				}.sleep();
			}
		} else if (DepositBox.contains(this.myPosition()) && !this.myPlayer().isMoving() && !depositBox.isOpen()) {
			RS2Object Dbox = getObjects().closest("Bank deposit box");
			if (Dbox != null && Dbox.exists()) {
				if (Dbox.interact("Deposit")) {
					new ConditionalSleep(30000, (int) (Math.random() * 493 + 312)) {
						@Override
						public boolean condition() throws InterruptedException {
							return depositBox.isOpen();
						}
					}.sleep();
				}
			}
		} else if (this.depositBox.isOpen()) {
			this.depositBox.depositAllExcept("Essentials");
			new ConditionalSleep(9000, (int) (Math.random() * 248 + 127)) {
				@Override
				public boolean condition() throws InterruptedException {
					return inventory.isEmptyExcept("Essentials");
				}
			}.sleep();
			this.depositBox.close();
		} else if (!KaramFishingSpot.contains(this.myPosition()) && !this.myPlayer().isMoving()) {
			if (getWalking().webWalk(KaramFishingSpot)) {
				new ConditionalSleep(900000, (int) (Math.random() * 486 + 307)) {
					@Override
					public boolean condition() throws InterruptedException {
						return KaramFishingSpot.contains(myPosition());
					}
				}.sleep();
			}
		}
	}

	private BotState GetState() {
		if (getInventory().isFull()) {
			return BotState.Banking;
		}
		return BotState.Fishing;
	}

	@Override
	public void onExit() {
		log("Houston, we have a problem...");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}
}

 

 
 

 

Neither script has errors in the IDE, also, whilst the script that runs, actually runs... It starts to fish, but then when the character stops (due to an interruption etc), the script doesn't continue the fishing and instead doesn't do anything! Is that a problem for another day? 

Thanks again.

Edited by Glaciation96
Link to comment
Share on other sites

5 hours ago, Glaciation96 said:

RS2Object gangplank = getObjects().closest("Gangplank");

This is the reason your script is not starting. You can't access this data until the script has started - instead, initialise the variable to null or locate it elsewhere in your code.

Your second problem is a little more deep-routed and is more of a design flaw to your script rather than a quick fix. Let me explain:

When writing a script, you want to maintain the continuously looping nature of the onloop and only delay completion of the onLoop where totally necessary. I see in your code you are using massive 90000ms conditional sleeps. BAD! That way your script isn't looping and being aware of the game, it's just sitting there doing a dumb sleep. Instead, use the game state to determine what to do and perhaps have an idle case where you need to sleep.

Hopefully that makes sense but if not let me know.

Apa

  • Like 1
Link to comment
Share on other sites

Thanks for the response! 

But yes the last part is a little difficult to grasp lol, I'll break down where the confusion is for me.. 

I always thought that it didn't matter how long a conditional sleep is set at since the bot stops sleeping once a condition is met, but that's wrong then? For example, for the below snippet..

if (!KaramFishingSpot.contains(this.myPosition()) && !this.myPlayer().isMoving()
				&& getWalking().webWalk(KaramFishingSpot)) {
			new ConditionalSleep(900000, (int) (Math.random() * 498 + 303)) {
				@Override
				public boolean condition() throws InterruptedException {
					return KaramFishingSpot.contains(myPosition()); //<-- Isn't this the condition to stop sleeping?
				}
			}.sleep();
		}

Despite the massive sleep time, doesn't the bot stop sleeping as soon as the player reaches KaramFishingSpot? Also, by using game states, do you mean returning !myPlayer().isAnimating(); or myPlayer().isMoving(); instead? As they're character states I'm guessing you mean that. 

Secondly, with an idle case, not sure how I can set conditional sleeps to return every possible outcome in a single case, that's something I'll have to look into lol. But tbh It's probably a completely different thing to what I'm thinking of for starters! 

Link to comment
Share on other sites

26 minutes ago, Glaciation96 said:

Thanks for the response! 

But yes the last part is a little difficult to grasp lol, I'll break down where the confusion is for me.. 

I always thought that it didn't matter how long a conditional sleep is set at since the bot stops sleeping once a condition is met, but that's wrong then? For example, for the below snippet..


if (!KaramFishingSpot.contains(this.myPosition()) && !this.myPlayer().isMoving()
				&& getWalking().webWalk(KaramFishingSpot)) {
			new ConditionalSleep(900000, (int) (Math.random() * 498 + 303)) {
				@Override
				public boolean condition() throws InterruptedException {
					return KaramFishingSpot.contains(myPosition()); //<-- Isn't this the condition to stop sleeping?
				}
			}.sleep();
		}

Despite the massive sleep time, doesn't the bot stop sleeping as soon as the player reaches KaramFishingSpot? Also, by using game states, do you mean returning !myPlayer().isAnimating(); or myPlayer().isMoving(); instead? As they're character states I'm guessing you mean that. 

Secondly, with an idle case, not sure how I can set conditional sleeps to return every possible outcome in a single case, that's something I'll have to look into lol. But tbh It's probably a completely different thing to what I'm thinking of for starters! 

Imagine something goes wrong with the webwalking, then the script will never get to the Karam fishing spot. The conditional sleep will cause the script to wait 900 seconds before trying again. Surely you can see the problem with that!

What i'm trying to get at is a more deep-rooted, structural idea - you can never rely on any line of code to execute perfectly as this is a live game and there are many influencing variables. When I say game state, I mean querying a current 'snapshot' of the game. You're right, isAnimating is an example of this, as is the distance between the lumbridge guide and lumbridge castle. Having your script be entirely conditional on game state instead of executing lines like a recipe will make for a much more reliable script.

Apa

  • Like 1
Link to comment
Share on other sites

Yes of course, seems so obvious now, I fixed that simply by just reducing sleep times lol. 

I've also noticed a couple things when testing my script and attempting some debugging. Whilst it is still listed in the API, completeDialogue no longer seems to work, or maybe it's unreliable? For example, when running the below snippet, the bot will only advance 'continue' dialogues, but do nothing when the options are presented. Any idea what's going on there? Could I be using it wrong?

Spoiler

public final String[] CustomsOptions = { "Can I journey on this ship?", "Search away, I have nothing to hide.", "Ok." };

public void talkToOfficer() throws InterruptedException {
		Entity sailor = npcs.closest("Customs officer");
		if (sailor != null && !dialogues.inDialogue()) {
			if (sailor.interact("Talk to")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return getDialogues().inDialogue();
					}
				}.sleep();
			}
		} else {
			if (dialogues.completeDialogue("CustomsOptions")) {
				new ConditionalSleep(9000, (int) (Math.random() * 436 + 247)) {
					@Override
					public boolean condition() throws InterruptedException {
						return !getDialogues().inDialogue();
					}
				}.sleep();
			}
		} //etc..

 

 

 

What's more, the depositAllExcept function only works with ids now? But I've seen people use strings to accomplish this task! So why does my bot bank the coins and lobster pot along with the lobsters when depositing? Everything seems to be in place... Unless the examples/tutorials that I've seen have called upon outside classes that weren't shown to get it working.

Spoiler

public final String[] Essentials = { "Coins", "Lobster pot" };

else if (this.depositBox.isOpen()) {
			this.depositBox.depositAllExcept("Essentials");
			new ConditionalSleep(9000, (int) (Math.random() * 248 + 127)) {
				@Override
				public boolean condition() throws InterruptedException {
					return inventory.isEmptyExcept("Essentials");
				}
			}.sleep();

 

 

 

I really appreciate the help. Hopefully other scrubs reading will benefit aswell.

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