Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class throwAway
- {
- public static int GetItemQuantity(string itemName)
- {
- var execute =
- "local itemCount = 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, \"" + itemName + "\") then " +
- "itemCount = itemCount + stackCount; " +
- "end " +
- "end " +
- "end " +
- "end " +
- "end; " +
- "return itemCount; ";
- return Lua.LuaDoString<int>(execute);
- }
- /// <summary>
- /// Used to delete all items by name.
- /// </summary>
- /// <param name="itemName">The item to delete.</param>
- /// <param name="leaveAmount">The amount of items which remain in the bag.</param>
- /// <remarks>Bug at links with "-"</remarks>
- public static void DeleteItems(string itemName, int leaveAmount)
- {
- var itemQuantity = GetItemQuantity(itemName) - leaveAmount;
- if(string.IsNullOrWhiteSpace(itemName) || itemQuantity <= 0)
- return;
- var execute =
- "local itemCount = " + itemQuantity + "; " +
- "local deleted = 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 " +
- "local leftItems = itemCount - deleted; " +
- "if string.find(itemLink, \"" + itemName + "\") and leftItems > 0 then " +
- "if stackCount <= 1 then " +
- "PickupContainerItem(b, s); " +
- "DeleteCursorItem(); " +
- "deleted = deleted + 1; " +
- "else " +
- "if (leftItems > stackCount) then " +
- "SplitContainerItem(b, s, stackCount); " +
- "DeleteCursorItem(); " +
- "deleted = deleted + stackCount; " +
- "else " +
- "SplitContainerItem(b, s, leftItems); " +
- "DeleteCursorItem(); " +
- "deleted = deleted + leftItems; " +
- "end " +
- "end " +
- "end " +
- "end " +
- "end " +
- "end " +
- "end; ";
- Lua.LuaDoString(execute);
- }
- }
- throwAway.DeleteItems("Soul Shard", 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement