Jump to content
This site uses cookies! Learn More

This site uses cookies!

By continuing to use this site, you agree to allow us to store cookies on your computer. :)

Recommended Posts

Hi 

I want Send a number items to a recipient with code。How can i set the quantity? 

Like this :SendItems("recipient", "sub","item" ,quantity)

Share this post


Link to post
Share on other sites
// Mail Items *custom script* - By Reapler


    public static int InteractItems(List<string> itemNames, int interactions = int.MaxValue)
    {
        if (!itemNames.Any())
            return -1;
        var execute = 
            "local counter = 0; " +
            "local leftStacks = 0; " +
            "for b=0,4 do " +
            "if GetBagName(b) then " +
            "for s=1, GetContainerNumSlots(b) do " +
            "local itemLink = GetContainerItemLink(b, s) " +
            "if itemLink then " +
            "local _, stackCount = GetContainerItemInfo(b, s)\t" +
            "if string.find(itemLink, \""+ itemNames.FirstOrDefault() + "\") ";
        if (itemNames.Count > 1)
        {
            execute = itemNames.Where(obj => itemNames.FirstOrDefault() != obj).Aggregate(execute, (current, obj) => current + "or string.find(itemLink, \"" + obj + "\") ");
        }
        execute = execute + 
                  "then " +
                  "if (counter < "+interactions+") then " +
                  "UseContainerItem(b, s); " +
                  "counter = counter + 1; " +
                  "else " +
                  "leftStacks = leftStacks + 1;" +
                  "end " +
                  "\tend\tend\tend end end return leftStacks;";
        return Lua.LuaDoString<int>(execute);
    }

    /// <summary>
    /// Sends a mail to a recipient.
    /// </summary>
    /// <param name="recipient">The recipient.</param>
    /// <param name="subject">The subject.</param>
    /// <param name="itemNames">The items to send as names.</param>
    /// <returns>true if successful ; false if no mailbox available or stacks are left.</returns>
    public bool SendItems(string recipient, string subject, List<string> itemNames)
    {
        var mailBox = ObjectManager.GetObjectWoWGameObject().FirstOrDefault(i => i.IsMailbox && i.GetDistance <= 5);
        if (mailBox == null || string.IsNullOrWhiteSpace(recipient))
            return false;
        if (subject.Length == 0)
            subject = "-";
        if (mailBox)
        {
            const int delayMs = 800;
            var timeOut = DateTime.Now.AddSeconds(40);
            Interact.InteractGameObject(mailBox.GetBaseAddress);
            Thread.Sleep(delayMs);
            Lua.LuaDoString("RunMacroText('/click MailFrameTab2');");
            Thread.Sleep(delayMs);

            var leftStack = InteractItems(itemNames, 12);
            Thread.Sleep(delayMs);
            Lua.LuaDoString($"SendMail(\"{recipient}\",\"{subject}\",\" \");");
            Thread.Sleep(delayMs*3);

            while (leftStack != 0 && DateTime.Now < timeOut)
            {
                leftStack = InteractItems(itemNames, 12);
                Thread.Sleep(delayMs);
                Lua.LuaDoString($"SendMail(\"{recipient}\",\"{subject}\",\" \");");
                Thread.Sleep(delayMs*3);
            }

            Lua.LuaDoString("CloseMail();");
            if (leftStack != 0)
                return false;
        }
        return true;
    }
	
	
	
	
	// Usage: runcode

        SendItems("Reapler", "items for you", 
            new List<string>
            {
                "Super Healing Potion",
                "Heavy Netherweave Bandage",
                "Super Mana Potion",
            });

 

Share this post


Link to post
Share on other sites

Thanks ! Smokie

I give an example:

 I have 100  light leather ,I need to send 28 light leather.not all.

I have many bots to train Leatherworking,I need send leather to  them. If i can't set the number of leather,mabe all leather will send to one of bot. 

Share this post


Link to post
Share on other sites

I have many bot to train Leatherworking,I need send leather to  them. If i can't set the number of leather,mabe all leather will send to one of bot. 

Share this post


Link to post
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
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.


×
×
  • Create New...