Advertisement
Guest User

Auto-Ammo every language

a guest
Oct 25th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. if not AutoAmmo_Quantity then
  2.     AutoAmmo_Quantity = 0
  3. end
  4.  
  5. local ammoLink, rangedItemLink;
  6.  
  7. local arrowTable = {
  8.     [1] = select(2,GetItemInfo(2512)), -- "Rauer Pfeil",
  9.     [10] = select(2,GetItemInfo(2515)), -- "Scharfer Pfeil",
  10.     [25] = select(2,GetItemInfo(3030)), -- "Schneidenofeil",
  11.     [40] = select(2,GetItemInfo(11285)), -- "Gezackter Pfeil",
  12. }
  13.  
  14. local bulletTable = {
  15.     [1] =  select(2,GetItemInfo(2516)), -- "Leichtes Geschoss",
  16.     [10] = select(2,GetItemInfo(2519)), -- "Schweres Geschoss",
  17.     [25] = select(2,GetItemInfo(3033)), -- "Robustes Geschoss",
  18.     [40] = select(2,GetItemInfo(11284)), -- "Genaue Patronen",
  19. }
  20.  
  21. function AutoAmmo_ItemToBuy()
  22.     rangedItemLink = GetInventoryItemLink("player", GetInventorySlotInfo("RangedSlot"))
  23.     if rangedItemLink ~= nil then
  24.         -- get SubclassID
  25.         local subclassID  = select(13, GetItemInfo(rangedItemLink))
  26.         ammoLink = nil
  27.         -- compare with ITEM ENUM subClassIDs
  28.         if subclassID == LE_ITEM_WEAPON_GUNS then
  29.             local playerLevel = UnitLevel("PLAYER");
  30.             while (playerLevel > 0) and (ammoLink == nil) do
  31.                 ammoLink = bulletTable[playerLevel]
  32.                 playerLevel = playerLevel - 1;
  33.             end
  34.         elseif subclassID == LE_ITEM_WEAPON_BOWS then
  35.             local playerLevel = UnitLevel("PLAYER");
  36.             while (playerLevel > 0) and (ammoLink == nil) do
  37.                 ammoLink = arrowTable[playerLevel]
  38.                 playerLevel = playerLevel - 1;
  39.             end
  40.         else
  41.             ammoLink = nil;
  42.         end
  43.     else
  44.         ammoLink = nil;
  45.     end
  46. end
  47.  
  48. local frame = CreateFrame("Frame")
  49. frame:RegisterEvent("MERCHANT_SHOW")
  50. frame:SetScript("OnEvent", function(self, event, ...)
  51.     AutoAmmo_ItemToBuy();
  52.     local merchItemLink = "";
  53.     local i = 1;
  54.     local toBuy = AutoAmmo_Quantity - GetItemCount(ammoLink)
  55.     if toBuy > 100 and ammoLink ~= nil then
  56.         while (merchItemLink ~= nil) do
  57.             merchItemLink = GetMerchantItemLink(i);
  58.             if merchItemLink == ammoLink then
  59.                 while (toBuy > 200) do
  60.                     BuyMerchantItem(i, 200)
  61.                     toBuy = toBuy - 200
  62.                 end
  63.                 if toBuy > 100 then
  64.                     BuyMerchantItem(i, toBuy)
  65.                 end
  66.             end
  67.             i = i + 1;
  68.         end
  69.     end
  70. end)
  71.  
  72.  
  73. function AutoAmmo_Command(arg1)
  74.     AutoAmmo_ItemToBuy(); -- So we can print the correct ammo
  75.  
  76.     if tonumber(arg1) ~= nil then
  77.         AutoAmmo_Quantity = tonumber(arg1)
  78.         if ammoLink ~= nil then
  79.            
  80.             print("Stockpiling " .. AutoAmmo_Quantity .. " " .. ammoLink .. " for " .. rangedItemLink)
  81.         else
  82.             print("You currently have no ranged wepon that needs ammo, but when you do, we'll stockpile " .. AutoAmmo_Quantity .. " ammo.")
  83.         end
  84.     else
  85.         print("Available command is \/aa <number>")
  86.     end
  87. end
  88.  
  89. SLASH_AUTOAMMO1 = "/aa"
  90. SLASH_AUTOAMMO2 = "/autoammo"
  91. SlashCmdList.AUTOAMMO = AutoAmmo_Command
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement