Jump to content

doorHandler not behaving as expected


Recommended Posts

Posted (edited)

Capture.png

 

when I try and leave the room with the spining wheel, doorHandler sometimes clicks the red door..It not a big deal, but it's happening a little tooo often imo. Im wondering how i can stop it from clicking the red door as it't not at all in my path. 

while (!map.canReach(STAIRS.getRandomPosition())) {
 doorHandler.handleNextObstacle(STAIRS);
 ConditionalSleep(10000);
}

I triple checked the coooords for my STAIRS area and the door is not inside the area! 

Edited by ni562
Posted (edited)

Capture.png

 

when I try and leave the room with the spining wheel, doorHandler sometimes clicks the red door..It not a big deal, but it's happening a little tooo often imo. Im wondering how i can stop it from clicking the red door as it't not at all in my path. 

while (!map.canReach(STAIRS.getRandomPosition())) {
 doorHandler.handleNextObstacle(STAIRS);
 ConditionalSleep(10000);
}

I triple checked the coooords for my STAIRS area and the door is not inside the area! 

 

 

You could try this as an alternative solution to DoorHandler, you pass the getDoor method an area that contains the door to distinguish it from other doors:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class DoorHelper {

    private final Script S;
    
    public DoorHelper(final Script S){
        
        this.S = S;
    }
    
    public RS2Object getDoor(Area doorArea){

        //noinspection unchecked
        return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
    }

    public boolean doorIsClosed(RS2Object door){

        return door.hasAction("Open");
    }

    public void openDoor(RS2Object door){

        if(door != null && doorIsClosed(door)){

            door.interact("Open");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !doorIsClosed(door);
                }
            }.sleep();
        }
    }
}
Edited by Explv
Posted

 

You could try this as an alternative solution to DoorHandler, you pass the getDoor method an area that contains the door to distinguish it from other doors:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class DoorHelper {

    private final Script S;
    
    public DoorHelper(final Script S){
        
        this.S = S;
    }
    
    public RS2Object getDoor(Area doorArea){

        //noinspection unchecked
        return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
    }

    public boolean doorIsClosed(RS2Object door){

        return door.hasAction("Open");
    }

    public void openDoor(RS2Object door){

        if(door != null && doorIsClosed(door)){

            door.interact("Open");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !doorIsClosed(door);
                }
            }.sleep();
        }
    }
}

 

Wow i'll try that! How can i pass it a Script object? that it the only part i'm unsure about.. 

Posted

 

You could try this as an alternative solution to DoorHandler, you pass the getDoor method an area that contains the door to distinguish it from other doors:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class DoorHelper {

    private final Script S;
    
    public DoorHelper(final Script S){
        
        this.S = S;
    }
    
    public RS2Object getDoor(Area doorArea){

        //noinspection unchecked
        return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
    }

    public boolean doorIsClosed(RS2Object door){

        return door.hasAction("Open");
    }

    public void openDoor(RS2Object door){

        if(door != null && doorIsClosed(door)){

            door.interact("Open");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !doorIsClosed(door);
                }
            }.sleep();
        }
    }
}
public RS2Object getDoor(Area doorArea){

//noinspection unchecked
return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
}

always returns null, any idea why? 

Posted

 

You could try this as an alternative solution to DoorHandler, you pass the getDoor method an area that contains the door to distinguish it from other doors:

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class DoorHelper {

    private final Script S;
    
    public DoorHelper(final Script S){
        
        this.S = S;
    }
    
    public RS2Object getDoor(Area doorArea){

        //noinspection unchecked
        return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
    }

    public boolean doorIsClosed(RS2Object door){

        return door.hasAction("Open");
    }

    public void openDoor(RS2Object door){

        if(door != null && doorIsClosed(door)){

            door.interact("Open");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !doorIsClosed(door);
                }
            }.sleep();
        }
    }
}

Why is it that the ConditionalSleep in the openDoor() method seems to always wait the full 5 seconds and not stop the sleep when the door is open like I would expect it to?

Posted

Why is it that the ConditionalSleep in the openDoor() method seems to always wait the full 5 seconds and not stop the sleep when the door is open like I would expect it to?

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class DoorHelper {

    private final Script S;
    
    public DoorHelper(final Script S){
        
        this.S = S;
    }
    
    public RS2Object getDoor(Area doorArea){

        //noinspection unchecked
        return S.getObjects().closest(obj -> obj.getName().equals("Door") && doorArea.contains(obj));
    }

    public boolean doorIsClosed(RS2Object door){

        return door.hasAction("Open");
    }

    public void openDoor(Area doorArea){

        RS2Object door = getDoor(doorArea);

        if(door != null && doorIsClosed(door)){

            door.interact("Open");
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !doorIsClosed(getDoor(doorArea));
                }
            }.sleep();
        }
    }
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...