Advertisement
Guest User

Visual Enchat Lua Script

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