Thread Tools Display Modes
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
 
09-23-14, 08:44 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Just a quick guess: does using PLAYER_LOGIN instead of PLAYER_ENTERING_WORLD fix your problem?

Don't ask me on details (can't remember exactly ), but the events on reloading the UI are not 100% the same as on login.

[e]
Doh. Nevermind. I'm just realizing that you're registering PLAYER_ENTERING_WORLD but don't actually use it.

Last edited by Duugu : 09-23-14 at 08:48 AM.
 
09-23-14, 08:54 AM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I would say this is about
Lua Code:
  1. if C["duffed"].spellannounce ~= true then return end

C["duffed"].spellannounce is there on reload but not on login.

Move this into the OnEvent function and trigger it on PLAYER_ENTERING_WORLD:

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. }

Do the same with this part:

Lua Code:
  1. D.Delay = function(delay, func, ...)
  2.     if(type(delay) ~= "number" or type(func) ~= "function") then
  3.         return false
  4.     end
  5.     if(waitFrame == nil) then
  6.         waitFrame = CreateFrame("Frame","WaitFrame", UIParent)
  7.         waitFrame:SetScript("onUpdate",function (self, elapse)
  8.             local count = #waitTable
  9.             local i = 1
  10.             while(i <= count) do
  11.                 local waitRecord = tremove(waitTable, i)
  12.                 local d = tremove(waitRecord, 1)
  13.                 local f = tremove(waitRecord, 1)
  14.                 local p = tremove(waitRecord, 1)
  15.                 if(d>elapse) then
  16.                   tinsert(waitTable, i, {d - elapse, f, p})
  17.                   i = i + 1
  18.                 else
  19.                   count = count - 1
  20.                   f(unpack(p))
  21.                 end
  22.             end
  23.         end)
  24.     end
  25.     tinsert(waitTable, {delay,func,{...}})
  26.     return true
  27. end
 
09-23-14, 09:06 AM   #4
liquidbase
A Warpwood Thunder Caller
 
liquidbase's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 97
D.Delay is a global function for the entire UI so I in which the option can not connect with. I use it for different elements. And when I put the query together with Spell-Table in the OnEvent function, I got the same result.

After logging => no function
After the reload => Works
 
09-23-14, 09:44 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Lua Code:
  1. local GUID = UnitGUID("player")
is nil as you can't query the GUID if the addon loads?
I don't know why it does work after reloading the UI (would say it shouldn't ) ... but this could be a hint to your problem.

Last edited by Duugu : 09-23-14 at 09:48 AM.
 
09-23-14, 09:53 AM   #6
liquidbase
A Warpwood Thunder Caller
 
liquidbase's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 97
After moving these two values into the OnEvent-function it works. I had replace GUID and Name in the function with UnitGUID("player") and UnitName("player") and it works. Code looks now posted below and ist works.

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 select = select
  53. local SendChatMessage = SendChatMessage
  54. local UnitAura = UnitAura
  55. local WaitTable = {}
  56.  
  57. local OnEvent = function(self, event, ...)
  58.     local Time, Type, HideCaster, SourceGUID, SourceName, SourceFlags, SourceRaidFlags, DestGUID, DestName, DestFlags, DestRaidFlags, SpellID, SpellName = ...
  59.  
  60.     if (SourceGUID ~= UnitGUID("player")) then return end
  61.  
  62.     if (D.Spells[SpellID] and Type == "SPELL_CAST_SUCCESS") then
  63.         if (not DestName) then DestName = SourceName end
  64.  
  65.         local Duration = select(6, UnitAura(DestName, SpellName)) or 10
  66.         local SpellString = "\124cff71d5ff\124Hspell:" .. SpellID .. "\124h[" .. SpellName .. "]\124h\124r"
  67.         local AnnounceTo = C["duffed"].announcechannel
  68.  
  69.         if (DestName ~= UnitName("player")) then
  70.             if (Duration == nil) then
  71.                 SendChatMessage("++ ".. SpellString .. " on " .. DestName .. "!", AnnounceTo)
  72.             else
  73.                 SendChatMessage("++ ".. SpellString .. " on " .. DestName .. " for " .. Duration .. " s", AnnounceTo)
  74.             end
  75.         else
  76.             SendChatMessage("++ ".. SpellString .. " for " .. Duration .. " s", AnnounceTo)
  77.         end
  78.         D.Delay(Duration, SendChatMessage, "-- ".. SpellString, AnnounceTo)
  79.     end
  80. end
  81.  
  82. local AnnounceFrame = CreateFrame("Frame")
  83. AnnounceFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  84. AnnounceFrame:SetScript("OnEvent", OnEvent)

Thanks Duugu, you have point me in the correct direction with your help
 
09-23-14, 09:56 AM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Yeah, name and/or GUID not being available seems probable. Much data gets downloaded as you login and might not need to be downloaded again when you reload the UI.

Another way to check if the unit is the player is this:
Code:
CombatLog_Object_IsA(flags, COMBATLOG_FILTER_ME)
(don't know if that's anything other than a bit.band?)
__________________
Grab your sword and fight the Horde!

Last edited by Lombra : 09-23-14 at 10:05 AM.
 
09-23-14, 10:05 AM   #8
liquidbase
A Warpwood Thunder Caller
 
liquidbase's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 97
Yes I've noticed with the script and after that is now fixed now it's really good to me. Was the very last thing that has annoyed me personally, before the actual release ^^
 
09-23-14, 05:52 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
UnitName will return a valid value for the player unit immediately. However, UnitGUID won't return anything useful until PLAYER_LOGIN. Rather than calling these functions repeatedly in a combat log handler (which runs extremely frequently, and therefore adding 2 function calls there is extremely inefficient) you should register for PLAYER_LOGIN and initialize the variables there.

Also, I don't understand why you're checking the destination name instead of the destination GUID? Just check the GUID like you're doing with the source...

Code:
-- at the top:
local PlayerGUID

-- at the bottom:
local AnnounceFrame = CreateFrame("Frame")
AnnounceFrame:RegisterEvent("PLAYER_LOGIN")
AnnounceFrame:SetScript("OnEvent", function(self, event)
    PlayerGUID = UnitGUID("player")
    self:UnregisterEvent("PLAYER_LOGIN")
    self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    self:SetScript("OnEvent", OnEvent)
end)
The basic idea is that:

1. You only register for PLAYER_LOGIN at first.
2. When it fires, store the player's GUID, register for CLEU, and replace the OnEvent handler with the CLEU handler.
3. In the CLEU handler, refer to the stored GUID instead of looking up the same value over and over millions of times per play session.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
 
 

WoWInterface » Site Forums » Archived Beta Forums » WoD Beta archived threads » Issue with Cooldownannounce-Script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off