September 16, 20178 yr Lua.LuaDoString<string>("itemId = GetContainerItemID(1,2);", "itemId"); Isnt working ;( I want to send items by mail, can send one item per cycle using Bag.GetItemContainerBagIdAndSlot, but it is very slow, because I have to wait 5 sec (antispam system).
September 16, 20178 yr Hello, what's your primary goal? Do you want to send items by item name / id? Will the code be used in a plugin or quester profile?
September 16, 20178 yr Author Quote Do you want to send items by item name / id? Hey, yes, prefer by item name. Some items have same Id but different names: Tanzanite pendant of the Gorilla/of the Monkey, etc. The code will be used in a plugin (burning crusade).
September 16, 20178 yr In my other post, i've written a method to interact with the items: https://wrobot.eu/forums/topic/7064-check-distance/?tab=comments#comment-32142 You can also use this to right clicking your items to the mail attachment. I've rewritten abit, so it returns the left stacks: /// <summary> /// Interact with all listed item names. /// </summary> /// <param name="itemNames">The itemNames to interact with.</param> /// <param name="interactions">The amount of interactions.</param> /// <returns>The amount of itemNames / stacks blocked by "interactions".</returns> /// <remarks>Bug at links with "-"</remarks> 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: SendItems("Reapler", "items for you", new List<string> { "Super Healing Potion", "Heavy Netherweave Bandage", "Super Mana Potion", });
September 17, 20178 yr Author Works fine as charm, hell thanks. Dont know why but i had to replace . Lua.LuaDoString($"SendMail(\"{recipient}\",\"{subject}\",\" \");"); to Lua.LuaDoString("SendMail(\"" + recipient + "\", \"" + subject + "\")");
September 17, 20178 yr Author Can it be rewritten for full bags disenchant? ( no mater which item is). Unfortunately I dont understand well what is going on in code above :(
September 17, 20178 yr 7 hours ago, sowelu said: Can it be rewritten for full bags disenchant? ( no mater which item is). Unfortunately I dont understand well what is going on in code above :( Yes, it's also possible. You need to change ""local _, stackCount = GetContainerItemInfo(b, s)\t" +" with GetItemInfo, add your conditions and return a list with a struct of the bag position & its slot. The struct: public struct BagInfo { public int Bag; public int Slot; public BagInfo(int bag, int slot) { Bag = bag; Slot = slot; } public override string ToString() { return "Bag = " + Bag + " ; Slot = " + Slot; } } The disenchant list: /// <summary> /// Used to get a list of all disenchantable items as bag and slot position. /// </summary> /// <param name="maxItemLevel">The maximum item level.</param> /// <param name="interactions">The amount of interactions.</param> /// <returns></returns> public static List<BagInfo> DisenchantList(int maxItemLevel = int.MaxValue, int interactions = int.MaxValue)//parameter list can be extended { var execute = "local counter = 0; " + "local leftStacks = 0; " + "local bs = {}" + "for b=0,4 do " + "if GetBagName(b) then " + "for s=1, GetContainerNumSlots(b) do " + "local itemLink = GetContainerItemLink(b, s) " + "if itemLink then " + "local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemLink) \t" + "if itemRarity > 1 and itemRarity < 5 " + "and itemLevel <= " + maxItemLevel + " " + "and (itemType == 'Armor' or itemType == 'Weapon') "; execute = execute + "then " + "if (counter < "+interactions+") then " + "table.insert(bs, b); " + "table.insert(bs, s); " + "counter = counter + 1; " + "else " + "leftStacks = leftStacks + 1;" + "end " + "\tend\tend\tend end end return unpack(bs);"; var bs = Lua.LuaDoString<List<int>>(execute); var list = new List<BagInfo>(); for (var i = 0; i < bs.Count; i += 2) { list.Add(new BagInfo(bs[i], bs[i+1])); } return list; } The final method to execute: /// <summary> /// Disenchant all items depend on the itemLevel. /// </summary> /// <param name="maxItemLevel">The maximum item level.</param> /// <remarks>AutoLoot must be enabled to work properly.</remarks> public void Disenchant(int maxItemLevel = int.MaxValue) { var disenchant = new Spell("Disenchant"); foreach (var bagInfo in DisenchantList()) { disenchant.Launch(); Thread.Sleep(100); Lua.LuaDoString("UseContainerItem("+bagInfo.Bag+", "+bagInfo.Slot+");"); Thread.Sleep((int)disenchant.CastTime+800); } } Not fully tested, but it should work. And 9 hours ago, sowelu said: Works fine as charm, hell thanks. Dont know why but i had to replace . Lua.LuaDoString($"SendMail(\"{recipient}\",\"{subject}\",\" \");"); to Lua.LuaDoString("SendMail(\"" + recipient + "\", \"" + subject + "\")"); I think you let it compile by WRobot or using a lower framework version, so new additions over the course of the years like this example doesn't support it.
Create an account or sign in to comment