Advertisement
Rochet2

Untitled

May 29th, 2015
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.36 KB | None | 0 0
  1. --[[
  2. 4.0
  3. Transmogrification TBC - Gossip Menu By Rochet2 Updatet by Salja
  4. Eluna version
  5. TODO:
  6. Make DB saving even better (Deleting)? What about coding?
  7. Fix the cost formula
  8. TODO in the distant future:
  9. Are the qualities right? Blizzard might have changed the quality requirements.
  10. What can and cant be used as source or target..?
  11. Cant transmogrify:
  12. rediculus items -- Foereaper: would be fun to stab people with a fish
  13. -- Cant think of any good way to handle this easily
  14. Cataclysm:
  15. Test on cata : implement UI xD?
  16. Item link icon to Are You sure text
  17. ]]
  18.  
  19. local NPC_Entry = 123123
  20.  
  21. local RequireGold = 1
  22. local GoldModifier = 1.0
  23. local GoldCost = 100000
  24.  
  25. local RequireToken = false
  26. local TokenEntry = 49426
  27. local TokenAmount = 1
  28.  
  29. local Qualities =
  30. {
  31.     [0]  = true, -- AllowPoor
  32.     [1]  = true, -- AllowCommon
  33.     [2]  = true , -- AllowUncommon
  34.     [3]  = true , -- AllowRare
  35.     [4]  = true , -- AllowEpic
  36.     [5]  = true, -- AllowLegendary
  37.     [6]  = true, -- AllowArtifact
  38.     [7]  = true , -- AllowHeirloom
  39. }
  40.  
  41. local EQUIPMENT_SLOT_START        = 0
  42. local EQUIPMENT_SLOT_HEAD         = 0
  43. local EQUIPMENT_SLOT_NECK         = 1
  44. local EQUIPMENT_SLOT_SHOULDERS    = 2
  45. local EQUIPMENT_SLOT_BODY         = 3
  46. local EQUIPMENT_SLOT_CHEST        = 4
  47. local EQUIPMENT_SLOT_WAIST        = 5
  48. local EQUIPMENT_SLOT_LEGS         = 6
  49. local EQUIPMENT_SLOT_FEET         = 7
  50. local EQUIPMENT_SLOT_WRISTS       = 8
  51. local EQUIPMENT_SLOT_HANDS        = 9
  52. local EQUIPMENT_SLOT_FINGER1      = 10
  53. local EQUIPMENT_SLOT_FINGER2      = 11
  54. local EQUIPMENT_SLOT_TRINKET1     = 12
  55. local EQUIPMENT_SLOT_TRINKET2     = 13
  56. local EQUIPMENT_SLOT_BACK         = 14
  57. local EQUIPMENT_SLOT_MAINHAND     = 15
  58. local EQUIPMENT_SLOT_OFFHAND      = 16
  59. local EQUIPMENT_SLOT_RANGED       = 17
  60. local EQUIPMENT_SLOT_TABARD       = 18
  61. local EQUIPMENT_SLOT_END          = 19
  62.  
  63. local INVENTORY_SLOT_BAG_START    = 19
  64. local INVENTORY_SLOT_BAG_END      = 23
  65.  
  66. local INVENTORY_SLOT_ITEM_START   = 23
  67. local INVENTORY_SLOT_ITEM_END     = 39
  68.  
  69. local INVTYPE_CHEST               = 5
  70. local INVTYPE_WEAPON              = 13
  71. local INVTYPE_TWOHAND             = 17
  72. local INVTYPE_ROBE                = 20
  73. local INVTYPE_WEAPONMAINHAND      = 21
  74. local INVTYPE_WEAPONOFFHAND       = 22
  75.  
  76. local ITEM_CLASS_WEAPON           = 2
  77. local ITEM_CLASS_ARMOR            = 4
  78.  
  79. local ITEM_SUBCLASS_WEAPON_BOW          = 2
  80. local ITEM_SUBCLASS_WEAPON_GUN          = 3
  81. local ITEM_SUBCLASS_WEAPON_CROSSBOW     = 18
  82. local ITEM_SUBCLASS_WEAPON_FISHING_POLE = 20
  83.  
  84. local PLAYER_VISIBLE_ITEM_1_ENTRYID = 283
  85.  
  86. local INVENTORY_SLOT_BAG_0        = 255
  87.  
  88. local SlotNames = {
  89.     [EQUIPMENT_SLOT_HEAD      ] = {"Head",         nil, nil, nil, nil, nil, nil, nil, nil},
  90.     [EQUIPMENT_SLOT_SHOULDERS ] = {"Shoulders",    nil, nil, nil, nil, nil, nil, nil, nil},
  91.     [EQUIPMENT_SLOT_BODY      ] = {"Shirt",        nil, nil, nil, nil, nil, nil, nil, nil},
  92.     [EQUIPMENT_SLOT_CHEST     ] = {"Chest",        nil, nil, nil, nil, nil, nil, nil, nil},
  93.     [EQUIPMENT_SLOT_WAIST     ] = {"Waist",        nil, nil, nil, nil, nil, nil, nil, nil},
  94.     [EQUIPMENT_SLOT_LEGS      ] = {"Legs",         nil, nil, nil, nil, nil, nil, nil, nil},
  95.     [EQUIPMENT_SLOT_FEET      ] = {"Feet",         nil, nil, nil, nil, nil, nil, nil, nil},
  96.     [EQUIPMENT_SLOT_WRISTS    ] = {"Wrists",       nil, nil, nil, nil, nil, nil, nil, nil},
  97.     [EQUIPMENT_SLOT_HANDS     ] = {"Hands",        nil, nil, nil, nil, nil, nil, nil, nil},
  98.     [EQUIPMENT_SLOT_BACK      ] = {"Back",         nil, nil, nil, nil, nil, nil, nil, nil},
  99.     [EQUIPMENT_SLOT_MAINHAND  ] = {"Main hand",    nil, nil, nil, nil, nil, nil, nil, nil},
  100.     [EQUIPMENT_SLOT_OFFHAND   ] = {"Off hand",     nil, nil, nil, nil, nil, nil, nil, nil},
  101.     [EQUIPMENT_SLOT_RANGED    ] = {"Ranged",       nil, nil, nil, nil, nil, nil, nil, nil},
  102.     [EQUIPMENT_SLOT_TABARD    ] = {"Tabard",       nil, nil, nil, nil, nil, nil, nil, nil},
  103. }
  104. local Locales = {
  105.     {"Update menu", nil, nil, nil, nil, nil, nil, nil, nil},
  106.     {"Remove all transmogrifications", nil, nil, nil, nil, nil, nil, nil, nil},
  107.     {"Remove transmogrifications from all equipped items?", nil, nil, nil, nil, nil, nil, nil, nil},
  108.     {"Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?", nil, nil, nil, nil, nil, nil, nil, nil},
  109.     {"Remove transmogrification from %s?", nil, nil, nil, nil, nil, nil, nil, nil},
  110.     {"Back..", nil, nil, nil, nil, nil, nil, nil, nil},
  111.     {"Remove transmogrification", nil, nil, nil, nil, nil, nil, nil, nil},
  112.     {"Transmogrifications removed from equipped items", nil, nil, nil, nil, nil, nil, nil, nil},
  113.     {"You have no transmogrified items equipped", nil, nil, nil, nil, nil, nil, nil, nil},
  114.     {"%s transmogrification removed", nil, nil, nil, nil, nil, nil, nil, nil},
  115.     {"No transmogrification on %s slot", nil, nil, nil, nil, nil, nil, nil, nil},
  116.     {"%s transmogrified", nil, nil, nil, nil, nil, nil, nil, nil},
  117.     {"Selected items are not suitable", nil, nil, nil, nil, nil, nil, nil, nil},
  118.     {"Selected item does not exist", nil, nil, nil, nil, nil, nil, nil, nil},
  119.     {"Equipment slot is empty", nil, nil, nil, nil, nil, nil, nil, nil},
  120.     {"You don't have enough %ss", nil, nil, nil, nil, nil, nil, nil, nil},
  121. }
  122. local function LocText(id, p) -- "%s":format("test")
  123.     if(Locales[id]) then
  124.         local s = Locales[id][p:GetDbcLocale()+1] or Locales[id][1]
  125.         if(s) then
  126.             return s
  127.         end
  128.     end
  129.     return "Text not found: "..(id or 0)
  130. end
  131. --[[
  132. typedef UNORDERED_MAP<uint32, uint32> transmogData
  133. typedef UNORDERED_MAP<uint32, transmogData> transmogMap
  134. static transmogMap entryMap -- entryMap[pGUID][iGUID] = entry
  135. static transmogData dataMap -- dataMap[iGUID] = pGUID
  136. ]]
  137. local entryMap = {}
  138. local dataMap = {}
  139.  
  140. local function GetSlotName(slot, locale)
  141.     if(not SlotNames[slot]) then return end
  142.     return SlotNames[slot][locale and locale+1 or 1]
  143. end
  144.  
  145. local function GetFakePrice(item)
  146.     local sellPrice = item:GetSellPrice()
  147.     local minPrice = item:GetRequiredLevel() * 1176
  148.     if (sellPrice < minPrice) then
  149.         sellPrice = minPrice
  150.     end
  151.     return sellPrice
  152. end
  153.  
  154. local function GetFakeEntry(item)
  155.     local guid = item and item:GetGUIDLow()
  156.     if(guid and dataMap[guid]) then
  157.         if(entryMap[dataMap[guid]]) then
  158.             return entryMap[dataMap[guid]][guid]
  159.         end
  160.     end
  161. end
  162.  
  163. local function DeleteFakeFromDB(itemGUID)
  164.     if (dataMap[itemGUID]) then
  165.         if(entryMap[dataMap[itemGUID]]) then
  166.             entryMap[dataMap[itemGUID]][itemGUID] = nil
  167.         end
  168.         dataMap[itemGUID] = nil
  169.     end
  170.     CharDBExecute("DELETE FROM custom_transmogrification WHERE GUID = "..itemGUID)
  171. end
  172.  
  173. local function DeleteFakeEntry(item)
  174.     if (not GetFakeEntry(item)) then
  175.         return false
  176.     end
  177.     item:GetOwner():SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * 2), item:GetEntry())
  178.     DeleteFakeFromDB(item:GetGUIDLow())
  179.     return true
  180. end
  181.  
  182. local function SetFakeEntry(item, entry)
  183.     local player = item:GetOwner()
  184.     if(player) then
  185.         local pGUID = player:GetGUIDLow()
  186.         local iGUID = item:GetGUIDLow()
  187.         player:SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * 2), entry)
  188.         if(not entryMap[pGUID]) then
  189.             entryMap[pGUID] = {}
  190.         end
  191.         entryMap[pGUID][iGUID] = entry
  192.         dataMap[iGUID] = pGUID
  193.         CharDBExecute("REPLACE INTO custom_transmogrification (GUID, FakeEntry, Owner) VALUES ("..iGUID..", "..entry..", "..pGUID..")")
  194.     end
  195. end
  196.  
  197. local function GetTransmogSubClass(class, subclass)
  198.     if class == ITEM_CLASS_WEAPON then
  199.         if subclass == ITEM_SUBCLASS_WEAPON_GUN or subclass == ITEM_SUBCLASS_WEAPON_CROSSBOW then
  200.             return ITEM_SUBCLASS_WEAPON_BOW
  201.         elseif subclass == 1 then
  202.             return 0
  203.         elseif subclass == 5 then
  204.             return 4
  205.         elseif subclass == 8 then
  206.             return 7
  207.         end
  208.     end
  209.     return subclass
  210. end
  211.  
  212. local function SuitableForTransmogrification(player, oldItem, newItem)
  213.     -- not possibly the best structure here, but atleast I got my head around this
  214.     if (not Qualities[newItem:GetQuality()]) then
  215.         return false
  216.     end
  217.     if (not Qualities[oldItem:GetQuality()]) then
  218.         return false
  219.     end
  220.  
  221.     if(oldItem:GetDisplayId() == newItem:GetDisplayId()) then
  222.         return false
  223.     end
  224.     --if (GetFakeEntry(oldItem))
  225.     --    if (const ItemTemplate* fakeItemTemplate = sObjectMgr:GetItemTemplate(GetFakeEntry(oldItem)))
  226.     --        if (fakeItemTemplate:DisplayInfoID == newItem:GetTemplate():DisplayInfoID)
  227.     --            return false
  228.     local fentry = GetFakeEntry(oldItem)
  229.     if(fentry and fentry == newItem:GetEntry()) then
  230.         return false
  231.     end
  232.     if (player:CanUseItem(newItem) ~= 0) then
  233.         return false
  234.     end
  235.     local newClass = newItem:GetClass()
  236.     local oldClass = oldItem:GetClass()
  237.     local newSubClass = newItem:GetSubClass()
  238.     local oldSubClass = oldItem:GetSubClass()
  239.     local newInventorytype = newItem:GetInventoryType()
  240.     local oldInventorytype = oldItem:GetInventoryType()
  241.     if (newClass ~= oldClass) then
  242.         return false
  243.     end
  244.     if (newClass == ITEM_CLASS_WEAPON and newSubClass ~= ITEM_SUBCLASS_WEAPON_FISHING_POLE and oldSubClass ~= ITEM_SUBCLASS_WEAPON_FISHING_POLE) then
  245.         if GetTransmogSubClass(newClass, newSubClass) == GetTransmogSubClass(oldClass, oldSubClass) then
  246.             if (newInventorytype == oldInventorytype or (newInventorytype == INVTYPE_WEAPON and (oldInventorytype == INVTYPE_WEAPONMAINHAND or oldInventorytype == INVTYPE_WEAPONOFFHAND))
  247.             or (newInventorytype == INVTYPE_TWOHAND  and (oldInventorytype == INVTYPE_WEAPON or oldInventorytype == INVTYPE_WEAPONMAINHAND or oldInventorytype == INVTYPE_WEAPONOFFHAND))
  248.             or (oldInventorytype == INVTYPE_TWOHAND  and (newInventorytype == INVTYPE_WEAPON or newInventorytype == INVTYPE_WEAPONMAINHAND or newInventorytype == INVTYPE_WEAPONOFFHAND))) then
  249.                 return true
  250.             else
  251.                 return false
  252.             end
  253.         else
  254.             return false
  255.         end
  256.     elseif (newClass == ITEM_CLASS_ARMOR) then
  257.         --if (newSubClass == oldSubClass) then_ -- commented out to allow leather-plate transmog
  258.         if (newInventorytype == oldInventorytype or (newInventorytype == INVTYPE_CHEST and oldInventorytype == INVTYPE_ROBE) or (newInventorytype == INVTYPE_ROBE and oldInventorytype == INVTYPE_CHEST)) then
  259.             return true
  260.         else
  261.             return false
  262.         end
  263.         --else_
  264.         --  return false
  265.         --end
  266.     end
  267.     return false
  268. end
  269.  
  270. local menu_id = math.random(1000)
  271.  
  272. local function OnGossipHello(event, player, creature)
  273.     player:GossipClearMenu()
  274.     for slot = EQUIPMENT_SLOT_START, EQUIPMENT_SLOT_END-1 do
  275.         local newItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slot)
  276.         if (newItem) then
  277.             if (Qualities[newItem:GetQuality()]) then
  278.                 local slotName = GetSlotName(slot, player:GetDbcLocale())
  279.                 if (slotName) then
  280.                     player:GossipMenuAddItem(3, slotName, EQUIPMENT_SLOT_END, slot)
  281.                 end
  282.             end
  283.         end
  284.     end
  285.     player:GossipMenuAddItem(4, LocText(2, player), EQUIPMENT_SLOT_END+2, 0, false, LocText(3, player), 0)
  286.     player:GossipMenuAddItem(7, LocText(1, player), EQUIPMENT_SLOT_END+1, 0)
  287.     player:GossipSendMenu(100, creature, menu_id)
  288. end
  289.  
  290. local _items = {}
  291. local function OnGossipSelect(event, player, creature, se_nder, uiAction)
  292.     if se_nder == EQUIPMENT_SLOT_END then -- Show items you can use
  293.         local oldItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, uiAction)
  294.         if (oldItem) then
  295.             local lowGUID = player:GetGUIDLow()
  296.             _items[lowGUID] = {} -- Remove this with logix
  297.             local limit = 0
  298.             local price = 0
  299.             if(RequireGold == 1) then
  300.                 price = GetFakePrice(oldItem)*GoldModifier
  301.             elseif(RequireGold == 2) then
  302.                 price = GoldCost
  303.             end
  304.  
  305.             for i = INVENTORY_SLOT_ITEM_START, INVENTORY_SLOT_ITEM_END-1 do
  306.                 if (limit > 30) then
  307.                     break
  308.                 end
  309.                 local newItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, i)
  310.                 if (newItem) then
  311.                     local display = newItem:GetDisplayId()
  312.                     if (SuitableForTransmogrification(player, oldItem, newItem)) then
  313.                         if (not _items[lowGUID][display]) then
  314.                             limit = limit + 1
  315.                             _items[lowGUID][display] = {newItem:GetBagSlot(), newItem:GetSlot()}
  316.                             local popup = LocText(4, player).."\n\n"..newItem:GetItemLink(player:GetDbcLocale()).."\n"
  317.                             if(RequireToken) then
  318.                                 popup = popup.."\n"..TokenAmount.." x "..GetItemLink(TokenEntry, player:GetDbcLocale())
  319.                             end
  320.                             player:GossipMenuAddItem(4, newItem:GetItemLink(player:GetDbcLocale()), uiAction, display, false, popup, price)
  321.                         end
  322.                     end
  323.                 end
  324.             end
  325.  
  326.             for i = INVENTORY_SLOT_BAG_START, INVENTORY_SLOT_BAG_END-1 do
  327.                 local bag = player:GetItemByPos(INVENTORY_SLOT_BAG_0, i)
  328.                 if (bag) then
  329.                     for j = 0, bag:GetBagSize()-1 do
  330.                         if (limit > 30) then
  331.                             break
  332.                         end
  333.                         local newItem = player:GetItemByPos(i, j)
  334.                         if (newItem) then
  335.                             local display = newItem:GetDisplayId()
  336.                             if (SuitableForTransmogrification(player, oldItem, newItem)) then
  337.                                 if (not _items[lowGUID][display]) then
  338.                                     limit = limit + 1
  339.                                     _items[lowGUID][display] = {newItem:GetBagSlot(), newItem:GetSlot()}
  340.                                     player:GossipMenuAddItem(4, newItem:GetItemLink(player:GetDbcLocale()), uiAction, display, false, popup, price)
  341.                                 end
  342.                             end
  343.                         end
  344.                     end
  345.                 end
  346.             end
  347.  
  348.             player:GossipMenuAddItem(4, LocText(7, player), EQUIPMENT_SLOT_END+3, uiAction, false, LocText(5, player):format(GetSlotName(uiAction, player:GetDbcLocale())))
  349.             player:GossipMenuAddItem(7, LocText(6, player), EQUIPMENT_SLOT_END+1, 0)
  350.             player:GossipSendMenu(100, creature, menu_id)
  351.         else
  352.             OnGossipHello(event, player, creature)
  353.         end
  354.     elseif se_nder == EQUIPMENT_SLOT_END+1 then -- Back
  355.         OnGossipHello(event, player, creature)
  356.     elseif se_nder == EQUIPMENT_SLOT_END+2 then -- Remove Transmogrifications
  357.         local removed = false
  358.         for slot = EQUIPMENT_SLOT_START, EQUIPMENT_SLOT_END-1 do
  359.             local newItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slot)
  360.             if (newItem) then
  361.                 if (DeleteFakeEntry(newItem) and not removed) then
  362.                     removed = true
  363.                 end
  364.             end
  365.         end
  366.         if (removed) then
  367.             player:SendAreaTriggerMessage(LocText(8, player))
  368.             player:PlayDirectSound(3337)
  369.         else
  370.             player:SendNotification(LocText(9, player))
  371.         end
  372.         OnGossipHello(event, player, creature)
  373.     elseif se_nder == EQUIPMENT_SLOT_END+3 then -- Remove Transmogrification from single item
  374.         local newItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, uiAction)
  375.         if (newItem) then
  376.             if (DeleteFakeEntry(newItem)) then
  377.                 player:SendAreaTriggerMessage(LocText(10, player):format(GetSlotName(uiAction, player:GetDbcLocale())))
  378.                 player:PlayDirectSound(3337)
  379.             else
  380.                 player:SendNotification(LocText(11, player):format(GetSlotName(uiAction, player:GetDbcLocale())))
  381.             end
  382.         end
  383.         OnGossipSelect(event, player, creature, EQUIPMENT_SLOT_END, uiAction)
  384.     else -- Transmogrify
  385.         local lowGUID = player:GetGUIDLow()
  386.         if(not RequireToken or player:GetItemCount(TokenEntry) >= TokenAmount) then
  387.             local oldItem = player:GetItemByPos(INVENTORY_SLOT_BAG_0, se_nder)
  388.             if (oldItem) then
  389.                 if (_items[lowGUID] and _items[lowGUID][uiAction] and _items[lowGUID][uiAction]) then
  390.                     local newItem = player:GetItemByPos(_items[lowGUID][uiAction][1], _items[lowGUID][uiAction][2])
  391.                     if (newItem:GetOwnerGUID() == player:GetGUID() and (newItem:IsInBag() or newItem:GetBagSlot() == INVENTORY_SLOT_BAG_0) and SuitableForTransmogrification(player, oldItem, newItem)) then
  392.                         local price
  393.                         if(RequireGold == 1) then
  394.                             price = GetFakePrice(oldItem)*GoldModifier
  395.                         elseif(RequireGold == 2) then
  396.                             price = GoldCost
  397.                         end
  398.                         if(price) then player:ModifyMoney(-1*price) end
  399.                         if(RequireToken) then
  400.                             player:RemoveItem(TokenEntry, TokenAmount)
  401.                         end
  402.                         SetFakeEntry(oldItem, newItem:GetEntry())
  403.                         -- newItem:SetNotRefundable(player)
  404.                         newItem:SetBinding(true)
  405.                         player:PlayDirectSound(3337)
  406.                         player:SendAreaTriggerMessage(LocText(12, player):format(GetSlotName(se_nder, player:GetDbcLocale())))
  407.                     else
  408.                         player:SendNotification(LocText(13, player))
  409.                     end
  410.                 else
  411.                     player:SendNotification(LocText(14, player))
  412.                 end
  413.             else
  414.                 player:SendNotification(LocText(15, player))
  415.             end
  416.         else
  417.             player:SendNotification(LocText(16, player):format(GetItemLink(TokenEntry, player:GetDbcLocale())))
  418.         end
  419.         _items[lowGUID] = {}
  420.         OnGossipSelect(event, player, creature, EQUIPMENT_SLOT_END, se_nder)
  421.     end
  422. end
  423.  
  424. local function OnLogin(event, player)
  425.     local playerGUID = player:GetGUIDLow()
  426.     entryMap[playerGUID] = {}
  427.     local result = CharDBQuery("SELECT GUID, FakeEntry FROM custom_transmogrification WHERE Owner = "..playerGUID)
  428.     if (result) then
  429.         repeat
  430.             local itemGUID = result:GetUInt32(0)
  431.             local fakeEntry = result:GetUInt32(1)
  432.             -- if (sObjectMgr:GetItemTemplate(fakeEntry)) then_
  433.             -- {_
  434.             dataMap[itemGUID] = playerGUID
  435.             entryMap[playerGUID][itemGUID] = fakeEntry
  436.             -- }
  437.             -- else_
  438.             --     sLog:outError(LOG_FILTER_SQL, "Item entry (Entry: %u, itemGUID: %u, playerGUID: %u) does not exist, deleting.", fakeEntry, itemGUID, playerGUID)
  439.             --     Transmogrification::DeleteFakeFromDB(itemGUID)
  440.             -- end
  441.         until not result:NextRow()
  442.  
  443.         for slot = EQUIPMENT_SLOT_START, EQUIPMENT_SLOT_END-1 do
  444.             local item = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slot)
  445.             if (item) then
  446.                 if(entryMap[playerGUID]) then
  447.                     if(entryMap[playerGUID][item:GetGUIDLow()]) then
  448.                         player:SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * 2), entryMap[playerGUID][item:GetGUIDLow()])
  449.                     end
  450.                 end
  451.             end
  452.         end
  453.     end
  454. end
  455.  
  456. local function OnLogout(event, player)
  457.     local pGUID = player:GetGUIDLow()
  458.     entryMap[pGUID] = nil
  459. end
  460.  
  461. local function OnEquip(event, player, item, bag, slot)
  462.     local fentry = GetFakeEntry(item)
  463.     if (fentry) then
  464.         if(item:GetOwnerGUID() ~= player:GetGUID()) then
  465.             DeleteFakeFromDB(item:GetGUIDLow())
  466.             return
  467.         end
  468.         player:SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * 16), fentry)
  469.     else
  470.         -- player:SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * 16), pItem:GetEntry())
  471.     end
  472. end
  473.  
  474. -- Note, Query is instant when Execute is delayed
  475. CharDBQuery([[
  476. CREATE TABLE IF NOT EXISTS `custom_transmogrification` (
  477. `GUID` INT(10) UNSIGNED NOT NULL COMMENT 'Item guidLow',
  478. `FakeEntry` INT(10) UNSIGNED NOT NULL COMMENT 'Item entry',
  479. `Owner` INT(10) UNSIGNED NOT NULL COMMENT 'Player guidLow',
  480. PRIMARY KEY (`GUID`)
  481. )
  482. COMMENT='version 4.0'
  483. COLLATE='latin1_swedish_ci'
  484. ENGINE=InnoDB;
  485. ]])
  486.  
  487. print("Deleting non-existing transmogrification entries...")
  488. CharDBQuery("DELETE FROM custom_transmogrification WHERE NOT EXISTS (SELECT 1 FROM item_instance WHERE item_instance.guid = custom_transmogrification.GUID)")
  489.  
  490. RegisterPlayerEvent(3, OnLogin)
  491. RegisterPlayerEvent(4, OnLogout)
  492. RegisterPlayerEvent(29, OnEquip)
  493.  
  494. -- Test code
  495. -- RegisterPlayerEvent(18, function(e,p,m,t,l) if(m == "test") then OnGossipHello(e,p,p) end end)
  496. -- RegisterPlayerGossipEvent(menu_id, 2, OnGossipSelect)
  497.  
  498. RegisterCreatureGossipEvent(NPC_Entry, 1, OnGossipHello)
  499. RegisterCreatureGossipEvent(NPC_Entry, 2, OnGossipSelect)
  500.  
  501. local plrs = GetPlayersInWorld()
  502. if(plrs) then
  503.     for k, player in ipairs(plrs) do
  504.         OnLogin(k, player)
  505.     end
  506. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement