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.

[HELP] Making script go task to task instead of looping over first two

Featured Replies

package oaklarders;



import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

// Start script lvl 33 Construction

@ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0)

public class Oaklarders extends Script {


	@Override
	public void onStart() {
		log("Sit back and relax");
	}
	@Override
	public int onLoop() throws InterruptedException {
		
		objects.closest("Larder space").interact("Build"); {
			sleep(1000);
		}
		
		RS2Widget widget = widgets.get(458, 5, 4);
		if(widget != null) {
			widget.interact(); {
				sleep(2000); 
			}
		objects.closest("Larder").interact("Remove");
		sleep(1000);
		}
         
		RS2Widget removeMenu = widgets.get(219, 1, 1);
		if(removeMenu != null) {
			removeMenu.interact(); {
		sleep(1000);
			}
		
		if(!inventory.contains("Oak plank")) {
		RS2Widget settings = widgets.get(548, 35);
		if(settings != null) {
			settings.interact(); {
				sleep(200);
				
			}
				RS2Widget house = widgets.get(261, 99);
				if(house != null) {
					house.interact(); {
						sleep(200);
					}
				RS2Widget servant = widgets.get(370, 19, 0);
				if(servant != null) {
					servant.interact(); {
						sleep(200);
					}
				RS2Widget unote = widgets.get(219, 1, 1);
				if(unote != null) {
					unote.interact(); {
						sleep(10000);
					}
				}
				}
				}
			}
		}
		}
		
			return(200);

		
	}	
	
	@Override 
    public void onExit() {
    	log("Thank's for using Oaklardersv1");
    }

}

	

// Make bot build and remove larders
// Make bot interact with butler to unote planks
// Make bot call servant if needed
// Add humanlike behavior sleeps etc

So everything's good untill I run out of planks and it trys to build larders over and over again. I know sleeps arnt the best method and should be using ConditionalSleeps but still a noob to this shit lol. If anyone can help give me an idea on how to break each task up id greatly appreciate it. 

 

 

i-will-find-you-thank-you-memes.jpg

By any chance does it leave you with one or two oak planks in invent when it's finished building as many as it can?

maybe just try to use if and else statements

so

if(has planks)
   build larders
else if(condition 2)
   remove larders
else if(condition 3)
   interact with butler

 

You can do several checks, if more than 'x' oak planks, interact.

  • Author
5 minutes ago, TutIslander said:

By any chance does it leave you with one or two oak planks in invent when it's finished building as many as it can?

Well for example ill have 20 planks in inv at start of script. Then it builds two larders (16x planks) and i still have 4 left. Then it continuously try's to build over and over.

Here is what you should look into, the code has not been tested so just use it as a guide :)

package oaklarders;



import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

// Start script lvl 33 Construction

@ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0)

public class Oaklarders extends Script {


	@Override
	public void onStart() {
		log("Sit back and relax");
	}
	@Override
	public int onLoop() throws InterruptedException {
		
      /* OLD
		objects.closest("Larder space").interact("Build"); {
			sleep(1000);
		}
      */
      
      	if (!objects.closest("Larder space").interact("Build") {
          return; // If the interaction fails we return and it will try again.
        } else {
          // Do a conditional sleep here to make sure we dont spam interact.
          // The conditional sleep should check if the widget exists.
          new ConditionalSleep(3000) {
              @Override
              public boolean condition() {
          		  RS2Widget widget = widgets.get(458, 5, 4);
                  return widget.isVisiable();
              }
          }.sleep();
          
          if (widget == null || !widget.interact()) {
            return; // Here we return so if the widget is null or not shown and the 3000 ms has passed, we try again.
          }
          
        }
            
        // Repeat here with the remove function
		
		if(!inventory.contains("Oak plank")) {
		RS2Widget settings = widgets.get(548, 35); // Look at the api to see if you can find the settings in the tab to open it.
		if(settings == null) { // Here we changed it from not null to is equial to null so we dont wrap everything into this if statment :)
         return; // Then we can just return instead. 
        }
          
			settings.interact(); {
				sleep(200); // look above to see what to do instead of using sleeps like this.
				
			}
				RS2Widget house = widgets.get(261, 99);
				if(house != null) {
					house.interact(); {
						sleep(200); // look above to see what to do instead of using sleeps like this.
					}
				RS2Widget servant = widgets.get(370, 19, 0);
				if(servant != null) {
					servant.interact(); {
						sleep(200); // look above to see what to do instead of using sleeps like this.
					}
				RS2Widget unote = widgets.get(219, 1, 1);
				if(unote != null) {
					unote.interact(); {
						sleep(10000); // look above to see what to do instead of using sleeps like this.
					}
				}
				}
				}
		}
		}
		
		return(200);

		
	}	
	
	@Override 
    public void onExit() {
    	log("Thank's for using Oaklardersv1");
    }

}

	

// Make bot build and remove larders
// Make bot interact with butler to unote planks
// Make bot call servant if needed
// Add humanlike behavior sleeps etc

Thats just my quick gist of what you can improve, best of luck!

Edited by ItPoke
Refactored a tiny bit

6 minutes ago, Imthabawse said:

Well for example ill have 20 planks in inv at start of script. Then it builds two larders (16x planks) and i still have 4 left. Then it continuously try's to build over and over.

if getInvetory().getAmount(plank) > 5 

Edited by FuryShark

@Imthabawse thought so, your code is just checking that you have 1 plank in invent that's why it'll keep trying to build.

 

Furyshark has pointed you in the right direction.

  • Author

So I added @ItPoke's suggestion and now I'm getting multiple errors ? If anyone has any ideas where I went wrong (I'm sure most of you do you're all very knowledgeable) Any help would be greatly appreciated! It's a long stretched out mess of a code and I'm sure it could be shortened significantly but I R Nub so don't h8 :)

package oaklarders;



import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

// Start script lvl 33 Construction

@ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0)

public class Oaklarders extends Script {


	@Override
	public void onStart() {
		log("Sit back and relax");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		
		
		if (!objects.closest("Larder space").interact("Build")) {
			return;
		} else {
			
			new ConditionalSleep(3000) {
				@Override
				public boolean condition() {
		RS2Widget widget = widgets.get(458, 5, 4);
		return widget.isVisible();
		}
			}.sleep();
	
		if (widget == null || !widget.interact()) {
			return;
			}
		}
		if (!objects.closest("Larder").interact("Remove")) {
			return;
		} else {
			new ConditionalSleep(3000) {
				@Override
				public boolean condition() {
					RS2Widget widget = widgets.get(219, 1, 1);
					return widget.isVisible();
				}
		}.sleep();
         
		if (widget == null || !widget.interact()) {
			return;
			}
		
		if(getInventory().getAmount("Oak plank") > 4) {
		RS2Widget settings = widgets.get(548, 35);
		if(settings == null) {
			return;
		}
			settings.interact(); {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() {
						RS2Widget widget = widgets.get(548, 35);
						return widget.isVisible();
					}
				}.sleep();
				
				if (widget == null || !widget.interact()) {
					return;
				}
				
				RS2Widget house = widgets.get(261, 99);
				if(house != null) {
					house.interact(); {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() {
						RS2Widget widget = widgets.get(261, 99);
						return widget.isVisible();
					}
					}.sleep();
					if (widget == null || !widget.interact()) {
						return;
					}
				
					RS2Widget servant = widgets.get(370, 19, 0);
				if(servant != null) {
					servant.interact(); {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() {
						RS2Widget widget = widgets.get(370, 19, 0);
						return widget.isVisible();
					}
				}.sleep();
				if (widget == null || !widget.interact()) {
					return;
				}
					
				RS2Widget unote = widgets.get(219, 1, 1);
				if(unote != null) {
					unote.interact(); {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() {
						RS2Widget widget = widgets.get(219, 1, 1);
						return widget.isVisible();
					}
				}.sleep();
				if (widget == null || !widget.interact()) {
					return;
				}
						
				RS2Widget inventory = widgets.get(548, 51);
						if(inventory != null) {
							inventory.interact(); {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() {
						RS2Widget widget = widgets.get(548, 51);
						return widget.isVisible();
					}
				}.sleep();
				if (widget == null || !widget.interact()) {
					return;
				}
							}
						}
					}
				}
				}
				}
			}
		}
		}
		
			return(500);

			
	
	
	@Override 
    public void onExit() {
    	log("Thank's for using Oaklardersv1");
    }

}

	

// Make bot build and remove larders
// Make bot interact with butler to unote planks
// Make bot call servant if needed
// Add humanlike behavior sleeps etc

 

  • Author
59 minutes ago, ItPoke said:

Format the code better and make sure you don't have too many }

if (widget == null || !widget.interact()) { 

^This was one of my first errors any ideas? Also with return; I get error: "This method must return a result of type int" ? So could I just make "return 0;" ?

Edited by Imthabawse

35 minutes ago, Imthabawse said:

if (widget == null || !widget.interact()) { 

^This was one of my first errors any ideas? Also with return; I get error: "This method must return a result of type int" ? So could I just make "return 0;" ?

I just told you to clean the code so you can make sure that you have your brackets correct....
 

if (widget == null || !widget.interact()) {
    return;
  } // <- Why is there a curly bracket here?!
}

 

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.