View Single Post
06-23-09, 08:47 AM   #25
Ambrya
Premium Member
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 49
Originally Posted by Coren View Post
You could store the current time of your warning and suppress following ones in a time frame:

Okay, I tend to start making code look messy when I try to patchwork stuff in, but I've added this in, hopefully without screwing up the indentations to keep everything tidy, etc too much and will take it for a test run later.

You could register "QUEST_LOG_UPDATE" and set me.Time to time() + 20 at that event. Then the first 20s after the quest start nothing would be output.
I added the registration for the "QUEST_LOG_UPDATE event, but I'm not sure how to do the rest, or at least not sure at which point in the script to do it. I'll probably drop that down to 10 seconds as well, since it seems like with the quest I'm using as a test case on my friend's toon, the first event requiring an action occurs fairly soon after the quest begins sometimes.

Here's what I have...did I butcher it too badly?

Code:
local me = CreateFrame("Frame", "stupidframe")

me:RegisterEvent("CHAT_MSG_MONSTER_EMOTE")
me:RegisterEvent("CHAT_MSG_MONSTER_SAY")
me:RegisterEvent("CHAT_MSG_MONSTER_WHISPER")
me:RegisterEvent("QUEST_LOG_UPDATE")
--add any others...that's probably good enough

me.listOfNames = {
     {"Ringo", "Yo! The goblin has fainted, throw some water on him, quick!!"},
     {"Kerlonian Evershade", "Darn it!  That lazy druid has fallen asleep again, time to use the horn!!!"},
     {"Shay", "That dippy night elf girl is chasing butterflies again, better ring the bell and call her back."},
     {"A-Me 01", "The suicidal ape robot is charging off into the fray again, go defend her!"},
     --etc
}

function me.EventHandler(self, event, _, name)
      for i = 1, #self.listOfNames do
           if name:find(self.listOfNames[i][1]) then
               -- only one warning per 10 seconds
               if ((me.Time == nil) or (time() - me.Time > 10)) then
                    me.Time = time();
                    PlaySound("RaidWarning")
                    local msg = self.listOfNames[i][2] or "Heads Up!  Your quest NPC needs help!!!"
                    RaidNotice_AddMessage(RaidWarningFrame, msg, ChatTypeInfo["RAID_WARNING"])
                    return
               end
           end
      end
end

me:SetScript("OnEvent", me.EventHandler)
  Reply With Quote