Jump to content

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


Imthabawse

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?!
}

 

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