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

    Droidz

    Posted

    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);
                                    }

     

    Pudge

    Posted

     

     

    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

    TheSmokie

    Posted

    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));
        }

     

    Droidz

    Posted

    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 

     



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