Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

My Code Crashes

Featured Replies

I'm learning how to interact with items in the inventory. Also trying to learn how to interact with items on the ground.

When I run the code, my OsBot freezes, and I have to task manager to close it. Here's what I have at the moment.

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 = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0)
public class Main extends Script {

	@Override
	public int onLoop() throws InterruptedException {

		if (fireCheck()) {
			log("hello bitch");
		} else {
			makeFire();

		}

		return 50;
	}

	public boolean fireCheck() {
		RS2Object fire = objects.closest("Fire");

		if (fire != null) {
			return true;
		} else {
			return false;
		}
	}

	public void makeFire() {

		if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {

			RS2Object log = objects.closest("Logs");

			if (log.interact("Light")) {
				new ConditionalSleep(random(600, 1200)) {

					@Override
					public boolean condition() throws InterruptedException {
						return myPlayer().isAnimating();
					}
				}.sleep();
			}
		}
	}

}

 

  • Author
11 minutes ago, Chris said:

VNxpXer.png

Not 100% what you meant by this, But I took my guess.

This is the change I made.

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 = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0)
public class Main extends Script {

	@Override
	public int onLoop() throws InterruptedException {

		makeFire();

		return 50;
	}

	public void makeFire() {

		RS2Object fire = objects.closest("Fire");
		RS2Object log = objects.closest("Logs");

		if (fire != null) {
			if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {
				if (log.interact("Light")) {
					new ConditionalSleep(random(600, 1200)) {

						@Override
						public boolean condition() throws InterruptedException {
							return myPlayer().isAnimating();
						}
					}.sleep();
				}
			}
		}

	}

}

It's not freezing anymore but my code isn't doing anything. So am I using the wrong api to interact with the log that's on the ground?

Edited by kingbutton

o null check b4 interacting

if its a ground item

use the GroundItem api

 

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 = "Kingbutton", info = "Fire Cooking", logo = "", name = "LumbCook", version = 0)
public class Main extends Script {

	@Override
	public int onLoop() throws InterruptedException {

		if (fireCheck()) {
			log("hello bitch");
		} else {
			makeFire();

		}

		return 50;
	}

	public boolean fireCheck() {
		RS2Object fire = objects.closest("Fire");

		return fire != null;
	}

	public void makeFire() {

		if (!myPlayer().isAnimating() && !myPlayer().isMoving()) {

			GroundItem log = getGroundItems().closest("Logs");

			if (log != null && log.interact("Light")) {
				new ConditionalSleep(3000) {

					@Override
					public boolean condition() throws InterruptedException {
						return myPlayer().isAnimating();
					}
				}.sleep();
			}
		}
	}

}

 

  • Author

Ight thanks MAN!

Can you explain to me why in the fireCheck() method I have to return fire != null.

Like why can't i do it in the makeFire() method?

3 hours ago, kingbutton said:

Ight thanks MAN!

Can you explain to me why in the fireCheck() method I have to return fire != null.

Like why can't i do it in the makeFire() method?

You can do it in the makeFire() method, For example something like this:

public void makeFire() {
		RS2Object fire = objects.closest("Fire");
		if (!myPlayer().isAnimating() && !myPlayer().isMoving() && fire != null) {

			GroundItem log = getGroundItems().closest("Logs");

			if (log != null && log.interact("Light")) {
				new ConditionalSleep(3000) {

					@Override
					public boolean condition() throws InterruptedException {
						return myPlayer().isAnimating();
					}
				}.sleep();
			}
		}
	}

It's mostly down to preference, however the way you had it before makes it clearer (to me) when you want the script to light a fire.

Also at the moment you're trying to interact with logs on the ground. If you want to interact with logs in your inventory do this:

Item log = getInventory().getItem("Logs");

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.