Thread Tools Display Modes
06-17-10, 05:52 AM   #1
Wildbreath
A Cyclonian
 
Wildbreath's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 46
Equipment manager extra button

lua Code:
  1. local BankSlots = { -1,5,6,7,8,9,10,11 }
  2. local isAtBank = false
  3. local preserve = {}
  4. for i=-2,11 do
  5.    preserve[i] = {}
  6. end
  7.    
  8. function getCurrentSetName()
  9.    for i = 1, MAX_EQUIPMENT_SETS_PER_PLAYER do
  10.       if _G["GearSetButton"..i]:GetChecked() then
  11.          return _G["GearSetButton" .. i .. "Name"]:GetText()
  12.       end
  13.    end
  14. end
  15.    
  16. function ValidBag(bagid)
  17.     local linkid,bagtype
  18.     if bagid==0 or bagid==-1 then
  19.         return 1
  20.     else
  21.         if GetItemFamily(string.match(GetInventoryItemLink("player",ContainerIDToInventoryID(bagid)) or "","item:(%-?%d+)"))==0 then
  22.             return 1
  23.         end
  24.     end
  25. end
  26.  
  27. function haveBankSlots()
  28.    if not isAtBank then return end
  29.     for _,i in pairs(BankSlots) do
  30.         if ValidBag(i) then
  31.             for j=1,GetContainerNumSlots(i) do
  32.                 if not GetContainerItemLink(i,j) and not preserve[i][j] then
  33.                     preserve[i][j] = 1
  34.                     return i,j
  35.                 end
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. function PutSet(msg)
  42.    local a1, a2 = {}, {}
  43.    a1=GetEquipmentSetLocations(getCurrentSetName())
  44.    if a1 then
  45.       for _, v in pairs(a1) do
  46.          local player, bank, bags, slot, bag = EquipmentManager_UnpackLocation(v)
  47.          local freebag, freeslot= 0, 0
  48.          if slot then
  49.             freebag, freeslot = haveBankSlots()
  50.             if bag then
  51.                PickupContainerItem(bag, slot)
  52.             elseif player and not bag then
  53.                PickupInventoryItem(slot)
  54.             end
  55.             PickupContainerItem(freebag, freeslot)
  56.          end
  57.       end
  58.       clearPreserve()
  59.       ClearCursor()
  60.    end
  61. end
  62.  
  63. function clearPreserve()
  64.    for i=-2,11 do
  65.         for j in pairs(preserve[i]) do
  66.             preserve[i][j] = nil
  67.         end
  68.     end
  69. end
  70.  
  71.  
  72. local frm = CreateFrame("frame")
  73. frm:RegisterEvent("BANKFRAME_OPENED")
  74. frm:RegisterEvent("BANKFRAME_CLOSED")
  75. frm:RegisterEvent("PLAYER_ENTERING_WORLD")
  76. frm:SetScript("OnEvent", function(self, event, ...)
  77.    if event =="PLAYER_ENTERING_WORLD" then
  78.       local ef = _G["GearManagerDialog"]
  79.       ef:SetHeight(195)
  80.       local putb = CreateFrame("button", "butbank_button", ef, "UIPanelButtonTemplate")
  81.       putb:SetWidth(_G["GearManagerDialogDeleteSet"]:GetWidth())
  82.       putb:SetHeight(22)
  83.       putb:SetPoint("BOTTOMLEFT", _G["GearManagerDialogDeleteSet"], "TOPLEFT", 0, 4)
  84.       putb:SetText("in bank")
  85.       putb:Disable()
  86.       putb:SetScript("OnClick", function()
  87.          local sname = getCurrentSetName()
  88.          if isAtBank then
  89.             if not sname then
  90.                UIErrorsFrame:AddMessage("Select set!", 1.0, 0.1, 0.1, 1.0)
  91.                return
  92.             end
  93.             PutSet(true)
  94.          else
  95.             UIErrorsFrame:AddMessage("You should open bank", 1.0, 0.1, 0.1, 1.0)
  96.          end
  97.       end)
  98.    elseif event == "BANKFRAME_OPENED" then
  99.       isAtBank = true
  100.       _G["butbank_button"]:Enable()
  101.    elseif event == "BANKFRAME_CLOSED" then
  102.       isAtBank = false
  103.       _G["butbank_button"]:Disable()
  104.    end
  105. end)
(sorry for bad english messages )

Last edited by Wildbreath : 09-05-10 at 10:39 PM.
  Reply With Quote
08-10-10, 01:36 PM   #2
Karudon
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 15
butbank_button a nil value
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Equipment manager extra button

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off