Advertisement
conan513

Untitled

Jun 24th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. --[[
  2. Author: Rochet2 - https://rochet2.github.io/
  3. Source: http://emudevs.com/showthread.php/53-Lua-Enchant-visual-system-and-gossip
  4.  
  5. About:
  6. All weapons looted have a 25% chance to have a random enchant visual
  7. This is purely visual fun and the visual will be replaced when the weapon is enchanted.
  8.  
  9. This script is 100% automatic. You can only put it to your script folder and it will work.
  10. ]]
  11.  
  12. local chance = 1.0
  13.  
  14. -- Do not edit anything below
  15.  
  16. local charactersSQL = [[
  17. CREATE TABLE IF NOT EXISTS `custom_item_enchant_visuals` (
  18.     `iguid` INT(10) UNSIGNED NOT NULL COMMENT 'item DB guid',
  19.     `display` INT(10) UNSIGNED NOT NULL COMMENT 'enchantID',
  20.     PRIMARY KEY (`iguid`)
  21. )
  22. COMMENT='stores the enchant IDs for the visuals'
  23. COLLATE='utf8_general_ci'
  24. ENGINE=InnoDB;
  25. ]]
  26. CharDBQuery(charactersSQL)
  27.  
  28. -- script variables:
  29. local EQUIPMENT_SLOT_MAINHAND = 15
  30. local EQUIPMENT_SLOT_OFFHAND = 16
  31. local PLAYER_VISIBLE_ITEM_1_ENCHANTMENT = 284
  32. local PERM_ENCHANTMENT_SLOT = 0
  33. local DD
  34.  
  35. -- functions
  36. local LoadDB, setVisual, applyVisuals, LOGIN
  37.  
  38. function LoadDB()
  39.     DD = {}
  40.     CharDBQuery("DELETE FROM custom_item_enchant_visuals WHERE NOT EXISTS(SELECT 1 FROM item_instance WHERE custom_item_enchant_visuals.iguid = item_instance.guid)")
  41.     local Q = CharDBQuery("SELECT iguid, display FROM custom_item_enchant_visuals")
  42.     if (Q) then
  43.         repeat
  44.             local iguid, display = Q:GetUInt32(0), Q:GetUInt32(1)
  45.             DD[iguid] = display
  46.         until not Q:NextRow()
  47.     end
  48. end
  49. LoadDB()
  50.  
  51. function setVisual(player, item, display)
  52.     if (not player or not item) then return
  53.         false
  54.     end
  55.     local iguid = item:GetGUIDLow()
  56.     local enID = item:GetEnchantmentId(PERM_ENCHANTMENT_SLOT) or 0
  57.     if (enID ~= 0) then
  58.         CharDBExecute("DELETE FROM custom_item_enchant_visuals WHERE iguid = "..iguid)
  59.         DD[iguid] = nil
  60.         display = enID
  61.     elseif (not display) then
  62.         if (not DD[iguid]) then
  63.             return false
  64.         end
  65.         display = DD[iguid]
  66.     else
  67.         CharDBExecute("REPLACE INTO custom_item_enchant_visuals (iguid, display) VALUES ("..iguid..", "..display..")")
  68.         DD[iguid] = display
  69.     end
  70.     if (item:IsEquipped()) then
  71.         player:SetUInt16Value(PLAYER_VISIBLE_ITEM_1_ENCHANTMENT + (item:GetSlot() * 2), 0, display)
  72.     end
  73.     return true
  74. end
  75.  
  76. function applyVisuals(player)
  77.     if (not player) then
  78.         return
  79.     end
  80.     for i = EQUIPMENT_SLOT_MAINHAND, EQUIPMENT_SLOT_OFFHAND do
  81.         setVisual(player, player:GetItemByPos(255, i))
  82.     end
  83. end
  84.  
  85. function LOGIN(event, player)
  86.     applyVisuals(player)
  87. end
  88.  
  89. RegisterPlayerEvent(3, LOGIN)
  90. RegisterPlayerEvent(29, function(e,p,i,b,s) setVisual(p, i) end)
  91.  
  92. -- Enchant IDs
  93. local E = {3789, 3854, 3273, 3225, 3870, 1899, 2674, 2675, 2671, 2672, 3365, 2673, 2343, 425, 3855, 1894, 1103, 1898, 3345, 1743, 3093, 1900, 3846, 1606, 283, 1, 3265, 2, 3, 3266, 1903, 13, 26, 7, 803, 1896, 2666, 253789, 3854, 3273, 3225, 3870, 1899, 2674, 2675, 2671, 2672, 3365, 2673, 2343, 425, 3855, 1894, 1103, 1898, 3345, 1743, 3093, 1900, 3846, 1606, 283, 1, 3265, 2, 3, 3266, 1903, 13, 26, 7, 803, 1896, 2666, 25}
  94. local SubClasses = {
  95.     [0] = true,
  96.     [1] = true,
  97.     [4] = true,
  98.     [5] = true,
  99.     [6] = true,
  100.     [7] = true,
  101.     [8] = true,
  102.     [10] = true,
  103.     [11] = true,
  104.     [12] = true,
  105.     [14] = true,
  106.     [15] = true,
  107. }
  108.  
  109. math.randomseed(os.time())
  110. local function ONITEMLOOT(event, player, item, count, guid)
  111.     if (item:GetClass() == 2 and SubClasses[item:GetSubClass()]) then
  112.         if (math.random() < chance) then -- 25% of looted weapons get the visuals
  113.             setVisual(player, item, E[math.random(#E)])
  114.         end
  115.     end
  116. end
  117.  
  118. RegisterPlayerEvent(32, ONITEMLOOT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement