Originally Posted by Tim
Try to remember to give your frames unique names so it's easier to point out when further developing your addon. While naming the frame "frame" is alright with this small addon you should make it a habit to do the other.
|
The OP is actually creating a dynamic frame with no name.
frame is a local variable that the widget is being stored in. As the frame isn't set up to be rendered, it won't be visible to
/fstack, so naming it isn't going to provide any benefit anyway.
Originally Posted by Kanegasi
This isn't perfect, there could be times where an event happens immediately after the message, causing any timers that were triggered earlier to push out a second message
|
This can be fixed using separate timers for the delay and reset. This also fixes self congratulating and addresses some possible performance issues with queuing up extraneous timers.
Lua Code:
local Throttle=30;-- Message throttle in seconds
local Delay=1;-- Message delay in seconds
local Message="Grats!!!";
-- Define this here so we aren't recreating it every time we want to send the message
local function SendMessage() SendChatMessage(Message,"GUILD"); end
local LastTrigger,PlayerGUID=0,nil;-- Throttle control and Player ID
local Frame=CreateFrame("Frame");
Frame:RegisterEvent("PLAYER_LOGIN");
Frame:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT");
Frame:SetScript("OnEvent",function(self,event,...)
local now=GetTime();-- Cache current time for later
if event=="PLAYER_LOGIN" then-- Store our GUID on login
PlayerGUID=UnitGUID("player");
elseif event=="CHAT_MSG_GUILD_ACHIEVEMENT" and now-LastTrigger>Throttle and select(12,...)~=PlayerGUID then-- Check throttle and compare sender (we don't want to congradulate ourselves)
C_Timer.After(Delay,SendMessage);-- Send after delay
LastTrigger=now;-- Update throttle control
end
end);