Jump to content

Trying to get amount of Ground items from an area or position


Recommended Posts

Posted

Can't seem to get this working correctly. The value (groundTinderbox) always seems to come back as 1 no matter how many ground items there are as long as it isn't 0. I'm almost certain it could be because it isn't a stackable item, but not sure. Here is the snippet:

    public void shouldPickUpTinderboxes() throws InterruptedException
    {
        GroundItem groundTinderbox = groundItems.closest(areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf, "Tinderbox");
        int emptyInventorySlots = inventory.getEmptySlots();

        if (!boolShouldPickUpTinderboxes && !boolShouldSpeakToWiseOldMan && !boolShouldBank && stringMethodSelector.contains("tinderbox_picker") && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(myPlayer()) && groundTinderbox != null && groundTinderbox.getAmount() >= emptyInventorySlots)
        {
            boolShouldPickUpTinderboxes = true;
            log("Attempting to pick tinderboxes.");
        }
        if (boolShouldPickUpTinderboxes)
        {
            if (boolShouldSpeakToWiseOldMan || boolShouldBank || !stringMethodSelector.contains("tinderbox_picker") || !areaDraynorVillageWiseOldMan.contains(myPlayer()) || groundTinderbox.getAmount() == 0 || getInventory().isFull())
            {
                boolShouldPickUpTinderboxes = false;
                log("Tinderboxes picked.");
            }
        }
    }

 

Posted

@FushigiBot Each item is a separate entity, you probably need to do something like this and use .size() for the amount
 

    public List<GroundItem> getAllTinderboxes()
    {
        return getGroundItems()
                .getAll()
                .stream()
                .filter(g -> g.getName().equals("Tinderbox")
                        && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(g.getPosition())
                        && getMap().canReach(g))
                .collect(Collectors.toList());
    }

 

Posted
15 minutes ago, Gunman said:

@FushigiBot Each item is a separate entity, you probably need to do something like this and use .size() for the amount
 

    public List<GroundItem> getAllTinderboxes()
    {
        return getGroundItems()
                .getAll()
                .stream()
                .filter(g -> g.getName().equals("Tinderbox")
                        && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(g.getPosition())
                        && getMap().canReach(g))
                .collect(Collectors.toList());
    }

 

Yikes, thanks. Will try that now.

Posted

It worked. Thanks!

 

    public void shouldPickUpTinderboxes() throws InterruptedException
    {
        List<GroundItem> allTinderboxes = getAllTinderboxes();
        int emptyInventorySlots = inventory.getEmptySlots();

        if (!boolShouldPickUpTinderboxes && !boolShouldSpeakToWiseOldMan && !boolShouldBank && stringMethodSelector.contains("tinderbox_picker") && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(myPlayer()) && !allTinderboxes.isEmpty() && allTinderboxes.size() >= emptyInventorySlots)
        {
            boolShouldPickUpTinderboxes = true;
            log("Attempting to pick tinderboxes.");
        }
        if (boolShouldPickUpTinderboxes)
        {
            if (boolShouldSpeakToWiseOldMan || boolShouldBank || !stringMethodSelector.contains("tinderbox_picker") || !areaDraynorVillageWiseOldMan.contains(myPlayer()) || allTinderboxes.isEmpty() || getInventory().isFull())
            {
                boolShouldPickUpTinderboxes = false;
                log("Tinderboxes picked.");
            }
        }
    }

    public List<GroundItem> getAllTinderboxes()
    {
        return getGroundItems()
                .getAll()
                .stream()
                .filter(g -> g.getName().equals("Tinderbox")
                        && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(g.getPosition())
                        && getMap().canReach(g))
                .collect(Collectors.toList());
    }

 

Posted (edited)
16 hours ago, FushigiBot said:

Can't seem to get this working correctly. The value (groundTinderbox) always seems to come back as 1 no matter how many ground items there are as long as it isn't 0. I'm almost certain it could be because it isn't a stackable item, but not sure. Here is the snippet:

    public void shouldPickUpTinderboxes() throws InterruptedException
    {
        GroundItem groundTinderbox = groundItems.closest(areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf, "Tinderbox");
        int emptyInventorySlots = inventory.getEmptySlots();

        if (!boolShouldPickUpTinderboxes && !boolShouldSpeakToWiseOldMan && !boolShouldBank && stringMethodSelector.contains("tinderbox_picker") && areaDraynorVillageWiseOldManFrontOfTinderboxBookshelf.contains(myPlayer()) && groundTinderbox != null && groundTinderbox.getAmount() >= emptyInventorySlots)
        {
            boolShouldPickUpTinderboxes = true;
            log("Attempting to pick tinderboxes.");
        }
        if (boolShouldPickUpTinderboxes)
        {
            if (boolShouldSpeakToWiseOldMan || boolShouldBank || !stringMethodSelector.contains("tinderbox_picker") || !areaDraynorVillageWiseOldMan.contains(myPlayer()) || groundTinderbox.getAmount() == 0 || getInventory().isFull())
            {
                boolShouldPickUpTinderboxes = false;
                log("Tinderboxes picked.");
            }
        }
    }

 

Well the method used here is "groundItems.closest" so you will only get the one that's the closest to the player :)
What gunman said is the perfect solution, just get all and filter out what you need ^^

Edited by Khaleesi

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