Jump to content

Recommended Posts

// 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",
            });

 

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. 

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