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($@"
    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



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...