1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Developer Support' started by theSmeg, Aug 6, 2019.

  1. theSmeg

    Joined:
    Jun 25, 2019
    Messages:
    24
    Likes Received:
    5
    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 (Text):
    1.  @Override
    2.     public void execute() {
    3.         if (useRanged) {
    4.             if (Inventory.contains("Iron arrow")) {
    5.                 Inventory.getItems("Iron arrow").first().click();
    6.             }
    7.         }
    8.  
    9.         if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
    10.             Bank.open();
    11.         }
    12.         if (Bank.isOpen()) {
    13.             // deposit loot
    14.             for (SpriteItem item : Inventory.getItems().asList()) {
    15.                 if (!requiredItems().keySet().contains(item.getDefinition().getName())) {
    16.                     Bank.depositInventory();
    17.                 }
    18.             }
    19.             //withdraw items
    20.             requiredItems().forEach((item, itemAmount) -> {
    21.                 if (Inventory.getQuantity(item) != itemAmount) {
    22.                     Bank.withdraw(item, itemAmount);
    23.                 }
    24.             });
    25.             // deposit if items overdrawn
    26.             requiredItems().forEach((item, itemAmount) -> {
    27.                 if (Inventory.getItems(item).size() == 0) {
    28.                     return;
    29.                 } else if (Inventory.getQuantity(item) != itemAmount) {
    30.                     Bank.depositInventory();
    31.                 }
    32.             });
    33.         }
    34.         if (Inventory.isFull()) {
    35.             Bank.close();
    36.         }
    37.     }
     
  2. CoreBot

    CoreBot Making nice things

    Joined:
    Jun 7, 2019
    Messages:
    39
    Likes Received:
    21
    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
     
    Fabreze likes this.
  3. theSmeg

    Joined:
    Jun 25, 2019
    Messages:
    24
    Likes Received:
    5
    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 (Text):
    1.     public void execute() {
    2.         if (useRanged) {
    3.             if (Inventory.contains("Iron arrow")) {
    4.                 Inventory.getItems("Iron arrow").first().click();
    5.             }
    6.         }
    7.  
    8.         if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
    9.             Bank.open();
    10.         }
    11.         if (Bank.isOpen()) {
    12.             // deposit loot
    13.             SpriteItem deposit = Inventory.getItems().stream()
    14.                     .filter(item -> !requiredItems().keySet().contains(item.getDefinition().getName())).findFirst().orElse(null);
    15.             getLogger().info("deposit " + deposit);
    16.             if (deposit != null) {
    17.                 getLogger().info("Depositing loot");
    18.                 Bank.depositInventory();
    19.             }
    20.             //withdraw items
    21.             requiredItems().forEach((item, itemAmount) -> {
    22.                 if (Inventory.getQuantity(item) != itemAmount) {
    23.                     Bank.withdraw(item, itemAmount);
    24.                     getLogger().info("Withdrawing " + item);
    25.                 }
    26.             });
    27.             // deposit if items overdrawn
    28.             requiredItems().forEach((item, itemAmount) -> {
    29.                 if (Inventory.getItems(item).size() == 0) {
    30.                     return;
    31.                 } else if (Inventory.getQuantity(item) != itemAmount) {
    32.                     Bank.depositInventory();
    33.                     getLogger().info("Depositing overdrawn item " + item);
    34.                 }
    35.             });
    36.         }
    37.         if (Inventory.isFull()) {
    38.             Bank.close();
    39.         }
    40.     }
     
  4. CoreBot

    CoreBot Making nice things

    Joined:
    Jun 7, 2019
    Messages:
    39
    Likes Received:
    21
    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 (Text):
    1.  
    2. if (!Inventory.isEmpty() && !Inventory.contains(id)) {
    3.                 Bank.depositInventory();
    4.                 Execution.delayUntil(() -> Inventory.isEmpty(), 500, 1500);
    5.                 return;
    6. }
    7.  
    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 :) )
     
  5. theSmeg

    Joined:
    Jun 25, 2019
    Messages:
    24
    Likes Received:
    5
    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 (Text):
    1. package com.thesmeg.bots.fleshcrawler.leaf;
    2.  
    3. import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    5. import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
    6. import com.runemate.game.api.script.Execution;
    7. import com.runemate.game.api.script.framework.tree.LeafTask;
    8.  
    9. import java.util.*;
    10. import java.util.stream.Collectors;
    11. import java.util.stream.Stream;
    12.  
    13. public class GetSupplies extends LeafTask {
    14.  
    15.     public final Map<String, Integer> requiredItems() {
    16.         return Collections.unmodifiableMap(Stream.of(
    17.                 new AbstractMap.SimpleEntry<>("Pike", 25),
    18.                 new AbstractMap.SimpleEntry<>("Fire rune", 1),
    19.                 new AbstractMap.SimpleEntry<>("Air rune", 3),
    20.                 new AbstractMap.SimpleEntry<>("Law rune", 1)
    21.         ).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())));
    22.     }
    23.  
    24.     Boolean useRanged = true;
    25.  
    26.     @Override
    27.     public void execute() {
    28.         if (useRanged) {
    29.             if (Inventory.contains("Iron arrow")) {
    30.                 Inventory.getItems("Iron arrow").first().click();
    31.                 return;
    32.             }
    33.         }
    34.  
    35.         if (!Bank.isOpen() && !Inventory.contains("Iron arrow")) {
    36.             Bank.open();
    37.             return;
    38.         }
    39.         if (Bank.isOpen()) {
    40.             // deposit loot
    41.             SpriteItem deposit = Inventory.getItems().stream()
    42.                     .filter(item -> !requiredItems().keySet().contains(item.getDefinition().getName())).findFirst().orElse(null);
    43.             getLogger().info("deposit " + deposit);
    44.             if (deposit != null) {
    45.                 getLogger().info("Depositing loot");
    46.                 Bank.depositInventory();
    47.                 return;
    48.             }
    49.             //withdraw items
    50.             requiredItems().forEach((item, itemAmount) -> {
    51.                 if (Inventory.getQuantity(item) != itemAmount) {
    52.                     getLogger().info("Withdrawing " + item);
    53.                     Bank.withdraw(item, itemAmount);
    54.                     Execution.delayUntil(() -> Inventory.contains(item), () -> false, 50, 500, 1500);
    55.                 }
    56.             });
    57.             // deposit if items overdrawn
    58.             requiredItems().forEach((item, itemAmount) -> {
    59.                 if (Inventory.getItems(item).size() == 0) {
    60.                     return;
    61.                 } else if (Inventory.getQuantity(item) != itemAmount) {
    62.                     Bank.depositInventory();
    63.                     getLogger().info("Depositing overdrawn item " + item);
    64.                 }
    65.             });
    66.         }
    67.         if (Inventory.isFull()) {
    68.             Bank.close();
    69.         }
    70.     }
    71. }
    72.  
     
    #5 theSmeg, Aug 12, 2019
    Last edited: Aug 13, 2019

Share This Page

Loading...