Jump to content

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


FushigiBot

Recommended Posts

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.");
            }
        }
    }

 

Link to comment
Share on other sites

@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());
    }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());
    }

 

Link to comment
Share on other sites

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