Jump to content

need some help


MarWo22

Recommended Posts

Im trying to make the piece of script to sell all the clean herbs i have in my inventory. I have an enum with all the herbs data. I've been trying to do it with a for loop but for some reason it doesn't work. If anyone could help me out that would be great

 

Quote

for(Herbs h : Herbs.values()) {
                if(mp.getInventory().contains(h.cleanName)) {
                    if(mp.getGrandExchange().sellItem(h.cleanId, h.getCleanHerbPrice(), (int) mp.getInventory().getAmount(h.cleanName))) new ConditionalSleep(5000) {
                        
                        @Override
                        public boolean condition() throws InterruptedException {
                            return !mp.getGrandExchange().isOfferScreenOpen();
                        }
                    }.sleep();
                }
            }

 

Link to comment
Share on other sites

MethodProvider

You've got a variable for what I assume is the MethodProvider. You need to make sure that, before you use it, you call:

mp.exchangeContext(bot)

With the "bot" being passed in from the script.

 

Herb enum

Can you post your enum code? On the one hand, you have:

h.getCleanHerbPrice()

But on the other hand you're also doing:

h.cleanName
h.cleanId

So it would be good to check to make sure you're calling stuff correctly.

 

Script loop v.s. for-loop

Your script already loops over and over again. It's safer to pick one herb per loop cycle and to just deal with that. That way, you avoid problems like having the bot try to drop a bunch of items in one go, only to then end up trying to drop an item that no longer exists.

Link to comment
Share on other sites

Look up the api, it says that you just specify an amount, no need to loop over them. That way you just sell one at a time.

Also I would say change the if statement that checks if the inventory contains a clean herb and just do an inverse in the bank. So if the bank does not contain anymore dirty herbs, then widthdraw all clean herbs as noted, get the noted id for the herbs and sell them on the GE.

I can give more specfic code examples if you need more help. :) 

Link to comment
Share on other sites

15 minutes ago, liverare said:

Can you post your enum code? On the one hand, you have

This is the enum im using. It uses a snippet to gather the prices for the items

 

Quote

public enum Herbs {

    GUAM_LEAF("Guam leaf", 3, 199, 249),
    MARRENTILL("Marrentill" , 5, 201, 251),
    TARROMIN ("Tarromin", 11, 203, 253),
    HARRALANDER ("Harralander", 20, 205, 255),
    RANARR_WEED ("Ranarr weed", 25, 207, 257),
    TOADFLAX ("Toadflax", 30, 3049, 2998),
    IRIT_LEAF ("Irit leaf", 40, 209, 259),
    AVANTOE ("Avantoe", 48, 211, 261),
    KWUARM ("Kwuarm", 54, 213, 263),
    SNAPDRAGON ("Snapdragon", 59, 3051, 3000),
    CADANTINE ("Cadantine", 65, 215, 265),
    LANTADYME ("Lantadyme", 67, 2485, 2481),
    DWARF_WEED ("Dwarf weed", 70, 217, 267),
    TORSTOL ("Torstol", 75, 219, 269);
    
    public String grimyName;
    public String cleanName;
    public int margin;
    public int lvl;
    public int grimyId;
    public int cleanId;
    
    Herbs(String herbName, int lvl, int grimy, int clean) {
        grimyName = "Grimy " + herbName.toLowerCase();
        cleanName = herbName;
        this.lvl = lvl;
        margin = getCleanHerbPrice() - getGrimyHerbPrice();
        grimyId = grimy;
        cleanId = clean;
    }
    
    public int getGrimyHerbPrice() {
        int price = 0;
        
        try {
            price = Math.max(ItemLookup.get(grimyName, Property.BUY_AVERAGE).map(Integer::parseInt).get(), ItemLookup.get(grimyName, Property.SELL_AVERAGE).map(Integer::parseInt).get());
        } catch (Exception e) {
            price = -1;
        }
        return price;
    }
    
    public int getCleanHerbPrice() {
        int price = 0;
        
        try {
            price = Math.min(ItemLookup.get(cleanName, Property.BUY_AVERAGE).map(Integer::parseInt).get(), ItemLookup.get(cleanName, Property.SELL_AVERAGE).map(Integer::parseInt).get());
        } catch (Exception e) {
            price = -1;
        }
        return price;
    }
    
}

 

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