Thread Tools Display Modes
03-30-17, 08:20 PM   #1
JTyld
A Defias Bandit
Join Date: Mar 2017
Posts: 2
Simple addon help, sending guild message on event

I am trying to make an addon that does a simple checking for achievement in guild and then spits out a chat message.

So far this is what I have come up with:

Code:
local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT")
frame:SetScript("OnEvent",
   function(self, event)
      SendChatMessage("oh wow grats","GUILD")
end)
Not sure what I am missing here, but this isn't working for me. Also I am trying to come up with a way to make it only do this every X seconds (so it doesnt spam after 20 people get an achievement for example). Any suggestions? Appreciate any help.
  Reply With Quote
03-30-17, 08:33 PM   #2
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
It looks fine to me, did you also try turning it into an addon with http://addon.bool.no/

Last edited by Ketho : 03-30-17 at 09:55 PM.
  Reply With Quote
03-31-17, 02:33 PM   #3
JTyld
A Defias Bandit
Join Date: Mar 2017
Posts: 2
Originally Posted by Ketho View Post
It looks fine to me, did you also try turning it into an addon with http://addon.bool.no/
That worked! Thank you! I must have jacked up something with the TOC file. Now I am just trying to figure out a timing mechanism.
  Reply With Quote
03-31-17, 03:21 PM   #4
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 308
Here's the lovely C_Timer functions..

http://wow.gamepedia.com/API_C_Timer.After
http://wow.gamepedia.com/API_C_Timer.NewTimer
http://wow.gamepedia.com/API_C_Timer.NewTicker


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.

Code:
local AchieveHandler = CreateFrame("Frame")
AchieveHandler:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT")
AchieveHandler:SetScript("OnEvent", function(self, event)

   C_Timer.After(10, function()
      SendChatMessage("oh wow grats", "GUILD")
   end)

end)
Change 10 to whatever delay you want.
  Reply With Quote
03-31-17, 04:47 PM   #5
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Those timers won't work that way. If 20 people get an achievement, 20 messages will still go out but 10 seconds later.

Try this:

Code:
local autograts=CreateFrame('frame')
autograts:RegisterEvent('CHAT_MSG_GUILD_ACHIEVEMENT')
autograts:SetScript('OnEvent',function()
    autograts.trigger=true
    C_Timer.After(5,function()
        if autograts.trigger then
            autograts.trigger=false
            SendChatMessage('oh wow grats','GUILD')
        end
    end)
end)
This code will wait 5 seconds after the first event, then send only one message for any events that happened in that 5 seconds. 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, but this way, you don't spam guild chat with 20 instant messages.

Last edited by Kanegasi : 03-31-17 at 04:50 PM.
  Reply With Quote
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,313
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

WoWInterface » Developer Discussions » General Authoring Discussion » Simple addon help, sending guild message on event

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