Advertisement
Guest User

add-on caride

a guest
Sep 1st, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. --[[
  2. KillingSpree authored by Douglas Craig (chexsum) <chexsum@gmail.com>
  3.  
  4. Announces consecutive killing blows.
  5.  
  6. ]]
  7. KillingSpree = LibStub("AceAddon-3.0"):NewAddon("KillingSpree", "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0", "LibSink-2.0")
  8. local self = KillingSpree
  9.  
  10. local MULTITIMER = 120 -- Seconds given to perform multi kills
  11. local SPREETIMER = 600 -- Seconds given to perform spree kills
  12.  
  13. local time = time
  14. local string_format = string.format
  15. local PlaySoundFile = PlaySoundFile
  16. local InterfaceOptionsFrame_OpenToCategory = InterfaceOptionsFrame_OpenToCategory
  17. local CombatLog_Object_IsA = CombatLog_Object_IsA
  18. local COMBATLOG_FILTER_ME = COMBATLOG_FILTER_ME
  19. local COMBATLOG_FILTER_MINE = COMBATLOG_FILTER_MINE
  20. local COMBATLOG_FILTER_MY_PET = COMBATLOG_FILTER_MY_PET
  21. local COMBATLOG_FILTER_HOSTILE_UNITS = COMBATLOG_FILTER_HOSTILE_UNITS
  22. local COMBATLOG_FILTER_HOSTILE_PLAYERS = COMBATLOG_FILTER_HOSTILE_PLAYERS
  23.  
  24. function KillingSpree:OnInitialize()
  25. self.scheme = {}
  26. self.schemes = { "UT2k3", "UT2k4Male", "UT2k4Male2", "UT2k4Female", "UT2k4Female2" }
  27. for scheme = 1, #self.schemes do
  28. self.scheme[self.schemes[scheme]] = {
  29. ['firstblood'] = { "firstblood.ogg", "First Blood!" },
  30. ['multi'] = {
  31. [2] = { "doublekill.ogg", "Double Kill!" },
  32. [3] = { "multikill.ogg", "Multi Kill!" },
  33. [4] = { "megakill.ogg", "Mega Kill!" },
  34. [5] = { "ultrakill.ogg", "Ultra Kill!" },
  35. [6] = { "monsterkill.ogg", "Monster Kill!" },
  36. },
  37. ['spree'] = {
  38. [10] = { "killingspree.ogg", "Killing Spree!" },
  39. [13] = { "rampage.ogg", "Rampage!" },
  40. [16] = { "dominating.ogg", "Dominating!" },
  41. [19] = { "unstoppable.ogg", "Unstoppable!" },
  42. [22] = { "godlike.ogg", "God-like!" },
  43. },
  44. }
  45. if self.schemes[scheme] ~= "UT2k3" then
  46. self.scheme[self.schemes[scheme]]['multi'][7] = { "ludicrouskill.ogg", "Ludicrous Kill!" }
  47. self.scheme[self.schemes[scheme]]['spree'][25] = { "wickedsick.ogg", "Wicked Sick!" }
  48. end
  49. end
  50. if UnitSex('player') == 3 then
  51. self.defaultscheme = "UT2k4Female"
  52. else
  53. self.defaultscheme = "UT2k4Male"
  54. end
  55. self.defaults = {
  56. profile = {
  57. pvp = true,
  58. pve = false,
  59. scheme = self.defaultscheme,
  60. },
  61. }
  62. self.db = LibStub("AceDB-3.0"):New("KillingSpreeDB", self.defaults, "Default")
  63. self.options = {
  64. type = 'group',
  65. name = "KillingSpree",
  66. desc = "Consecutive kill announcer",
  67. icon = "Interface\\AddOns\\KillingSpree\\icon",
  68. args = {
  69. pvp = {
  70. order = 1,
  71. type = 'toggle',
  72. name = "Show PVP",
  73. desc = "Show PVP kills",
  74. get = function(info)
  75. return self.db.profile.pvp
  76. end,
  77. set = function(info, value)
  78. self.db.profile.pvp = value
  79. self:UpdateVictims()
  80. end,
  81. },
  82. pve = {
  83. order = 2,
  84. type = 'toggle',
  85. name = "Show PVE",
  86. desc = "Show PVE kills",
  87. get = function(info)
  88. return self.db.profile.pve
  89. end,
  90. set = function(info, value)
  91. self.db.profile.pve = value
  92. self:UpdateVictims()
  93. end,
  94. },
  95. scheme = {
  96. order = 5,
  97. type = 'select',
  98. name = "Sound scheme",
  99. desc = "Selects the sound scheme",
  100. get = function(info)
  101. return self.db.profile.scheme
  102. end,
  103. set = function(info, value)
  104. self.db.profile.scheme = value
  105. end,
  106. values = {
  107. ["UT2k3"] = "UT2k3",
  108. ["UT2k4Male"] = "UT2k4Male",
  109. ["UT2k4Male2"] = "UT2k4Male2",
  110. ["UT2k4Female"] = "UT2k4Female",
  111. ["UT2k4Female2"] = "UT2k4Female2",
  112. },
  113. },
  114. },
  115. }
  116. self:SetSinkStorage(self.db.profile)
  117. self.options.args.output = self:GetSinkAce3OptionsDataTable()
  118. LibStub("AceConfig-3.0"):RegisterOptionsTable("KillingSpree", self.options, {"killingspree"})
  119. self.optionsDialog = LibStub("AceConfigDialog-3.0")
  120. self.optionsFrame = self.optionsDialog:AddToBlizOptions("KillingSpree", "KillingSpree")
  121. end
  122.  
  123. function KillingSpree:OnEnable()
  124. self:ResetVictims()
  125. self:RegisterEvent("PLAYER_DEAD", "ResetVictims")
  126. self:RegisterEvent("PLAYER_REGEN_ENABLED", "DeleteVictims")
  127. self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED", "CombatLogEvent")
  128. end
  129.  
  130. function KillingSpree:ResetVictims()
  131. self.victims = {}
  132. self.kills = 0
  133. self.multi = 0
  134. self.spree = 0
  135. self.bestspree = 0
  136. self.bestmulti = 0
  137. end
  138.  
  139. function KillingSpree:DeleteVictims()
  140. local multi, spree, time = 0, 0, time()
  141. for victim = 1, self.kills, 1 do
  142. if self.victims[victim] then
  143. local difference = time - self.victims[victim].tod
  144. if difference > SPREETIMER then
  145. self.victims[victim] = null
  146. self.kills = self.kills - 1
  147. else
  148. break
  149. end
  150. end
  151. end
  152. end
  153.  
  154. function KillingSpree:UpdateVictims()
  155. local multi, spree, time = 0, 0, time()
  156. for victim = self.kills, 1, -1 do
  157. if self.victims[victim] then
  158. local difference = time - self.victims[victim].tod
  159. if difference < MULTITIMER then
  160. multi = multi + 1
  161. elseif difference < SPREETIMER then
  162. spree = spree + 1
  163. else
  164. break
  165. end
  166. end
  167. end
  168. self.multi = multi
  169. self.spree = spree + multi
  170. end
  171.  
  172. function KillingSpree:Announce()
  173. if self.spree > 1 and self.scheme[self.db.profile.scheme]['spree'][self.spree] and self.spree > self.bestspree then
  174. PlaySoundFile(string_format("Interface\\AddOns\\KillingSpree\\Snds\\%s\\%s", self.db.profile.scheme, self.scheme[self.db.profile.scheme]['spree'][self.spree][1]))
  175. self:Pour(string_format("%s", self.scheme[self.db.profile.scheme]['spree'][self.spree][2]), 1, 0, 0)
  176. self.bestspree = self.spree
  177. elseif self.spree > 1 and self.scheme[self.db.profile.scheme]['multi'][self.multi] and self.multi > self.bestmulti then
  178. PlaySoundFile(string_format("Interface\\AddOns\\KillingSpree\\Snds\\%s\\%s", self.db.profile.scheme, self.scheme[self.db.profile.scheme]['multi'][self.multi][1]))
  179. self:Pour(string_format("%s", self.scheme[self.db.profile.scheme]['multi'][self.multi][2]), 1, 0, 0)
  180. self.bestmulti = self.multi
  181. elseif self.spree == 1 and self.scheme[self.db.profile.scheme]['firstblood'] then
  182. PlaySoundFile(string_format("Interface\\AddOns\\KillingSpree\\Snds\\%s\\%s", self.db.profile.scheme, self.scheme[self.db.profile.scheme]['firstblood'][1]))
  183. self:Pour(string_format("%s", self.scheme[self.db.profile.scheme]['firstblood'][2]), 1, 0, 0)
  184. end
  185. end
  186.  
  187. function KillingSpree:CombatLogEvent(event, timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destinationGUID, destinationName, destinationFlags, destinationRaidFlags, ...)
  188. if eventType and eventType == "PARTY_KILL" then
  189. if sourceFlags and (CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_ME) or CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MINE) or CombatLog_Object_IsA(sourceFlags, COMBATLOG_FILTER_MY_PET)) then
  190. if (self.db.profile.pvp and CombatLog_Object_IsA(destinationFlags, COMBATLOG_FILTER_HOSTILE_PLAYERS)) or (self.db.profile.pve and CombatLog_Object_IsA(destinationFlags, COMBATLOG_FILTER_HOSTILE_UNITS)) then
  191. self.kills = self.kills + 1
  192. self.victims[self.kills] = {}
  193. self.victims[self.kills].tod = time()
  194. self.victims[self.kills].name = destinationName
  195. self:UpdateVictims()
  196. self:Announce()
  197. end
  198. end
  199. end
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement