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.

[Script Help Please] Construction script

Featured Replies

Hi all,

Questions:

  • The script runs fine if I start it with the Larder space is empty, but if I start it with something in the larder space, it doesn't do anything. Why?
  • Do I have to declare the RS2Objects over and over again, or will it recognize if I declare it once at the beginning of the script?
package core;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;


import java.awt.*;


@ScriptManifest(name = "Construction Lite", version = 1, author = "Marcus", logo = "", info = "Creates oak larders")


public class Main extends Script {
	

    @Override
    public void onStart() throws InterruptedException {
        getExperienceTracker().start(Skill.CONSTRUCTION);
    }
    
    

    @Override
    public int onLoop() throws InterruptedException {

        if (hasPlanks()) {
            makeLarder();
        } else if (hasLarder()) {
            removeLarder(); 
        }
        return 700;
    }

    public boolean hasPlanks() {
        return (inventory.contains(8794,2347,995,8779) &&
        	   (inventory.contains(8778) && inventory.getAmount(8778) >= 8));
    }

    public void makeLarder() throws InterruptedException {
    	
		RS2Object larder = getObjects().closest("Larder space");

        if  (larder != null); {
        	 larder.interact("Build");
        	 sleep(random(1600, 2000));
        	 keyboard.typeString("2");
        	 sleep(random(750, 900));
            new ConditionalSleep(1800, 100) {
                @Override
                public boolean condition() throws InterruptedException {
                    return getInventory().isEmptyExcept(8794,2347,995,8779);
                }
            }.sleep();
        }
    }
    
    public boolean hasLarder() {
    	
		RS2Object oaklarder = getObjects().closest("Larder");
		
        return (oaklarder != null);
    }

    public void removeLarder() throws InterruptedException {
    	
		RS2Object oaklarder = getObjects().closest("Larder");

        if  (oaklarder != null); {
        	 oaklarder.interact("Remove");
        	 sleep(random(1600, 2000));
        	 keyboard.typeString("1");
        	 sleep(random(750, 900));
        }
    }
    

    @Override
    public void onPaint(Graphics2D paint) {
        int	cXp = getExperienceTracker().getGainedXP(Skill.CONSTRUCTION);
        int cXpph = getExperienceTracker().getGainedXPPerHour(Skill.CONSTRUCTION);



        super.onPaint(paint);
        paint.drawString("Construction XP: " + cXp, 387, 328);
        paint.drawString("Construction XP/ph: " + cXpph, 387, 313);

    }
}

 

Edited by Lol_marcus

Quote

The script runs fine if I start it with the Larder space is empty, but if I start it with something in the larder space, it doesn't do anything. Why?

I do not understand your question. What do you mean by "start it with the larder space empty". You need to be more specific when posting large sections of code.

Quote

Do I have to declare the RS2Objects over and over again, or will it recognize if I declare it once at the beginning of the script?

Typically an object should be initialized only within the scope that is needed. You should look into Java Variable Scope which will further explain when to declare variables and how their access works.

Lastly, I noticed you're using methods that return a boolean but never check the return value. You should put methods with return type boolean into an if else in-case they fail.

if(oaklarder.interact("Remove")) {
	// the interaction was sucessfull and now we should do a CONDITIONAL sleep
} else {
	// you don't neccesarily need an else, but you can do error checking here!
	// if you don't use the else the loop will just reiterate and hopefully the interaction will be successful.
}

 

RS2Object larder = getObjects().closest(o -> o.getName().equals("Object name here"));
if (larder != null)
    if (larder.hasAction("Build"){
        //add your building code here
    } else if (larder.hasAction("Remove"){
        //add your remove larder code here
    }
  • Author
3 hours ago, ExtraBotz said:

I do not understand your question. What do you mean by "start it with the larder space empty". You need to be more specific when posting large sections of code.

Typically an object should be initialized only within the scope that is needed. You should look into Java Variable Scope which will further explain when to declare variables and how their access works.

Lastly, I noticed you're using methods that return a boolean but never check the return value. You should put methods with return type boolean into an if else in-case they fail.


if(oaklarder.interact("Remove")) {
	// the interaction was sucessfull and now we should do a CONDITIONAL sleep
} else {
	// you don't neccesarily need an else, but you can do error checking here!
	// if you don't use the else the loop will just reiterate and hopefully the interaction will be successful.
}

 

Let me try to explain better.

So, if the first statement isn't being met, it's shutting down. What I can't figure out is, if the larder has already been made, why isn't it going to the "else" statement? This would happen if for example someone started the script with the larder already made in the house, does that make sense?

    public int onLoop() throws InterruptedException {

        if (hasPlanks()) {
            makeLarder();
        } else if (hasLarder()) {
            removeLarder(); 
24 minutes ago, progamerz said:

RS2Object larder = getObjects().closest(o -> o.getName().equals("Object name here"));
if (larder != null)
    if (larder.hasAction("Build"){
        //add your building code here
    } else if (larder.hasAction("Remove"){
        //add your remove larder code here
    }

Oh wow. I didn't even know there was that function! :o I'll try to implement this, could be the solution I was looking for! Thanks

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.