Jump to content

getAmount() Problem


frozen8

Recommended Posts

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.

Link to comment
Share on other sites

 

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

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;

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! :)

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