Advertisement
Guest User

cooldowns

a guest
Mar 2nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.00 KB | None | 0 0
  1. if UnitClass("player") == "Warrior" then
  2.  
  3. local _G = getfenv(0)
  4. local editmode = false
  5. local CreateFrames, SetCooldown
  6.  
  7. function WHUD_Cooldowns_Init()
  8. CreateFrames()
  9. WHUD_Cooldowns_VarUpdate()
  10. end
  11.  
  12. function CreateFrames()
  13. -- basic frame
  14. CreateFrame("Frame", "WHUD_CDBAR", UIParent)
  15. WHUD_CDBAR:SetHeight(85)
  16. WHUD_CDBAR:SetWidth(120)
  17. WHUD_CDBAR:EnableMouse(false)
  18. WHUD_CDBAR:SetFrameStrata(WHUD_VARS.Cooldowns.strata)
  19. WHUD_CDBAR:SetScale(WHUD_VARS.Cooldowns.scale)
  20. WHUD_CDBAR:SetAlpha(WHUD_VARS.Cooldowns.transparency)
  21. WHUD_CDBAR:SetPoint("CENTER", "UIParent", WHUD_VARS.Cooldowns.X ,WHUD_VARS.Cooldowns.Y)
  22. WHUD_CDBAR:Show()
  23. -- create the icons now
  24. for i=1,6 do
  25. CreateFrame("Frame", "WHUD_CDBAR"..i, WHUD_CDBAR)
  26. _G["WHUD_CDBAR"..i]:SetHeight(35)
  27. _G["WHUD_CDBAR"..i]:SetWidth(35)
  28. -- Texture
  29. _G["WHUD_CDBAR"..i]:CreateTexture("WHUD_CD"..i, "ARTWORK")
  30. _G["WHUD_CD"..i]:SetTexture("")
  31. _G["WHUD_CD"..i]:SetBlendMode("BLEND")
  32. _G["WHUD_CD"..i]:SetWidth(35)
  33. _G["WHUD_CD"..i]:SetHeight(35)
  34. _G["WHUD_CD"..i]:SetPoint("CENTER","WHUD_CDBAR"..i,0,0)
  35. -- Timer
  36. CreateFrame("Frame", "WHUD_CDBAR"..i.."_FRAME",_G["WHUD_CDBAR"..i])
  37. _G["WHUD_CDBAR"..i.."_FRAME"]:SetFrameStrata("DIALOG")
  38. _G["WHUD_CDBAR"..i.."_FRAME"]:CreateFontString("WHUD_CDBAR"..i.."_TIMER", "OVERLAY")
  39. _G["WHUD_CDBAR"..i.."_TIMER"]:SetParent(_G["WHUD_CDBAR"..i])
  40. _G["WHUD_CDBAR"..i.."_TIMER"]:SetFont("Interface\\AddOns\\WarriorHUD\\fonts\\Fishfingers.ttf", 20,"THINOUTLINE")
  41. _G["WHUD_CDBAR"..i.."_TIMER"]:SetPoint("CENTER",_G["WHUD_CDBAR"..i])
  42. _G["WHUD_CDBAR"..i.."_TIMER"]:SetText("")
  43. _G["WHUD_CDBAR"..i.."_TIMER"]:SetJustifyH("CENTER")
  44. _G["WHUD_CDBAR"..i.."_TIMER"]:SetTextColor(1,1,0,1)
  45. -- Clock animation
  46. CreateFrame("Model", "WHUD_CDBAR"..i.."CLOCKMODEL", _G["WHUD_CDBAR"..i], "CooldownFrameTemplate")
  47. -- INIT vars
  48. _G["WHUD_CD"..i.."_USED"] = ""
  49. _G["WHUD_CD"..i.."_TIME"] = 0
  50. _G["WHUD_CDBAR"..i.."_TIMER_START"] = 0
  51. _G["WHUD_CD"..i.."_CLOCK"] = false
  52. if WHUD_VARS.Cooldowns.fading then
  53. _G["WHUD_CD"..i.."_LAST"] = 0
  54. else
  55. _G["WHUD_CD"..i.."_LAST"] = WHUD_VARS.Cooldowns.transparency
  56. end
  57. end
  58. -- position them correctly
  59. WHUD_CDBAR1:SetPoint("CENTER",WHUD_CDBAR,0,-19)
  60. WHUD_CDBAR2:SetPoint("CENTER",WHUD_CDBAR1,-38,0)
  61. WHUD_CDBAR3:SetPoint("CENTER",WHUD_CDBAR1,38,0)
  62. WHUD_CDBAR4:SetPoint("CENTER",WHUD_CDBAR1,0,38)
  63. WHUD_CDBAR5:SetPoint("CENTER",WHUD_CDBAR4,-38,0)
  64. WHUD_CDBAR6:SetPoint("CENTER",WHUD_CDBAR4,38,0)
  65. end
  66.  
  67. function SetCooldown(name)
  68. if name then
  69. local id = WHUD_SPELLINFO[name][1]
  70. local startTime, duration = GetSpellCooldown(id,"player")
  71. local endTime
  72. if WHUD_SPELLINFO[name][2] == 0 or WHUD_SPELLINFO[name][3] == 0 then
  73. if startTime > 0 and duration > 0 then
  74. endTime = startTime + duration
  75. if endTime-GetTime() > 1.5 then -- this prevents the global cooldown to fuck shit up
  76. if WHUD_VARS.Cooldowns.fading then
  77. WHUD_SPELLINFO[name][2] = startTime
  78. WHUD_SPELLINFO[name][3] = endTime - WHUD_VARS.Cooldowns.fadetime
  79. else
  80. WHUD_SPELLINFO[name][2] = startTime
  81. WHUD_SPELLINFO[name][3] = endTime
  82. end
  83. end
  84. end
  85. end
  86. end
  87. end
  88.  
  89. function WHUD_Cooldowns_OnUpdate()
  90. if WHUD_VARS.Cooldowns.enabled then
  91. -- CLEARING THE COOLDOWN ICON SLOTS IF NEEDED
  92. if not editmode then
  93. for i=1,6 do
  94. if _G["WHUD_CD"..i.."_USED"] ~= "" and _G["WHUD_CD"..i.."_TIME"] > 0 then
  95. if WHUD_VARS.Cooldowns.fading and WHUD_SPELLINFO[_G["WHUD_CD"..i.."_USED"]][3] <= GetTime() then
  96. local value = (1-(((_G["WHUD_CD"..i.."_TIME"]+WHUD_VARS.Cooldowns.fadetime) - GetTime())/WHUD_VARS.Cooldowns.fadetime))* WHUD_VARS.Cooldowns.transparency
  97. if value > _G["WHUD_CD"..i.."_LAST"] and value > 0 and value <= 1 then
  98. _G["WHUD_CD"..i.."_LAST"] = value
  99. _G["WHUD_CD"..i]:SetAlpha(value)
  100. if _G["WHUD_CDBAR"..i.."_TIMER_START"] > 0 then
  101. local timeleft = math.floor(10*(_G["WHUD_CDBAR"..i.."_TIMER_START"]+WHUD_VARS.Cooldowns.fadetime-GetTime()))/10
  102. if timeleft > 0 then
  103. _G["WHUD_CDBAR"..i.."_TIMER"]:SetText(timeleft)
  104. else
  105. _G["WHUD_CDBAR"..i.."_TIMER"]:SetText("")
  106. end
  107. end
  108. if not _G["WHUD_CD"..i.."_CLOCK"] then
  109. _G["WHUD_CDBAR"..i.."_TIMER_START"] = GetTime()
  110. CooldownFrame_SetTimer(_G["WHUD_CDBAR"..i.."CLOCKMODEL"], GetTime(), WHUD_VARS.Cooldowns.fadetime, 1)
  111. _G["WHUD_CD"..i.."_CLOCK"] = true
  112. end
  113. end
  114. end
  115. if _G["WHUD_CD"..i.."_TIME"]+WHUD_VARS.Cooldowns.flashtime+0.5 <= GetTime() then
  116. WHUD_SPELLINFO[_G["WHUD_CD"..i.."_USED"]][2] = 0
  117. WHUD_SPELLINFO[_G["WHUD_CD"..i.."_USED"]][3] = 0
  118. _G["WHUD_CD"..i.."_USED"] = ""
  119. _G["WHUD_CD"..i.."_TIME"] = 0
  120. _G["WHUD_CDBAR"..i.."_TIMER"]:SetText("")
  121. _G["WHUD_CDBAR"..i.."_TIMER_START"] = 0
  122. _G["WHUD_CD"..i.."_CLOCK"] = false
  123. _G["WHUD_CD"..i]:SetTexture("")
  124. if WHUD_VARS.Cooldowns.fading then _G["WHUD_CD"..i.."_LAST"] = 0 else _G["WHUD_CD"..i.."_LAST"] = WHUD_VARS.Cooldowns.transparency end
  125. end
  126. end
  127. end
  128. -- UPDATING SPELL&RACIAL COOLDOWN INFO
  129. for impspells=1,(table.getn(WHUD_IMPORTANTSPELLS)+4) do
  130. local name = WHUD_IMPORTANTSPELLS[impspells]
  131. SetCooldown(name)
  132. if impspells > table.getn(WHUD_IMPORTANTSPELLS) then
  133. if (impspells - table.getn(WHUD_IMPORTANTSPELLS)) == 1 then
  134. name = "Overpower"
  135. elseif (impspells - table.getn(WHUD_IMPORTANTSPELLS)) == 2 then
  136. name = "Revenge"
  137. elseif (impspells - table.getn(WHUD_IMPORTANTSPELLS)) == 3 then
  138. name = "Shield Bash"
  139. elseif (impspells - table.getn(WHUD_IMPORTANTSPELLS)) == 4 then
  140. name = "Pummel"
  141. end
  142. end
  143. if WHUD_SPELLINFO[name][2] > 0 and WHUD_SPELLINFO[name][3] <= GetTime() then
  144. -- DISPLAYING THE SPELL&RACIAL COOLDOWNS HERE
  145. if not WHUD_VARS.Cooldowns.racials then
  146. for i=1,table.getn(WHUD_RACIALS) do
  147. if WHUD_RACIALS[i] == name then return end
  148. end
  149. end
  150. for i=1,6 do
  151. if _G["WHUD_CD"..i.."_USED"] == name then -- checking if the spell is already being displayed
  152. return
  153. end
  154. end
  155. for i=1,6 do
  156. if _G["WHUD_CD"..i.."_USED"] == "" then
  157. _G["WHUD_CD"..i]:SetTexture(GetSpellTexture(WHUD_SPELLINFO[name][1],"BOOKTYPE_SPELL"))
  158. _G["WHUD_CD"..i.."_USED"] = name
  159. _G["WHUD_CD"..i.."_TIME"] = GetTime()
  160. if WHUD_VARS.Cooldowns.fading then _G["WHUD_CD"..i]:SetAlpha(0) else _G["WHUD_CD"..i]:SetAlpha(WHUD_VARS.Cooldowns.transparency) end
  161. return
  162. end
  163. end
  164. end
  165. end
  166. if WHUD_VARS.Cooldowns.trinkets then
  167. -- UPDATING TRINKET COOLDOWN INFO
  168. if GetInventoryItemCooldown("player",13) > 0 and WHUD_SPELLINFO["Trinket1"][3] == 0 then
  169. local tr1start, tr1dur = GetInventoryItemCooldown("player",13)
  170. local tr1end = tr1start + tr1dur
  171. if WHUD_VARS.Cooldowns.fading then tr1end = tr1end - WHUD_VARS.Cooldowns.fadetime end
  172. if tr1start > 0 and tr1dur > 0 then -- TRNKET 1 is on Cooldown
  173. WHUD_SPELLINFO["Trinket1"] = {0,tr1start,tr1end}
  174. end
  175. end
  176. if GetInventoryItemCooldown("player",14) > 0 and WHUD_SPELLINFO["Trinket2"][3] == 0 then
  177. local tr2start, tr2dur = GetInventoryItemCooldown("player",14)
  178. local tr2end = tr2start + tr2dur
  179. if WHUD_VARS.Cooldowns.fading then tr2end = tr2end - WHUD_VARS.Cooldowns.fadetime end
  180. if tr2start > 0 and tr2dur > 0 then -- TRINKET 2 is on Cooldown
  181. WHUD_SPELLINFO["Trinket2"] = {0,tr2start,tr2end}
  182. end
  183. end
  184. -- INIT TRINKET DATA TO CHECK
  185. for i=1,2 do
  186. local name,slot
  187. if i == 1 then
  188. name = "Trinket1"
  189. slot = 13
  190. else
  191. name = "Trinket2"
  192. slot = 14
  193. end
  194. if WHUD_SPELLINFO[name][2] > 0 and WHUD_SPELLINFO[name][3] <= GetTime() then
  195. -- DISPLAYING TRINKET COOLDOWNS HERE
  196. for y=1,6 do
  197. if _G["WHUD_CD"..y.."_USED"] == name then
  198. return
  199. end
  200. end
  201. for x=1,6 do
  202. if _G["WHUD_CD"..x.."_USED"] == "" then
  203. _G["WHUD_CD"..x]:SetTexture(GetInventoryItemTexture("player",slot))
  204. _G["WHUD_CD"..x.."_USED"] = name
  205. _G["WHUD_CD"..x.."_TIME"] = GetTime()
  206. if WHUD_VARS.Cooldowns.fading then _G["WHUD_CD"..x]:SetAlpha(0) else _G["WHUD_CD"..x]:SetAlpha(WHUD_VARS.Cooldowns.transparency) end
  207. break
  208. end
  209. end
  210. end
  211. end
  212. end
  213. end
  214. end
  215. end
  216.  
  217. function WHUD_Cooldowns_OnEvent(arg1)
  218. if (GetUnitName("target")) then
  219. if string.find(arg1,"Your Overpower") then
  220. SetCooldown("Overpower")
  221. elseif string.find(arg1,"Your Revenge") then
  222. SetCooldown("Revenge")
  223. elseif string.find(arg1,"Your Shield Bash") then
  224. SetCooldown("Shield Bash")
  225. elseif string.find(arg1,"Your Pummel") then
  226. SetCooldown("Pummel")
  227. end
  228. end
  229. end
  230.  
  231. function WHUD_Cooldowns_EditMode(t)
  232. if t == 0 then
  233. for i=1,6 do
  234. _G["WHUD_CD"..i]:SetTexture("")
  235. _G["WHUD_CD"..i.."_USED"] = ""
  236. _G["WHUD_CD"..i.."_TIME"] = 0
  237. _G["WHUD_CDBAR"..i.."_TIMER"]:SetText("")
  238. _G["WHUD_CDBAR"..i.."_TIMER_START"] = 0
  239. _G["WHUD_CD"..i.."_CLOCK"] = false
  240. if WHUD_VARS.Cooldowns.fading then _G["WHUD_CD"..i]:SetAlpha(0) else _G["WHUD_CD"..i]:SetAlpha(WHUD_VARS.Cooldowns.transparency) end
  241. end
  242. editmode = false
  243. else
  244. editmode = true
  245. for i=1,6 do
  246. _G["WHUD_CD"..i]:SetTexture("Interface\\Icons\\Ability_MeleeDamage")
  247. _G["WHUD_CD"..i.."_USED"] = "Overpower"
  248. end
  249. end
  250. end
  251.  
  252. function WHUD_Cooldowns_VarUpdate()
  253. if WHUD_VARS.Cooldowns.enabled then
  254. WHUD_RegisterEvent("CHAT_MSG_COMBAT_SELF_MISSES")
  255. WHUD_RegisterEvent("CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF")
  256. WHUD_RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE")
  257. WHUD_CDBAR:Show()
  258. WHUD_CDBAR:SetFrameStrata(WHUD_VARS.Cooldowns.strata)
  259. WHUD_CDBAR:SetScale(WHUD_VARS.Cooldowns.scale)
  260. WHUD_CDBAR:SetAlpha(WHUD_VARS.Cooldowns.transparency)
  261. WHUD_CDBAR:SetPoint("CENTER", "UIParent", WHUD_VARS.Cooldowns.X ,WHUD_VARS.Cooldowns.Y)
  262. else
  263. WHUD_CDBAR:Hide()
  264. end
  265. end
  266.  
  267. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement