Jump to content

getAmount() Problem


Recommended Posts

Posted

Facing camera to NPC: getCamera().toEntity(NPC);

Is your jug of water noted? inventory.getItem() returns the first found item, so you could be getting an unnoted one (hence getting 1), and none should very well be 0 as there are 0 jugs.

 

 

No they are not noted. I'm trying to get the number of Jug of water in my inventory.

Posted (edited)

 

The API states that #getItem() returns a type of item. The method you want is ItemContainer#getAmount(String ... items)

 

Usage:

int amt = getInventory().getAmount("Jug of Water");

 

 

Thanks it's working!

 

Also I'm having one last issue with the door.

 

My current code to handle the door is this:

        if(!myPlayer().isMoving()) {
            RS2Object largeDoor = objects.closest(new Filter<RS2Object>() {
                @Override
                public boolean match(RS2Object rs2Object) {
                    return rs2Object != null && rs2Object.getName().equals("Large door") && rs2Object.getPosition().equals(new Position(3293,3166,0));
                }
            });

            if(largeDoor != null){
                getCamera().toEntity(largeDoor);
                if(largeDoor.isVisible())
                    try {
                        largeDoor.interact("Open");
                        log("Opening the door");
                        return true;
                    }catch(Exception e){
                        log("Door is already open");
                        return false;
                    }
            }
        }

The bot isn't Facing the camera on the door and doesn't interact with it.

 

Thanks for helping me smile.png

Edited by frozen8
Posted

Thanks it's working!

 

Also I'm having one last issue with the door.

 

My current code to handle the door is this:

        if(!myPlayer().isMoving()) {
            RS2Object largeDoor = objects.closest(new Filter<RS2Object>() {
                @Override
                public boolean match(RS2Object rs2Object) {
                    return rs2Object != null && rs2Object.getName().equals("Large door") && rs2Object.getPosition().equals(new Position(3293,3166,0));
                }
            });

            if(largeDoor != null){
                getCamera().toEntity(largeDoor);
                if(largeDoor.isVisible())
                    try {
                        largeDoor.interact("Open");
                        log("Opening the door");
                        return true;
                    }catch(Exception e){
                        log("Door is already open");
                        return false;
                    }
            }
        }

The bot isn't Facing the camera on the door and doesn't interact with it.

 

Thanks for helping me smile.png

 

I don't think Camera#toEntity accepts an RS2Object as a parameter (could be wrong).

Instead, use Entity for objects and NPC for NPCs:

Entity door = getObjects().closest(new Filter<Entity>() {
 //match code
});

if (!door.isVisible()) {
    getCamera().toEntity(door);
}

if (!door.hasAction("Open")) {
    log("Door is open");
    return false;
}
door.interact("Open");
Position p = door.getPosition();
//Conditional sleep -> check objects at position p, see if they have action "Close"
log("Door should be open");
return true;

 

Posted

I don't think Camera#toEntity accepts an RS2Object as a parameter (could be wrong).

Instead, use Entity for objects and NPC for NPCs:

Entity door = getObjects().closest(new Filter<Entity>() {
 //match code
});

if (!door.isVisible()) {
    getCamera().toEntity(door);
}

if (!door.hasAction("Open")) {
    log("Door is open");
    return false;
}
door.interact("Open");
Position p = door.getPosition();
//Conditional sleep -> check objects at position p, see if they have action "Close"
log("Door should be open");
return true;
Rs2 object extends entity so it's fine lol.

@op leave it as rs2 object. Also the code seems fine. Try to see if the rs2 object is null. If it is it will explain why it doesn't interact

Posted

I did some modifications now and it seems to be working fine.

 

Also now another minor problem :)

When I use that path:
 

    private final Position[] pathToHassan =
            {
                    new Position(3275, 3169, 0),
                    new Position(3279, 3177, 0),
                    new Position(2388, 3180, 0),
                    new Position(3291, 3172, 0),
                    new Position(3292, 3167, 0)
            };

Sometime the bot click a couple time at the same position for some weird reason.

 

I use this to go to a certain location:

localWalker.walkPath(pathToHassan);


Thanks a lot guys for helping me out so much! :)

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