Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Bug Bank.depositInventory(); call clicks Bank Search button

Joined
Jun 25, 2019
Messages
24
Just like the title says the below code sometimes seems to get stuck and just repeatedly click the bank search button instead of deposit all:

Code:
 @Override
    public void execute() {
        if (useRanged) {
            if (Inventory.contains("Iron arrow")) {
                Inventory.getItems("Iron arrow").first().click();
            }
        }

        if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
            Bank.open();
        }
        if (Bank.isOpen()) {
            // deposit loot
            for (SpriteItem item : Inventory.getItems().asList()) {
                if (!requiredItems().keySet().contains(item.getDefinition().getName())) {
                    Bank.depositInventory();
                }
            }
            //withdraw items
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.withdraw(item, itemAmount);
                }
            });
            // deposit if items overdrawn
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getItems(item).size() == 0) {
                    return;
                } else if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.depositInventory();
                }
            });
        }
        if (Inventory.isFull()) {
            Bank.close();
        }
    }
 
Making nice things
Joined
Jun 7, 2019
Messages
39
you are calling .despoitInventory() while looping over all your inventory items. That does not seem to be correct.
Ideally you only want to do 1 action per bot iteration.It might be as easy as having "return;" right agter your bank.depositInv call.
Also when you do something like this you might want to use breaks and wait for the inventory to be deposited
 
Joined
Jun 25, 2019
Messages
24
you are calling .despoitInventory() while looping over all your inventory items. That does not seem to be correct.
Ideally you only want to do 1 action per bot iteration.It might be as easy as having "return;" right agter your bank.depositInv call.
Also when you do something like this you might want to use breaks and wait for the inventory to be deposited

yeah cheers, not surprised its not working if im calling it multiple times in a for loop. Does anyone have any example banking code, my withdrawing still seems to be buggy. Only when I run 2 bots for some reason?

Code:
    public void execute() {
        if (useRanged) {
            if (Inventory.contains("Iron arrow")) {
                Inventory.getItems("Iron arrow").first().click();
            }
        }

        if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
            Bank.open();
        }
        if (Bank.isOpen()) {
            // deposit loot
            SpriteItem deposit = Inventory.getItems().stream()
                    .filter(item -> !requiredItems().keySet().contains(item.getDefinition().getName())).findFirst().orElse(null);
            getLogger().info("deposit " + deposit);
            if (deposit != null) {
                getLogger().info("Depositing loot");
                Bank.depositInventory();
            }
            //withdraw items
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.withdraw(item, itemAmount);
                    getLogger().info("Withdrawing " + item);
                }
            });
            // deposit if items overdrawn
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getItems(item).size() == 0) {
                    return;
                } else if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.depositInventory();
                    getLogger().info("Depositing overdrawn item " + item);
                }
            });
        }
        if (Inventory.isFull()) {
            Bank.close();
        }
    }
 
Making nice things
Joined
Jun 7, 2019
Messages
39
yeah cheers, not surprised its not working if im calling it multiple times in a for loop. Does anyone have any example banking code, my withdrawing still seems to be buggy. Only when I run 2 bots for some reason?

Code:
    public void execute() {
        if (useRanged) {
            if (Inventory.contains("Iron arrow")) {
                Inventory.getItems("Iron arrow").first().click();
            }
        }

        if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
            Bank.open();
        }
        if (Bank.isOpen()) {
            // deposit loot
            SpriteItem deposit = Inventory.getItems().stream()
                    .filter(item -> !requiredItems().keySet().contains(item.getDefinition().getName())).findFirst().orElse(null);
            getLogger().info("deposit " + deposit);
            if (deposit != null) {
                getLogger().info("Depositing loot");
                Bank.depositInventory();
            }
            //withdraw items
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.withdraw(item, itemAmount);
                    getLogger().info("Withdrawing " + item);
                }
            });
            // deposit if items overdrawn
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getItems(item).size() == 0) {
                    return;
                } else if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.depositInventory();
                    getLogger().info("Depositing overdrawn item " + item);
                }
            });
        }
        if (Inventory.isFull()) {
            Bank.close();
        }
    }

I actually didnt really want to give you this example because sometimes you just have to try out what someone says instead of begging for a piece of code.

Please use breaks and returns; check conditions every loop. This will probably fix most of your bugs.

This is the example i gave you above

Code:
if (!Inventory.isEmpty() && !Inventory.contains(id)) {
                Bank.depositInventory();
                Execution.delayUntil(() -> Inventory.isEmpty(), 500, 1500);
                return;
}

Do this the same as withdraw :)

I hope i helped you a little.
(untested code ofcourse, did this 5 minutes before i go to bed :) )
 
Joined
Jun 25, 2019
Messages
24
I actually didnt really want to give you this example because sometimes you just have to try out what someone says instead of begging for a piece of code.

Please use breaks and returns; check conditions every loop. This will probably fix most of your bugs.

This is the example i gave you above

Code:
if (!Inventory.isEmpty() && !Inventory.contains(id)) {
                Bank.depositInventory();
                Execution.delayUntil(() -> Inventory.isEmpty(), 500, 1500);
                return;
}

Do this the same as withdraw :)

I hope i helped you a little.
(untested code ofcourse, did this 5 minutes before i go to bed :) )

thanks I have tried returning in a few more places. I am still a little bit confused about how to return out of a for loop. The example you gave works great if you are only withdrawing 1 item. I have a hashmap of a few items that I loop through and withdraw. Not sure how to return out of execute(){} after each hashmap.foreach() loop? Or if its something I should even be trying to loop out of?

Code:
package com.thesmeg.bots.fleshcrawler.leaf;

import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.tree.LeafTask;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class GetSupplies extends LeafTask {

    public final Map<String, Integer> requiredItems() {
        return Collections.unmodifiableMap(Stream.of(
                new AbstractMap.SimpleEntry<>("Pike", 25),
                new AbstractMap.SimpleEntry<>("Fire rune", 1),
                new AbstractMap.SimpleEntry<>("Air rune", 3),
                new AbstractMap.SimpleEntry<>("Law rune", 1)
        ).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())));
    }

    Boolean useRanged = true;

    @Override
    public void execute() {
        if (useRanged) {
            if (Inventory.contains("Iron arrow")) {
                Inventory.getItems("Iron arrow").first().click();
                return;
            }
        }

        if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
            Bank.open();
            return;
        }
        if (Bank.isOpen()) {
            // deposit loot
            SpriteItem deposit = Inventory.getItems().stream()
                    .filter(item -> !requiredItems().keySet().contains(item.getDefinition().getName())).findFirst().orElse(null);
            getLogger().info("deposit " + deposit);
            if (deposit != null) {
                getLogger().info("Depositing loot");
                Bank.depositInventory();
                return;
            }
            //withdraw items
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getQuantity(item) != itemAmount) {
                    getLogger().info("Withdrawing " + item);
                    Bank.withdraw(item, itemAmount);
                    Execution.delayUntil(() -> Inventory.contains(item), () -> false, 50, 500, 1500);
                }
            });
            // deposit if items overdrawn
            requiredItems().forEach((item, itemAmount) -> {
                if (Inventory.getItems(item).size() == 0) {
                    return;
                } else if (Inventory.getQuantity(item) != itemAmount) {
                    Bank.depositInventory();
                    getLogger().info("Depositing overdrawn item " + item);
                }
            });
        }
        if (Inventory.isFull()) {
            Bank.close();
        }
    }
}
 
Last edited:
Top