Advertisement
Guest User

Untitled

a guest
Aug 4th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. public class throwAway
  2. {
  3. public static int GetItemQuantity(string itemName)
  4. {
  5. var execute =
  6. "local itemCount = 0; " +
  7. "for b=0,4 do " +
  8. "if GetBagName(b) then " +
  9. "for s=1, GetContainerNumSlots(b) do " +
  10. "local itemLink = GetContainerItemLink(b, s) " +
  11. "if itemLink then " +
  12. "local _, stackCount = GetContainerItemInfo(b, s)\t " +
  13. "if string.find(itemLink, \"" + itemName + "\") then " +
  14. "itemCount = itemCount + stackCount; " +
  15. "end " +
  16. "end " +
  17. "end " +
  18. "end " +
  19. "end; " +
  20. "return itemCount; ";
  21. return Lua.LuaDoString<int>(execute);
  22. }
  23.  
  24. /// <summary>
  25. /// Used to delete all items by name.
  26. /// </summary>
  27. /// <param name="itemName">The item to delete.</param>
  28. /// <param name="leaveAmount">The amount of items which remain in the bag.</param>
  29. /// <remarks>Bug at links with "-"</remarks>
  30. public static void DeleteItems(string itemName, int leaveAmount)
  31. {
  32. var itemQuantity = GetItemQuantity(itemName) - leaveAmount;
  33. if(string.IsNullOrWhiteSpace(itemName) || itemQuantity <= 0)
  34. return;
  35. var execute =
  36. "local itemCount = " + itemQuantity + "; " +
  37. "local deleted = 0; " +
  38. "for b=0,4 do " +
  39. "if GetBagName(b) then " +
  40. "for s=1, GetContainerNumSlots(b) do " +
  41. "local itemLink = GetContainerItemLink(b, s) " +
  42. "if itemLink then " +
  43. "local _, stackCount = GetContainerItemInfo(b, s)\t " +
  44. "local leftItems = itemCount - deleted; " +
  45. "if string.find(itemLink, \"" + itemName + "\") and leftItems > 0 then " +
  46. "if stackCount <= 1 then " +
  47. "PickupContainerItem(b, s); " +
  48. "DeleteCursorItem(); " +
  49. "deleted = deleted + 1; " +
  50. "else " +
  51. "if (leftItems > stackCount) then " +
  52. "SplitContainerItem(b, s, stackCount); " +
  53. "DeleteCursorItem(); " +
  54. "deleted = deleted + stackCount; " +
  55. "else " +
  56. "SplitContainerItem(b, s, leftItems); " +
  57. "DeleteCursorItem(); " +
  58. "deleted = deleted + leftItems; " +
  59. "end " +
  60. "end " +
  61. "end " +
  62. "end " +
  63. "end " +
  64. "end " +
  65. "end; ";
  66. Lua.LuaDoString(execute);
  67. }
  68. }
  69.  
  70. throwAway.DeleteItems("Soul Shard", 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement