Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- by Mordred
- local TM = {itemTypes = {"Head","","Shoulders","","Chest","Waist","Legs","Feet","Wrists","Hands","","","","","Cloak","Mainhand","Offhand","Range"},
- colorCoef = {[0] = "5D5D5D", [1] = "FFFFFF", [2] = "44E125", [3] = "0A25D1", [4] = "7014AA", [5] = "F48906", [6] = "CB0000"},
- startValue = 10000,
- gCosts = 10,
- TomeID = 0}
- -----------------------------don't change below-----------------------------------
- function TransmogOpen(Unit,_,Player)
- local P = tostring(Player:GetGUID())
- TM[P] = {possSlots = {}, transmogged = {}}
- --
- for s=0,17,1 do
- if not (s==1 or s==3 or s==10 or s==11 or s==12 or s==13) then
- local slot = Player:GetEquippedItemBySlot(s)
- if slot~=nil and slot:GetEntryId()<TM.startValue then
- table.insert(TM[P].possSlots, slot)
- elseif slot~=nil and slot:GetEntryId()>=TM.startValue then
- table.insert(TM[P].transmogged, slot)
- end
- end
- end
- --
- if table.getn(TM[P].possSlots)<1 then
- Player:SendBroadcastMessage("You have to equip something first!")
- return;
- else
- TM[P].Items = {}
- local aDcounter = 0
- for num=1,table.getn(TM[P].possSlots),1 do
- item = TM[P].possSlots[num-aDcounter]
- TM[P].Items[num-aDcounter] = {"select an item ..."}
- local invtype = WorldDBQuery("SELECT inventorytype FROM items WHERE entry = "..item:GetEntryId()..";"):GetColumn(0):GetULong()
- local subclass = WorldDBQuery("SELECT subclass FROM items WHERE entry = "..item:GetEntryId()..";"):GetColumn(0):GetULong()
- local possData = WorldDBQuery("SELECT entry FROM transmog_items WHERE inventorytype = "..invtype.." AND subclass = "..subclass..";")
- if possData~=nil then
- repeat
- if Player:HasItem(possData:GetColumn(0):GetULong()) then
- local itemSv = Player:GetInventoryItemById(possData:GetColumn(0):GetULong())
- if not (tostring(item:GetGUID())==tostring(itemSv:GetGUID())) then
- if itemSv:GetEntryId()<TM.startValue then
- table.insert(TM[P].Items[num-aDcounter], itemSv)
- end
- end
- end
- until possData:NextRow()~=true
- if table.getn(TM[P].Items[num-aDcounter])<2 then
- TM[P].Items[num-aDcounter] = nil
- end
- end
- if TM[P].Items[num-aDcounter]==nil then
- table.remove(TM[P].possSlots, num-aDcounter)
- aDcounter = aDcounter + 1
- end
- end
- local buttonCoefHeight = 100
- if table.getn(TM[P].possSlots)>1 then
- buttonCoefHeight = table.getn(TM[P].possSlots)*30+30
- end
- --
- local changeToStandard = "|cFF313131changed to:|r "
- TM[P].Main = CreateFrame("Transmogrification")
- TM[P].Finish = TM[P].Main:CreateButton("Finish")
- TM[P].Restore = TM[P].Main:CreateButton("Restore")
- TM[P].Costs = TM[P].Main:CreateTextBox("Costs")
- TM[P].InfoBox = TM[P].Main:CreateTextBox("Info")
- if table.getn(TM[P].possSlots)<1 then
- 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.");
- else
- TM[P].InfoBox:SetText("")
- end
- TM[P].Exit = TM[P].Main:CreateButton("Exit")
- TM[P].ItemTos = {}; TM[P].NextItem = {}; TM[P].BackItem = {}
- ---------------------------------------------
- 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)
- --
- 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")
- TM[P].Finish:SetEvent("OnClick", function(_,_,plr,_)
- if plr then--and plr:GetItemCount(TM.TomeID)>=TM[P].TCosts then
- local P = tostring(plr:GetGUID())
- for num,item in pairs(TM[P].possSlots) do
- local itemSC = TM[P].Items[num][TM[P].ItemCounter[num]]
- if type(itemSC)~="string" then
- local itemInfo = WorldDBQuery("SELECT * FROM items WHERE entry = "..item:GetEntryId()..";")
- local iD = {}
- for d=0,itemInfo:GetColumnCount()-1,1 do
- if d==4 or d==96 then
- table.insert(iD, itemInfo:GetColumn(d):GetString())
- elseif d==49 or d==50 or d==52 or d==53 or d==64 or d==122 then
- table.insert(iD, itemInfo:GetColumn(d):GetFloat())
- else
- table.insert(iD, itemInfo:GetColumn(d):GetULong())
- end
- end
- for n1,is in pairs(iD) do if type(is)=="number" and math.floor(is/1000000)==4294 then iD[n1] = -1 end end
- local transTo = WorldDBQuery("SELECT displayid FROM items WHERE entry = "..itemSC:GetEntryId()..";"):GetColumn(0):GetULong()
- local maxEntry = WorldDBQuery("SELECT MAX(transmog_entry) FROM transmogged;"):GetColumn(0):GetULong()
- local newEntry = maxEntry+1
- if newEntry<TM.startValue then
- newEntry = TM.startValue
- end
- if maxEntry~=WorldDBQuery("SELECT MAX(entry) FROM items;"):GetColumn(0):GetULong() then
- WorldDBQuery("DELETE FROM transmogged WHERE transmog_entry = "..maxEntry..";")
- end
- 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)..");")
- WorldDBQuery("INSERT INTO transmogged VALUES ("..newEntry..","..item:GetEntryId()..");")
- ReloadTable("items")
- --plr:RemoveItem(TM.TomeID, TM[P].TCosts)
- local AE = plr:AddItem(newEntry, 1)
- if AE ~= nil then
- plr:RemoveItem(item:GetEntryId(), 1)
- RegisterTimedEvent("AutoEquip", 100, 1, AE)
- else
- print("reload error!!WTFUCKBOOOOOOOOOOOOOOOOOOOOOOOOM!")
- end
- end
- TM[P].ItemTos[num]:SetText("")
- TM[P].NextItem[num]:SetXOffset(-3000)
- TM[P].BackItem[num]:SetXOffset(-3000)
- end
- TM[P].Main:Send(plr)
- TM[P].Main:Hide(plr)
- plr:RemoveEvents()
- else
- plr:SendBroadcastMessage("You don't have enough Tomes!")
- end end)
- --
- 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")
- TM[P].Restore:SetEvent("OnClick", function(_,_,plr,_)
- local P = tostring(plr:GetGUID())
- local maxEntry = WorldDBQuery("SELECT MAX(transmog_entry) FROM transmogged;"):GetColumn(0):GetULong()
- for num,item in pairs(TM[P].transmogged) do
- local iEntry = item:GetEntryId()
- if iEntry~=nil and iEntry>=TM.startValue then
- local ntry = WorldDBQuery("SELECT real_entry FROM transmogged WHERE transmog_entry = "..iEntry..";"):GetColumn(0):GetULong()
- if ntry~=nil then
- plr:RemoveItem(iEntry,1)
- if iEntry~=maxEntry then
- WorldDBQuery("DELETE FROM transmogged WHERE transmog_entry = "..iEntry..";")
- end
- WorldDBQuery("DELETE FROM items WHERE entry = "..iEntry..";")
- local AE = plr:AddItem(ntry,1)
- if AE ~= nil then
- AE:EquipAuto()
- end
- else
- print("error in transmogged DB")
- end
- end
- end
- for num,item in pairs(TM[P].possSlots) do
- TM[P].ItemTos[num]:SetText("")
- TM[P].NextItem[num]:SetXOffset(-3000)
- TM[P].BackItem[num]:SetXOffset(-3000)
- end
- TM[P].Main:Send(plr)
- TM[P].Main:Hide(plr)
- plr:RemoveEvents()
- end)
- --
- 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")
- TM[P].Exit:SetEvent("OnClick", function(_,_,plr,_)
- local P = tostring(plr:GetGUID())
- for num,item in pairs(TM[P].possSlots) do
- TM[P].ItemTos[num]:SetText("")
- TM[P].NextItem[num]:SetXOffset(-3000)
- TM[P].BackItem[num]:SetXOffset(-3000)
- end
- TM[P].Main:Send(plr)
- TM[P].Main:Hide(plr)
- plr:RemoveEvents()
- end)
- --
- 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")
- --------------------------------------------------------- content
- local maxH = table.getn(TM[P].possSlots)*15-15
- TM[P].ItemCounter = {}
- TM[P].TCosts = 0
- for num,item in pairs(TM[P].possSlots) do
- TM[P].ItemCounter[num] = 1
- --
- TM[P].ItemTos[num] = TM[P].Main:CreateTextBox("Tonr"..num)
- 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)
- --
- TM[P].NextItem[num] = TM[P].Main:CreateButton("Nextnr"..num)
- 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)
- TM[P].NextItem[num]:SetEvent("OnClick", function(_,_,plr,_)
- local P = tostring(plr:GetGUID())
- if not (TM[P].ItemCounter[num]==table.getn(TM[P].Items[num])) then
- TM[P].ItemCounter[num] = TM[P].ItemCounter[num] + 1
- local itmIC = TM[P].Items[num][TM[P].ItemCounter[num]]
- local quality = WorldDBQuery("SELECT quality FROM items WHERE entry = "..itmIC:GetEntryId()..";"):GetColumn(0):GetULong()
- TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." |cFF"..TM.colorCoef[quality].."["..itmIC:GetName().."]|r")
- TM[P].TCosts = TM[P].TCosts + TM.gCosts
- TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
- TM[P].Main:Send(plr)
- end
- end)
- --
- TM[P].BackItem[num] = TM[P].Main:CreateButton("Backnr"..num)
- 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)
- TM[P].BackItem[num]:SetEvent("OnClick", function(_,_,plr,_)
- local P = tostring(plr:GetGUID())
- if not (TM[P].ItemCounter[num]==1) then
- TM[P].ItemCounter[num] = TM[P].ItemCounter[num] - 1
- local itmIC = TM[P].Items[num][TM[P].ItemCounter[num]]
- if TM[P].ItemCounter[num]==1 then
- TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." "..itmIC)
- TM[P].TCosts = TM[P].TCosts - TM.gCosts
- TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
- TM[P].Main:Send(plr)
- else
- local quality = WorldDBQuery("SELECT quality FROM items WHERE entry = "..itmIC:GetEntryId()..";"):GetColumn(0):GetULong()
- TM[P].ItemTos[num]:SetText(TM.itemTypes[item:GetEquippedSlot()+1].." "..changeToStandard.." |cFF"..TM.colorCoef[quality].."["..itmIC:GetName().."]|r")
- TM[P].TCosts = TM[P].TCosts - TM.gCosts
- TM[P].Costs:SetText(TM[P].TCosts.." Tomes")
- TM[P].Main:Send(plr)
- end
- end
- end)
- --
- maxH = maxH - 30
- end
- TM[P].Main:Send(Player)
- TM[P].Main:Hide(plr) -- resend because else there are issues with the dynamic content
- TM[P].Main:Send(Player)
- Player:RegisterLuaEvent(function() if Player:GetDistanceYards(Unit)>4 then
- for num,item in pairs(TM[P].possSlots) do
- TM[P].ItemTos[num]:SetText("")
- TM[P].NextItem[num]:SetXOffset(-3000)
- TM[P].BackItem[num]:SetXOffset(-3000)
- end
- TM[P].Main:Send(Player)
- TM[P].Main:Hide(Player)
- Player:RemoveEvents() end end, 1000, 0)
- end
- end
- RegisterUnitGossipEvent(14,1,TransmogOpen)
- function AutoEquip(Item)
- if Item~=nil then
- Item:EquipAuto()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement