Jump to content
  • buy item


    pudge
    • Product: WRobot General Type: Bug Status: Unconfirmed

     

    Hi. The function

    Vendor.BuyItem();

    does not work correctly.Instead of the required amount,just one good is always bought.

     



    User Feedback

    Recommended Comments

    hi,

    You need to call this method several time

                                    for (int i = 0; i < b.Quantity && b.NeedToBuy(); i++)
                                    {
                                        var qToBuy = b.Quantity - ItemsManager.GetItemCountByNameLUA(b.ItemName);
                                        if (qToBuy > MaxItemsQuantityToBuyByRequest)
                                            qToBuy = MaxItemsQuantityToBuyByRequest;
                                        Vendor.BuyItem(b.ItemName, qToBuy);
                                        Thread.Sleep(Usefuls.Latency + 400);
                                    }

     

    Link to comment
    Share on other sites

     

     

    I am already using code similar to yours, but this is a workaround, it just worked fine in older versions, and I noticed that the bot owes a debt to the vendor, when before the purchase took a couple of seconds. Thanks for the answer.

    vendor-buy-work-fine.PNG

    Link to comment
    Share on other sites

    i use this function to buy stuff from venders if it helps. 

    public static void BuyItem(string name, int amount)
        {
            Lua.LuaDoString(string.Format(@"
            local itemName = ""{0}""
            local quantity = {1}
            for i=1, GetMerchantNumItems() do
                local name = GetMerchantItemInfo(i)
                if name and name == itemName then 
                    BuyMerchantItem(i, quantity)
                end
            end", name, amount));
        }

     

    Link to comment
    Share on other sites

    I won't back to old version of code (change was do 1 year ago).

    Current code:

            public static void BuyItem(string name, int number)
            {
                try
                {
                    Lua.LuaDoString([email protected]"
    local n = '{name.Replace("'", @"\'")}'; 
    local q = {number}; 
    for i=1,100 do 
        local name, _, _, quantity = GetMerchantItemInfo(i) 
        if name and n==name then 
            if q > quantity then 
                q = quantity 
            end 
            BuyMerchantItem(i,q) 
        end 
    end");
                }
                catch (Exception e)
                {
                    Logging.WriteError("BuyItem(string name, int number): " + e);
                }
            }

    to get old code remove:

            if q > quantity then 
                q = quantity 
            end 

     

    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.

    Guest
    Add a comment...

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


×
×
  • Create New...