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.

Checking if a door is closed and open if it's closed

Featured Replies

Hello

So I'm kinda stuck in making my new script, I can't figure out how to check if the door is closed and open it if it's closed.

Please help me. :(

you could also create an area using one tile. Check that one tile to see if a door is null or not. Because the position of a tile changes when you open and close the door.

 

 

Edited by josedpay

  • Author
Arrays.asList(door.getDefinition().getActions()).contains("Open");

 

Care to elaborate?

if(door.getDefinition().getActions()[0].equals("Open")){
door.interact("Open);
}

I can't get this to work, where do I add the id/name of the door I want to open?

If you are using the code for one specific door at a specific location you could create a class to hold the name and position, such as this: 

package com.scripts.mrsdefnerd.dnfishcooker.utils;

import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.RS2Object;

import com.scripts.mrsdefnerd.dnfishcooker.core.Main;

public abstract class ObstacleObject {
	
	private String name;
	private Position location;
	public ObstacleObject(String name, Position location) {
		this.name = name;
		this.location = location;
	}
	
	public final String getName() {
		return name;
	}
	
	public final Position getLocation() {
		return location;
	}
	
	public final RS2Object get(Script ctx) {
		for (RS2Object object : ctx.closestObjectListForName(getName()))
			if (object != null && object.getPosition().equals(getLocation()))
				return object;
		return null;
	}
	
	public abstract boolean validate(Script ctx);

}

Declare this somewhere (I guess you can just declare it at the top of the class):

ObstacleObject door; 

Then you can do something like this in you startup method:

door = new ObstacleObject("Door", new Position(2816, 3438, 0)) {

		@Override
		public boolean validate(Script ctx) {
			return this.get(ctx) != null && !this.get(ctx).getDefinition().getActions()[1].toLowerCase().contains("close");
		}
		
	}

What the above code does is that it overrides the validate method to your custom prefference (it will check if the object at that position is not null, and make sure that the object does not have an action that contains close). 

 

EDIT: The "Door" is the name of the object, the new Position() is the position of the object, and the validate is the requirements for the object to retrieved (This way you can support most objects)

 

This is probably a bit overdone, but if you have to handle alot of different objects I guess its a good way to do it.

 

To use the code simply do (I am assuming you are calling the door class from the class that extends script):

RS2Object doorObject = door.get(this);

Edited by Mrsdefnerd

^^ nobo above me said it :D :D

You use pathfinder and clear door/obstacle flags and check for door/obstacle on the path. If one exists and is operable then it opens it. This is how AIO scripts handle obstacles without the actual position of them.

You use pathfinder and clear door/obstacle flags and check for door/obstacle on the path. If one exists and is operable then it opens it. This is how AIO scripts handle obstacles without the actual position of them.

Yep, but its not really needed if you know what objects you are interacting with (lets say a specific door)

Yep, but its not really needed if you know what objects you are interacting with (lets say a specific door)

	public final RS2Object get(Script ctx) {
		for (RS2Object object : ctx.closestObjectListForName(getName()))
			if (object != null && object.getPosition().equals(getLocation()))
				return object;
		return null;
	}
	

Just a little enhancement by me:

public WallObject getWallObjectOnPosition(Position position, String... names) {
        try {

            if (position == null) {
                return null;
            }
            if (client.getCurrentRegion() == null || client.getCurrentRegion().instance == null || client.getCurrentRegion().instance.getTiles() == null) {
                return null;
            }

            int localX = position.getLocalX(bot);
            int localY = position.getLocalY(bot);
            if (localX <= 104 && localY <= 104 && localX >= 0 && localY >= 0) {
                if (client.getCurrentRegion().instance.getTiles()[position.getZ()][localX][localY] == null) {
                    return null;
                }
                XWallObject wallObject = client.getCurrentRegion().instance.getTiles()[position.getZ()][localX][localY].getWallObject();
                WallObject wrap = WallObject.wrap(wallObject, position.getZ());

                if (names.length == 0 || Arrays.asList(names).contains(wrap.getDefinition().getName())) {
                    return wallObject == null ? null : wrap;
                }

            }
        } catch (Exception ignored) {
        }
        return null;
    }

well, closed door and a open door has 2 different ID's wouldnt it be possible to check if the open door id exist, to run trough, else just to open door :D?

Guest
This topic is now closed to further replies.

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.