Advertisement
Mordred

Transmog

Jun 20th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.35 KB | None | 0 0
  1. -- by Mordred
  2.  
  3. local TM = {itemTypes = {"Head","","Shoulders","","Chest","Waist","Legs","Feet","Wrists","Hands","","","","","Cloak","Mainhand","Offhand","Range"},
  4.             colorCoef = {[0] = "5D5D5D", [1] = "FFFFFF", [2] = "44E125", [3] = "0A25D1", [4] = "7014AA", [5] = "F48906", [6] = "CB0000"},
  5.             startValue = 10000,
  6.             gCosts = 10,
  7.             TomeID = 0}
  8.  
  9. -----------------------------don't change below-----------------------------------
  10.            
  11. function TransmogOpen(Unit,_,Player)
  12.     local P = tostring(Player:GetGUID())
  13.     TM[P] = {possSlots = {}, transmogged = {}}
  14.     --
  15.     for s=0,17,1 do
  16.         if not (s==1 or s==3 or s==10 or s==11 or s==12 or s==13) then
  17.             local slot = Player:GetEquippedItemBySlot(s)
  18.             if slot~=nil and slot:GetEntryId()<TM.startValue then
  19.                 table.insert(TM[P].possSlots, slot)
  20.             elseif slot~=nil and slot:GetEntryId()>=TM.startValue then
  21.                 table.insert(TM[P].transmogged, slot)
  22.             end
  23.         end
  24.     end
  25.     --
  26.     if table.getn(TM[P].possSlots)<1 then
  27.         Player:SendBroadcastMessage("You have to equip something first!")
  28.         return;
  29.     else
  30.         TM[P].Items = {}
  31.         local aDcounter = 0
  32.         for num=1,table.getn(TM[P].possSlots),1 do
  33.             item = TM[P].possSlots[num-aDcounter]
  34.             TM[P].Items[num-aDcounter] = {"select an item ..."}
  35.             local invtype = WorldDBQuery("SELECT inventorytype FROM items WHERE entry = "..item:GetEntryId()..";"):GetColumn(0):GetULong()
  36.             local subclass = WorldDBQuery("SELECT subclass FROM items WHERE entry = "..item:GetEntryId()..";"):GetColumn(0):GetULong()
  37.             local possData = WorldDBQuery("SELECT entry FROM transmog_items WHERE inventorytype = "..invtype.." AND subclass = "..subclass..";")
  38.            
  39.             if possData~=nil then
  40.                 repeat
  41.                     if Player:HasItem(possData:GetColumn(0):GetULong()) then
  42.                         local itemSv = Player:GetInventoryItemById(possData:GetColumn(0):GetULong())
  43.                         if not (tostring(item:GetGUID())==tostring(itemSv:GetGUID())) then
  44.                             if itemSv:GetEntryId()<TM.startValue then
  45.                                 table.insert(TM[P].Items[num-aDcounter], itemSv)
  46.                             end
  47.                         end
  48.                     end
  49.                 until possData:NextRow()~=true
  50.                 if table.getn(TM[P].Items[num-aDcounter])<2 then
  51.                     TM[P].Items[num-aDcounter] = nil
  52.                 end
  53.             end
  54.             if TM[P].Items[num-aDcounter]==nil then
  55.                 table.remove(TM[P].possSlots, num-aDcounter)
  56.                 aDcounter = aDcounter + 1
  57.             end
  58.         end
  59.  
  60.         local buttonCoefHeight = 100
  61.         if table.getn(TM[P].possSlots)>1 then
  62.             buttonCoefHeight = table.getn(TM[P].possSlots)*30+30
  63.         end
  64.         --
  65.         local changeToStandard = "|cFF313131changed to:|r "
  66.         TM[P].Main = CreateFrame("Transmogrification")
  67.             TM[P].Finish = TM[P].Main:CreateButton("Finish")
  68.             TM[P].Restore = TM[P].Main:CreateButton("Restore")
  69.             TM[P].Costs = TM[P].Main:CreateTextBox("Costs")
  70.             TM[P].InfoBox = TM[P].Main:CreateTextBox("Info")
  71.             if table.getn(TM[P].possSlots)<1 then
  72.                 TM[P].InfoBox:SetWidth(350); TM[P].InfoBox:SetHeight(buttonCoefHeight); TM[P].InfoBox:SetYOffset(-7); TM[P].InfoBox:SetText("You don't have any suitable armor on,\n which can be used for transmogrification.");
  73.             else
  74.                 TM[P].InfoBox:SetText("")
  75.             end
  76.             TM[P].Exit = TM[P].Main:CreateButton("Exit")
  77.             TM[P].ItemTos = {}; TM[P].NextItem = {}; TM[P].BackItem = {}
  78.         ---------------------------------------------
  79.         TM[P].Main:SetWidth(400); TM[P].Main:SetHeight(buttonCoefHeight); TM[P].Main:SetXOffset(-200); TM[P].Main:SetYOffset(50); TM[P].Main:SetCantMove(true); TM[P].Main:SetCantClose(true)
  80.         --
  81.         TM[P].Finish:SetYOffset(buttonCoefHeight/2-15); TM[P].Finish:SetXOffset(-143); TM[P].Finish:SetHeight(20); TM[P].Finish:SetWidth(100); TM[P].Finish:SetText("Finish")
  82.         TM[P].Finish:SetEvent("OnClick", function(_,_,plr,_)
  83.                                             if plr then--and plr:GetItemCount(TM.TomeID)>=TM[P].TCosts then
  84.                                                 local P = tostring(plr:GetGUID())
  85.                                                 for num,item in pairs(TM[P].possSlots) do
  86.                                                     local itemSC = TM[P].Items[num][TM[P].ItemCounter[num]]
  87.                                                     if type(itemSC)~="string" then
  88.                                                         local itemInfo = WorldDBQuery("SELECT * FROM items WHERE entry = "..item:GetEntryId()..";")
  89.                                                         local iD = {}
  90.                                                         for d=0,itemInfo:GetColumnCount()-1,1 do
  91.                                                             if  d==4 or d==96 then
  92.                                                                 table.insert(iD, itemInfo:GetColumn(d):GetString())
  93.                                                             elseif d==49 or d==50 or d==52 or d==53 or d==64 or d==122 then
  94.                                                                 table.insert(iD, itemInfo:GetColumn(d):GetFloat())
  95.                                                             else
  96.                                                                 table.insert(iD, itemInfo:GetColumn(d):GetULong())
  97.                                                             end
  98.                                                         end
  99.                                                         for n1,is in pairs(iD) do if type(is)=="number" and math.floor(is/1000000)==4294 then iD[n1] = -1 end end
  100.                                                         local transTo = WorldDBQuery("SELECT displayid FROM items WHERE entry = "..itemSC:GetEntryId()..";"):GetColumn(0):GetULong()
  101.                                                         local maxEntry = WorldDBQuery("SELECT MAX(transmog_entry) FROM transmogged;"):GetColumn(0):GetULong()
  102.                                                         local newEntry = maxEntry+1
  103.                                                         if newEntry<TM.startValue then
  104.                                                             newEntry = TM.startValue
  105.                                                         end
  106.                                                         if maxEntry~=WorldDBQuery("SELECT MAX(entry) FROM items;"):GetColumn(0):GetULong() then
  107.                                                             WorldDBQuery("DELETE FROM transmogged WHERE transmog_entry = "..maxEntry..";")
  108.                                                         end
  109.                                                         WorldDBQuery("INSERT INTO items VALUES ("..newEntry..","..table.concat(iD,",",2,4)..",'"..string.gsub(iD[5],"'","\\'").."\n\n|cFFF659F3Transmogrified to:\n"..string.gsub(itemSC:GetName(),"'","\\'").."|r',"..transTo..","..table.concat(iD,",",7,96)..",'"..string.gsub(iD[97],"'","\\'").."',"..table.concat(iD,",",98,126)..");")
  110.                                                         WorldDBQuery("INSERT INTO transmogged VALUES ("..newEntry..","..item:GetEntryId()..");")
  111.                                                         ReloadTable("items")
  112.                                                         --plr:RemoveItem(TM.TomeID, TM[P].TCosts)
  113.                                                         local AE = plr:AddItem(newEntry, 1)
  114.                                                         if AE ~= nil then
  115.                                                             plr:RemoveItem(item:GetEntryId(), 1)
  116.                                                             RegisterTimedEvent("AutoEquip", 100, 1, AE)
  117.                                                         else
  118.                                                             print("reload error!!WTFUCKBOOOOOOOOOOOOOOOOOOOOOOOOM!")
  119.                                                         end
  120.                                                     end
  121.                                                     TM[P].ItemTos[num]:SetText("")
  122.                                                     TM[P].NextItem[num]:SetXOffset(-3000)
  123.                                                     TM[P].BackItem[num]:SetXOffset(-3000)
  124.                                                 end
  125.                                                 TM[P].Main:Send(plr)
  126.                                                 TM[P].Main:Hide(plr)
  127.                                                 plr:RemoveEvents()
  128.                                             else
  129.                                                 plr:SendBroadcastMessage("You don't have enough Tomes!")
  130.                                             end end)
  131.         --
  132.         TM[P].Restore:SetYOffset(buttonCoefHeight/2-15); TM[P].Restore:SetXOffset(-35); TM[P].Restore:SetHeight(20); TM[P].Restore:SetWidth(100); TM[P].Restore:SetText("Restore")
  133.         TM[P].Restore:SetEvent("OnClick", function(_,_,plr,_)
  134.                                                 local P = tostring(plr:GetGUID())
  135.                                                 local maxEntry = WorldDBQuery("SELECT MAX(transmog_entry) FROM transmogged;"):GetColumn(0):GetULong()
  136.                                                 for num,item in pairs(TM[P].transmogged) do
  137.                                                     local iEntry = item:GetEntryId()
  138.                                                     if iEntry~=nil and iEntry>=TM.startValue then
  139.                                                         local ntry = WorldDBQuery("SELECT real_entry FROM transmogged WHERE transmog_entry = "..iEntry..";"):GetColumn(0):GetULong()
  140.                                                         if ntry~=nil then
  141.                                                             plr:RemoveItem(iEntry,1)
  142.                                                             if iEntry~=maxEntry then
  143.                                                                 WorldDBQuery("DELETE FROM transmogged WHERE transmog_entry = "..iEntry..";")
  144.                                                             end
  145.                                                             WorldDBQuery("DELETE FROM items WHERE entry = "..iEntry..";")
  146.                                                             local AE = plr:AddItem(ntry,1)
  147.                                                             if AE ~= nil then
  148.                                                                 AE:EquipAuto()
  149.                                                             end
  150.                                                         else
  151.                                                             print("error in transmogged DB")
  152.                                                         end
  153.                                                     end
  154.                                                 end
  155.                                                 for num,item in pairs(TM[P].possSlots) do
  156.                                                     TM[P].ItemTos[num]:SetText("")
  157.                                                     TM[P].NextItem[num]:SetXOffset(-3000)
  158.                                                     TM[P].BackItem[num]:SetXOffset(-3000)
  159.                                                 end
  160.                                                 TM[P].Main:Send(plr)
  161.                                                 TM[P].Main:Hide(plr)
  162.                                                 plr:RemoveEvents()
  163.                                             end)
  164.         --
  165.         TM[P].Exit:SetYOffset(buttonCoefHeight/2-15); TM[P].Exit:SetXOffset(150); TM[P].Exit:SetHeight(20); TM[P].Exit:SetWidth(70); TM[P].Exit:SetText("Exit")
  166.         TM[P].Exit:SetEvent("OnClick", function(_,_,plr,_)
  167.                                             local P = tostring(plr:GetGUID())
  168.                                             for num,item in pairs(TM[P].possSlots) do
  169.                                                 TM[P].ItemTos[num]:SetText("")
  170.                                                 TM[P].NextItem[num]:SetXOffset(-3000)
  171.                                                 TM[P].BackItem[num]:SetXOffset(-3000)
  172.                                             end
  173.                                             TM[P].Main:Send(plr)
  174.                                             TM[P].Main:Hide(plr)
  175.                                             plr:RemoveEvents()
  176.                                         end)
  177.         --
  178.         TM[P].Costs:SetYOffset(buttonCoefHeight/2-15); TM[P].Costs:SetXOffset(75); TM[P].Costs:SetHeight(15); TM[P].Costs:SetWidth(70); TM[P].Costs:SetText("0 Tomes")
  179.         --------------------------------------------------------- content
  180.         local maxH = table.getn(TM[P].possSlots)*15-15
  181.         TM[P].ItemCounter = {}
  182.         TM[P].TCosts = 0
  183.         for num,item in pairs(TM[P].possSlots) do
  184.             TM[P].ItemCounter[num] = 1
  185.             --
  186.             TM[P].ItemTos[num] = TM[P].Main:CreateTextBox("Tonr"..num)
  187.             TM[P].ItemTos[num]:SetHeight(15); TM[P].ItemTos[num]:SetWidth(340); TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.."select an item ..."); TM[P].ItemTos[num]:SetYOffset(maxH-10)
  188.             --
  189.             TM[P].NextItem[num] = TM[P].Main:CreateButton("Nextnr"..num)
  190.             TM[P].NextItem[num]:SetHeight(20); TM[P].NextItem[num]:SetWidth(20); TM[P].NextItem[num]:SetText(">>"); TM[P].NextItem[num]:SetYOffset(maxH-10); TM[P].NextItem[num]:SetXOffset(183)
  191.             TM[P].NextItem[num]:SetEvent("OnClick", function(_,_,plr,_)
  192.                                                 local P = tostring(plr:GetGUID())
  193.                                                 if not (TM[P].ItemCounter[num]==table.getn(TM[P].Items[num])) then
  194.                                                     TM[P].ItemCounter[num] = TM[P].ItemCounter[num] + 1
  195.                                                     local itmIC = TM[P].Items[num][TM[P].ItemCounter[num]]
  196.                                                     local quality = WorldDBQuery("SELECT quality FROM items WHERE entry = "..itmIC:GetEntryId()..";"):GetColumn(0):GetULong()
  197.                                                     TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." |cFF"..TM.colorCoef[quality].."["..itmIC:GetName().."]|r")
  198.                                                     TM[P].TCosts = TM[P].TCosts + TM.gCosts
  199.                                                     TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
  200.                                                     TM[P].Main:Send(plr)
  201.                                                 end
  202.                                             end)
  203.             --
  204.             TM[P].BackItem[num] = TM[P].Main:CreateButton("Backnr"..num)
  205.             TM[P].BackItem[num]:SetHeight(20); TM[P].BackItem[num]:SetWidth(20); TM[P].BackItem[num]:SetText("<<"); TM[P].BackItem[num]:SetYOffset(maxH-10); TM[P].BackItem[num]:SetXOffset(-180)
  206.             TM[P].BackItem[num]:SetEvent("OnClick", function(_,_,plr,_)
  207.                                                 local P = tostring(plr:GetGUID())
  208.                                                 if not (TM[P].ItemCounter[num]==1) then
  209.                                                     TM[P].ItemCounter[num] = TM[P].ItemCounter[num] - 1
  210.                                                     local itmIC = TM[P].Items[num][TM[P].ItemCounter[num]]
  211.                                                     if TM[P].ItemCounter[num]==1 then
  212.                                                         TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." "..itmIC)
  213.                                                         TM[P].TCosts = TM[P].TCosts - TM.gCosts
  214.                                                         TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
  215.                                                         TM[P].Main:Send(plr)
  216.                                                     else
  217.                                                         local quality = WorldDBQuery("SELECT quality FROM items WHERE entry = "..itmIC:GetEntryId()..";"):GetColumn(0):GetULong()
  218.                                                         TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." |cFF"..TM.colorCoef[quality].."["..itmIC:GetName().."]|r")
  219.                                                         TM[P].TCosts = TM[P].TCosts - TM.gCosts
  220.                                                         TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
  221.                                                         TM[P].Main:Send(plr)
  222.                                                     end
  223.                                                 end
  224.                                             end)
  225.             --
  226.             maxH = maxH - 30
  227.         end
  228.         TM[P].Main:Send(Player)
  229.         TM[P].Main:Hide(plr) -- resend because else there are issues with the dynamic content
  230.         TM[P].Main:Send(Player)
  231.         Player:RegisterLuaEvent(function() if Player:GetDistanceYards(Unit)>4 then
  232.                                     for num,item in pairs(TM[P].possSlots) do
  233.                                         TM[P].ItemTos[num]:SetText("")
  234.                                         TM[P].NextItem[num]:SetXOffset(-3000)
  235.                                         TM[P].BackItem[num]:SetXOffset(-3000)
  236.                                     end
  237.                                     TM[P].Main:Send(Player)
  238.                                     TM[P].Main:Hide(Player)
  239.                                     Player:RemoveEvents() end end, 1000, 0)
  240.     end
  241. end
  242.  
  243. RegisterUnitGossipEvent(14,1,TransmogOpen)
  244.  
  245. function AutoEquip(Item)
  246.     if Item~=nil then
  247.         Item:EquipAuto()
  248.     end
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement