View Single Post
09-23-14, 08:28 AM   #1
liquidbase
A Warpwood Thunder Caller
 
liquidbase's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 97
Issue with Cooldownannounce-Script

Hey @all!

I use for DuffedUI v8 the following script to announce cooldowns like Icebound Fortitude, Shield Wall and so on.

Announcescript:
Lua Code:
  1. local D, C, L = unpack(select(2, ...))
  2. if C["duffed"].spellannounce ~= true then return end
  3.  
  4. D.Spells = {
  5.     -- Death Knight
  6.     [48792] = true, -- Icebound Fortitude
  7.     [48707] = true, -- Anti-Magic-Shell
  8.     [55233] = true, -- Vampric Blood
  9.     [61999] = true, -- Raise Ally
  10.     [113072] = true, -- Symbiosis (Might of Ursoc)
  11.  
  12.     -- Druid
  13.     [61336] = true, -- Survival Insticts
  14.     [106922] = true, -- Might of Ursoc
  15.  
  16.     -- Monk
  17.     [115203] = true, -- Fortifying Brew
  18.     [115213] = true, -- Avert Harm
  19.     [113306] = true, -- Symbiosis (Survival Insticts)
  20.  
  21.     -- Paladin
  22.     [498] = true, -- Divine Protection
  23.     [642] = true, -- Divine Shield
  24.     [31850] = true, -- Ardent Defender
  25.     [113075] = true, -- Symbiosis (Barkskin)
  26.    
  27.     -- Priest
  28.     [33206] = true, -- Pain Supression
  29.     [47788] = true, -- Guardian Spirit
  30.     [62618] = true, -- PW: Barrier
  31.     [109964] = true, -- Spirit Shell
  32.  
  33.     -- Shaman
  34.     [16190] = true, -- Mana Tide Totem
  35.     [98008] = true, -- Spirit Link Totem
  36.     [108280] = true, -- Healing Tide Totem
  37.     [120668] = true, -- Stormlash Totem
  38.  
  39.     -- Warlock
  40.     [20707] = true, -- Soulstone
  41.  
  42.     -- Warrior
  43.     [871] = true, -- Shield Wall
  44.     [12975] = true, -- Last Stand
  45.     [97462] = true, -- Rallying Cry
  46.     [114192] = true, -- Mocking Banner
  47.     [114203] = true, -- Demoralizing Banner
  48.     [114207] = true, -- Skull Banner
  49.     [122286] = true, -- Symbiosis (Savage Defense)
  50. }
  51.  
  52. local Name = UnitName("player")
  53. local GUID = UnitGUID("player")
  54. local select = select
  55. local SendChatMessage = SendChatMessage
  56. local WaitTable = {}
  57.  
  58. local AnnounceFrame = CreateFrame("Frame")
  59. AnnounceFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  60. AnnounceFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  61.  
  62. local OnEvent = function(self, event, ...)
  63.     local Time, Type, HideCaster, SourceGUID, SourceName, SourceFlags, SourceRaidFlags, DestGUID, DestName, DestFlags, DestRaidFlags, SpellID, SpellName = ...
  64.  
  65.     if (SourceGUID ~= GUID) then return end
  66.  
  67.     if (D.Spells[SpellID] and Type == "SPELL_CAST_SUCCESS") then
  68.         if (not DestName) then DestName = SourceName end
  69.  
  70.         local Duration = select(6, UnitAura(DestName, SpellName)) or 10
  71.         local SpellString = "\124cff71d5ff\124Hspell:" .. SpellID .. "\124h[" .. SpellName .. "]\124h\124r"
  72.         local AnnounceTo = C["duffed"].announcechannel
  73.  
  74.         if (DestName ~= Name) then
  75.             if (Duration == nil) then
  76.                 SendChatMessage("++ ".. SpellString .. " on " .. DestName .. "!", AnnounceTo)
  77.             else
  78.                 SendChatMessage("++ ".. SpellString .. " on " .. DestName .. " for " .. Duration .. " s", AnnounceTo)
  79.             end
  80.         else
  81.             SendChatMessage("++ ".. SpellString .. " for " .. Duration .. " s", AnnounceTo)
  82.         end
  83.         D.Delay(Duration, SendChatMessage, "-- ".. SpellString, AnnounceTo)
  84.     end
  85. end
  86.  
  87. AnnounceFrame:SetScript("OnEvent", OnEvent)

Delayfunction:
Lua Code:
  1. local waitTable = {}
  2. local waitFrame
  3. D.Delay = function(delay, func, ...)
  4.     if(type(delay) ~= "number" or type(func) ~= "function") then
  5.         return false
  6.     end
  7.     if(waitFrame == nil) then
  8.         waitFrame = CreateFrame("Frame","WaitFrame", UIParent)
  9.         waitFrame:SetScript("onUpdate",function (self, elapse)
  10.             local count = #waitTable
  11.             local i = 1
  12.             while(i <= count) do
  13.                 local waitRecord = tremove(waitTable, i)
  14.                 local d = tremove(waitRecord, 1)
  15.                 local f = tremove(waitRecord, 1)
  16.                 local p = tremove(waitRecord, 1)
  17.                 if(d>elapse) then
  18.                   tinsert(waitTable, i, {d - elapse, f, p})
  19.                   i = i + 1
  20.                 else
  21.                   count = count - 1
  22.                   f(unpack(p))
  23.                 end
  24.             end
  25.         end)
  26.     end
  27.     tinsert(waitTable, {delay,func,{...}})
  28.     return true
  29. end

The problem is that when I log in and use a skill that is in the table, nothing happens. Do I have a reload of the entire interface made​​, the script works and I get the desired output, such as
Merith: ++ [Anti-Magic Shell] for 5 s
on start at at the ending
Merith: -- [Anti-Magic Shell]
My impression is that I've forgotten something, what the correct function of the script prevented if you login with a character. Even if I add the event PLAYER_LOGIN, it does not fix the problem.

Currently, I honestly do not and how I could fix the problem.Thank you once for all proposals or suggestions to the problem.

greetz
liquid