View Single Post
04-01-17, 05:22 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Tim View Post
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 View Post
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:
  1. local Throttle=30;--    Message throttle in seconds
  2. local Delay=1;--    Message delay in seconds
  3. local Message="Grats!!!";
  4.  
  5. --  Define this here so we aren't recreating it every time we want to send the message
  6. local function SendMessage() SendChatMessage(Message,"GUILD"); end
  7. local LastTrigger,PlayerGUID=0,nil;--   Throttle control and Player ID
  8.  
  9. local Frame=CreateFrame("Frame");
  10. Frame:RegisterEvent("PLAYER_LOGIN");
  11. Frame:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT");
  12. Frame:SetScript("OnEvent",function(self,event,...)
  13.     local now=GetTime();--  Cache current time for later
  14.     if event=="PLAYER_LOGIN" then-- Store our GUID on login
  15.         PlayerGUID=UnitGUID("player");
  16.     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)
  17.         C_Timer.After(Delay,SendMessage);-- Send after delay
  18.         LastTrigger=now;--  Update throttle control
  19.     end
  20. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-01-17 at 05:56 AM.
  Reply With Quote