Advertisement
Rochet2

Enchant display system

Apr 21st, 2013
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.83 KB | None | 0 0
  1. -- Enchant display system:
  2.  
  3. --[[
  4. -- SQL:
  5.     CREATE TABLE `custom_item_enchant_visuals` (
  6.         `iguid` INT(10) UNSIGNED NOT NULL COMMENT 'item DB guid',
  7.         `display` INT(10) UNSIGNED NOT NULL COMMENT 'enchantID',
  8.         PRIMARY KEY (`iguid`)
  9.     )
  10.     COMMENT='stores the enchant IDs for the visuals'
  11.     COLLATE='latin1_swedish_ci'
  12.     ENGINE=InnoDB;
  13. ]]
  14.  
  15. -- script variables:
  16. local EQUIPMENT_SLOT_MAINHAND = 15
  17. local EQUIPMENT_SLOT_OFFHAND = 16
  18. local PLAYER_VISIBLE_ITEM_1_ENCHANTMENT = 284
  19. local PERM_ENCHANTMENT_SLOT = 0
  20. local DD = {}
  21.  
  22. -- functions
  23. local LoadDB, setVisual, applyVisuals, LOGOUT, LOGIN
  24.  
  25. function LoadDB()
  26.     DD = {}
  27.     CharDBQuery("DELETE FROM custom_item_enchant_visuals WHERE NOT EXISTS(SELECT 1 FROM item_instance WHERE custom_item_enchant_visuals.iguid = item_instance.guid)")
  28.     local Q = CharDBQuery("SELECT iguid, display FROM custom_item_enchant_visuals")
  29.     if(Q) then
  30.         repeat
  31.             local iguid, display = Q:GetUInt32(0), Q:GetUInt32(1)
  32.             DD[iguid] = display
  33.         until not Q:NextRow()
  34.     end
  35. end
  36. LoadDB()
  37.  
  38. function setVisual(player, item, display)
  39.     if(not player or not item or not item:IsEquipped()) then return false end
  40.     local iguid = item:GetGUIDLow()
  41.     if(not display) then
  42.         if(not DD[iguid]) then return false end
  43.         display = DD[iguid]
  44.     elseif(display ~= 0) then
  45.         CharDBExecute("REPLACE INTO custom_item_enchant_visuals (iguid, display) VALUES ("..iguid..", "..display..")")
  46.         DD[iguid] = display
  47.     end
  48.     if(display == 0) then
  49.         display = item:GetEnchantmentId(PERM_ENCHANTMENT_SLOT) or 0
  50.         if(DD[iguid]) then
  51.             CharDBExecute("DELETE FROM custom_item_enchant_visuals WHERE iguid = "..iguid)
  52.             DD[iguid] = nil
  53.         end
  54.     end
  55.     player:SetUInt16Value(PLAYER_VISIBLE_ITEM_1_ENCHANTMENT + (item:GetSlot() * 2), 0, display)
  56.     return true
  57. end
  58.  
  59. function applyVisuals(player)
  60.     if(not player) then return end
  61.     for i = EQUIPMENT_SLOT_MAINHAND, EQUIPMENT_SLOT_OFFHAND do
  62.         setVisual(player, player:GetItemByPos(255, i))
  63.     end
  64. end
  65.  
  66. function LOGIN(event, player)
  67.     applyVisuals(player)
  68. end
  69.  
  70. RegisterPlayerEvent(3, LOGIN)
  71. RegisterPlayerEvent(29, function(e,p,i,b,s) setVisual(p, i) end)
  72.  
  73. -- Enchant display gossip:
  74.  
  75. -- Enchant IDs and their names
  76. local E = {
  77.     {0, "Reset"},
  78.     {3789, "Berserking"},
  79.     {3854, "Spell Power"},
  80.     {3273, "Deathfrost"},
  81.     {3225, "Executioner"},
  82.     {3870, "Blood Draining"},
  83.     {1899, "Unholy Weapon"},
  84.     {2674, "Spellsurge"},
  85.     {2675, "Battlemaster"},
  86.     {2671, "Arcane and Fire Spell Power"},
  87.     {2672, "Shadow and Frost Spell Power"},
  88.     {3365, "Rune of Swordshattering"},
  89.     {2673, "Mongoose"},
  90.     {2343, "Spell Power"},
  91.     {425, "Black Temple Dummy"},
  92.     {3855, "Spell Power"},
  93.     {1894, "Icy Weapon"},
  94.     {1103, "Agility"},
  95.     {1898, "Lifestealing"},
  96.     {3345, "Earthliving 1"},
  97.     {1743, "MHTest02"},
  98.     {3093, "Attack Power vs Undead and Demons"},
  99.     {1900, "Crusader"},
  100.     {3846, "Spell Power"},
  101.     {1606, "Attack Power"},
  102.     {283, "Windfury 1"},
  103.     {1, "Rockbiter 3"},
  104.     {3265, "Blessed Weapon Coating"},
  105.     {2, "Frostbrand 1"},
  106.     {3, "Flametongue 3"},
  107.     {3266, "Righteous Weapon Coating"},
  108.     {1903, "Spirit"},
  109.     {13, "Sharpened (+3 Damage)"},
  110.     {26, "Frost Oil"},
  111.     {7, "Deadly Poison"},
  112.     {803, "Fiery Weapon"},
  113.     {1896, "Weapon Damage"},
  114.     {2666, "Intellect"},
  115.     {25, "Shadow Oil"},
  116. }
  117.  
  118. -- script variables:
  119. local chatCommand = "asd"
  120. local maxGossipItems = 14 -- per page
  121. local menu_id = 123
  122.  
  123. local safeGossipItems = 100 -- main menu: sender = safeGossipItems-1
  124. local EQUIPMENT_SLOT_MAINHAND = 15
  125. local EQUIPMENT_SLOT_OFFHAND = 16
  126. local D = {}
  127.  
  128. -- functions:
  129. local showItems, HELLO, SELECT, CHAT
  130.  
  131. function showItems(player, unit, offset)
  132.     local temp = (maxGossipItems)*offset+1
  133.     for i = temp, temp+maxGossipItems-1 do
  134.         local v = E[i]
  135.         if(not v) then break end
  136.         player:GossipMenuAddItem(9, v[2], safeGossipItems+offset, v[1]+1)
  137.     end
  138.     if(temp+maxGossipItems-1 < #E) then
  139.         player:GossipMenuAddItem(7, "Next..", safeGossipItems+offset+1, 0)
  140.     end
  141.     player:GossipMenuAddItem(7, "Back..", safeGossipItems+offset-1, 0)
  142.     player:GossipSendMenu(100, unit, menu_id)
  143. end
  144.    
  145. function HELLO(event, player, unit)
  146.     player:GossipMenuAddItem(9, "Main hand", 0, EQUIPMENT_SLOT_MAINHAND)
  147.     player:GossipMenuAddItem(9, "Off hand", 0, EQUIPMENT_SLOT_OFFHAND)
  148.     player:GossipSendMenu(100, unit, menu_id)
  149. end
  150.  
  151. function CHAT(event, player, msg, Type, lang)
  152.     if(msg == chatCommand) then
  153.         player:GossipClearMenu()
  154.         HELLO(1, player, player)
  155.         return false
  156.     end
  157. end
  158.  
  159. function SELECT(event, player, unit, sender, action, code)
  160.     local guid = player:GetGUIDLow()
  161.     if(not D[guid]) then
  162.         D[guid] = {}
  163.     end
  164.     if(sender == safeGossipItems-1 and action == 0) then
  165.         HELLO(event, player, unit)
  166.     elseif(sender >= safeGossipItems) then
  167.         if(action ~= 0) then
  168.             D[guid].display = action-1
  169.             if(D[guid].slot and D[guid].display) then
  170.                 local item = player:GetItemByPos(255, D[guid].slot)
  171.                 if(not item) then
  172.                     player:SendNotification("No item equipped in selected slot")
  173.                 else
  174.                     setVisual(player, item, D[guid].display)
  175.                 end
  176.             end
  177.         end
  178.         showItems(player, unit, sender-safeGossipItems)
  179.     elseif(sender == 0) then
  180.         D[guid].slot = action
  181.         showItems(player, unit, 0)
  182.     else
  183.         player:GossipCloseMenu()
  184.     end
  185. end
  186.  
  187. function LOGOUT(event, player)
  188.     D[player:GetGUIDLow()] = nil
  189. end
  190.  
  191. RegisterPlayerEvent(4, LOGOUT)
  192. RegisterPlayerEvent(18, CHAT)
  193. RegisterPlayerGossipEvent(menu_id, 2, SELECT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement