Thread Tools Display Modes
01-08-10, 03:31 AM   #1
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Checking buffs periodically

I'm making a simple little addon that will alert you when a fish feast is dropped with a sound, and then alert you every 15 seconds until you have the food buff. I've managed to get the sound to be played when the fish feast is first dropped, however I've spent the last 4 hours to no avail trying to get it to periodically check each 15 seconds for the buff, and if there is no buff to play the sound again.

Can anybody please help me out, it's getting rather frustrating, I've been looking at other addon codes and all over the web trying to find out how to do this.
  Reply With Quote
01-08-10, 04:39 AM   #2
contramundi
A Chromatic Dragonspawn
 
contramundi's Avatar
AddOn Compiler - Click to view compilations
Join Date: May 2008
Posts: 180
for buff checking, look at the source code from zomgbuffs or smartbuff or an addon that exists already to check buffs ^^
  Reply With Quote
01-08-10, 04:48 AM   #3
tattooedpierre
An Aku'mai Servant
 
tattooedpierre's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 38
Originally Posted by contramundi View Post
for buff checking, look at the source code from zomgbuffs or smartbuff or an addon that exists already to check buffs ^^
Two addons I did, HearMeClear and SurgeOfLight check buffs. Check the latter as, iirc, its the most up-to-date. Its only a few lines of code.
  Reply With Quote
01-08-10, 04:52 AM   #4
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by Toeler View Post
I'm making a simple little addon that will alert you when a fish feast is dropped with a sound, and then alert you every 15 seconds until you have the food buff. I've managed to get the sound to be played when the fish feast is first dropped, however I've spent the last 4 hours to no avail trying to get it to periodically check each 15 seconds for the buff, and if there is no buff to play the sound again.

Can anybody please help me out, it's getting rather frustrating, I've been looking at other addon codes and all over the web trying to find out how to do this.
Well, this is some simple untested code(make sure you edit the SOMETHING_HERE parts:
lua Code:
  1. local f = CreateFrame("Frame") -- Create the frame
  2. f:Hide() -- Make sure the OnUpdate function doesn't instantly start
  3. f:SetScript("OnUpdate", function(self, elapsed) -- Checks every 15 seconds for the buff, and if not active play the sound. If active hide the frame, stopping the OnUpdate script.
  4.     self.elapsed = self.elapsed + elapsed
  5.     if self.elapsed > 15 then
  6.         self.elapsed = 0
  7.         UnitBuff("Player", "THE_BUFF_YOUR_LOOKING_FOR_HERE") and self:Hide() or PlaySoundFile("SOME_SOUND_FILE_HERE")
  8.     end
  9. end)
  10. f:SetScript("OnShow", function(self)
  11.     self.elapsed = 0
  12. end)

Whenever fish feast is dropped, call f:Show(), whenever you want the script to stop reminding, call f:Hide().
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
01-08-10, 09:54 PM   #5
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by nightcracker View Post
Well, this is some simple untested code(make sure you edit the SOMETHING_HERE parts:

Whenever fish feast is dropped, call f:Show(), whenever you want the script to stop reminding, call f:Hide().
Another noob question, but do I have to add something to the xml for the OnUpdate part?

When I used your code as it is it would break the addon. The addon was loaded but the slash commands weren't working, and nothing in it was working. As soon as I took out the UnitBuff line (I did edit the buff name and sound file location) the addon worked again but without the periodic checking, I even put a line in to print a message where the UnitBuff line was and it didn't print out the message when it was supposed to.
  Reply With Quote
01-08-10, 10:13 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
His code will work without editing another file. As he notes:
Whenever fish feast is dropped, call f:Show(), whenever you want the script to stop reminding, call f:Hide()
f:Show will start the timer, using that code, and f:Hide will stop it. Note that whatever code calls those functions must be in the same file as his snippet, and below it. Also of course, don't use another variable called f.

I believe line 7 is a syntax error, because it's basically just writing "true" or "false" on a line (although maybe Lua allows that variation, I haven't tried it). Try turning Lua errors on (which you should do in general anyway, especially while writing an addon). While you certainly could write line 7 in that sort of way, I don't see any reason not to just do this:

lua Code:
  1. if UnitBuff("Player", "THE_BUFF_YOU'RE_LOOKING_FOR_HERE") then
  2.     self:Hide()
  3. else
  4.     PlaySoundFile("SOME_SOUND_FILE_HERE")
  5. end

Last edited by Akryn : 01-08-10 at 10:20 PM.
  Reply With Quote
01-08-10, 10:21 PM   #7
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by Akryn View Post
His code will work without editing another file. As he notes:


f:Show will start the timer, using that code, and f:Hide will stop it. Note that whatever code calls those functions must be in the same file as his snippet, and below it. Also of course, don't use another variable called f.

I believe line 7 is a syntax error, because it's basically just writing "true" or "false" on a line (although maybe Lua allows that variation, I haven't tried it). Try turning Lua errors on (which you should do in general anyway, especially while writing an addon). While you certainly could write line 7 in that sort of way, I don't see any reason not to just do this:

lua Code:
  1. if UnitBuff("Player", "THE_BUFF_YOU'RE_LOOKING_FOR_HERE") then
  2.     self:Hide()
  3. else
  4.     PlaySoundFile("SOME_SOUND_FILE_HERE")
  5. end
Yeah, I've got f:Show(); after the fish feast is detected in the lua. Completely forgot about turning lua errors on haha, will do that and see what it pops out.

-----

So I have it sorted now, missed the "and below it" haha. Thanks heaps Akryn and nightcracker!

Last edited by Toeler : 01-08-10 at 11:48 PM.
  Reply With Quote
01-10-10, 06:27 PM   #8
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Alright, so I've been working on my addon a little more, and was wondering how I would add another timer that doesn't get reset every 15 seconds, but can still be checked in the script that also checks the first timer (The first timer is check using self).

I just tried to replicate the first timer except using ff.elapsed instead of self.elapsed however I got an lua error saying error trying to compare a string and an integer. So how would I go about setting up a second timer that can still be checked in the same was self.elapsed is.
  Reply With Quote
01-10-10, 06:56 PM   #9
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
I'm not following what you want. Do you want a separate timer that executes code only once, or do you just want to be able to time how long it's been since something happened? If the latter then it's as easy as storing the value of time() in a variable and then later doing time() - theVariableYouUsed
  Reply With Quote
01-10-10, 07:57 PM   #10
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by Akryn View Post
I'm not following what you want. Do you want a separate timer that executes code only once, or do you just want to be able to time how long it's been since something happened? If the latter then it's as easy as storing the value of time() in a variable and then later doing time() - theVariableYouUsed
Hmm, I didn't consider saving the time to a variable, should be just what I need. Thanks again!

One last thing not related to this thread, but another problem I am having.

I'm trying to get a single variabled saved globally. I'm using http://www.wowwiki.com/Saving_variab..._game_sessions as my example, and have copied everything relating to what I need from it (everything minus the slash command, and anything relating to the HaveWeMetBool variable). However my variable is still not saving through sessions. The only thing I can think is that arg1 == "FishFeastAlert" isn't the right addon name, however that is only for setting it, if I set the variable it still isn't showing up in my SavedVariables folder, any ideas?

Last edited by Toeler : 01-10-10 at 07:59 PM.
  Reply With Quote
01-10-10, 08:02 PM   #11
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Can you post the relevant line from your .toc?
Also note that the variable must be global.

Edit: As far as finding your own addon's name, that gets passed to each file in the addon as ... as of WoW 3.3. So, at the top of your file you can do:

local myName, myNamespace = ...
and later
if arg1 == myName then

Last edited by Akryn : 01-10-10 at 08:06 PM.
  Reply With Quote
01-10-10, 08:11 PM   #12
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
FishFeastAlert.toc
Code:
## Interface: 30300
## Title: Fish Feast Alert
## Notes: Plays a sound when a fish feast is dropped. /ff for config
## Author: Toez
## Dependencies:
## SavedVariables: INTERVAL_TIME
## Version: 1.0.2

FishFeastAlert.lua
FishFeastAlert.xml
FishFeastAlert.lua
lua Code:
  1. local frame = CreateFrame("FRAME");
  2. frame:RegisterEvent("ADDON_LOADED");
  3.  
  4.  
  5.     function frame:OnEvent(event, arg1)
  6.         if event == "ADDON_LOADED" and arg1 == "FishFeastAlert" then
  7.             if INTERVAL_TIME == nil then
  8.                 INTERVAL_TIME = 20;
  9.             end
  10.         end
  11.     end
  12.    
  13.     frame:SetScript("OnEvent", frame.OnEvent);

Last edited by Toeler : 01-10-10 at 08:37 PM.
  Reply With Quote
01-10-10, 08:48 PM   #13
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
"Fish Feast Alert" ~= "FishFeastAlert"

Edit:
if I set the variable it still isn't showing up in my SavedVariables folder
Not sure there. The only other thing that looks weird to me is the fact that you have a "##Dependencies:" line with no actual dependencies listed. AFAIK that is fine to do, but maybe it no longer is? Have you tried without that line?

Last edited by Akryn : 01-10-10 at 08:51 PM.
  Reply With Quote
01-10-10, 09:02 PM   #14
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by Akryn View Post
"Fish Feast Alert" ~= "FishFeastAlert"

Edit:

Not sure there. The only other thing that looks weird to me is the fact that you have a "##Dependencies:" line with no actual dependencies listed. AFAIK that is fine to do, but maybe it no longer is? Have you tried without that line?
I'll take the line out and see what it does.

Originally Posted by Akryn View Post
"Fish Feast Alert" ~= "FishFeastAlert"
On the wowwiki article the Title is Have We Met? while arg1 == HaveWeMet
  Reply With Quote
01-10-10, 09:12 PM   #15
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Toeler View Post
On the wowwiki article the Title is Have We Met? while arg1 == HaveWeMet
I certainly could be wrong; I generally title my addons without spaces. However I would still assume that it needs to be exact. As I posted before though, you can just use ... to get the name.

What happens if you do a /run print(INTERVAL_TIME) in game?
  Reply With Quote
01-10-10, 09:18 PM   #16
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by Akryn View Post
I certainly could be wrong; I generally title my addons without spaces. However I would still assume that it needs to be exact. As I posted before though, you can just use ... to get the name.

What happens if you do a /run print(INTERVAL_TIME) in game?
I get nil, because it isn't being set by the function, and if I set it manually then print it then it works fine, however as soon as I relog it is back to nil.

Edit: Changing to myName it now sets the variable each time the addon loads. However I still have the problem of the veriable not saving each time I log out, so it just resets it back to the default.

Last edited by Toeler : 01-10-10 at 09:28 PM.
  Reply With Quote
01-10-10, 09:55 PM   #17
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Are there any other instances of INTERVAL_TIME in your lua file(s)?
  Reply With Quote
01-10-10, 10:00 PM   #18
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Originally Posted by Akryn View Post
Are there any other instances of INTERVAL_TIME in your lua file(s)?
lua Code:
  1. prt("Current interval is "..INTERVAL_TIME.." seconds."); -- Printing out the current integer
  2. INTERVAL_TIME = (argT[2]); -- Setting it using a slash command
  3. prt("You will now be notified every "..INTERVAL_TIME.." seconds to eat the fish feast."); -- Message after you set it
  4. if INTERVAL_TIME > 0 then
  5. if self.elapsed > INTERVAL_TIME then

That is all the other instances of INTERVAL_TIME in my lua file.

EDIT:

If you want I can upload my addon for you to have a look at it, I've gone over it multiple times and really can't see any reason for the variable to not be saving

Last edited by Toeler : 01-10-10 at 10:42 PM.
  Reply With Quote
01-11-10, 03:30 AM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Posting your whole code would probably help.

Originally Posted by Akryn View Post
"Fish Feast Alert" ~= "FishFeastAlert"
The string passed as an argument to the ADDON_LOADED event is the addon’s “internal name” — the name of the addon’s folder/TOC — so “FishFeastAlert” is correct. It doesn’t care about the Title field in your TOC, especially since that can differ according to the user’s locale. Consider that if MyAddon.toc includes this:

Code:
## Title: Cat
## Title-esES: Gato
## Title-ruRU: Кошка
Then:
Code:
GetAddOnMeta("Title", "MyAddon")
...will return “Кошка” in a Russian client, “Gato” in a Spanish client, and “Cat” in an English client (or any other client since it defaults to English when no localized field is provided).

It would be fairly confusing to deal with all of that if ADDON_LOADED worked off your addon’s TOC Title rather than your addon's internal name.
  Reply With Quote
01-11-10, 03:34 AM   #20
Toeler
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 29
Hmm, I think I've solved my problem some how. When I first asked about why my global variable wasn't saving my code was basically the same as it is now. As an attempt to fix it a little later I declared the global variable as a local at the top of the lua, when I removed it now it is now saving. I have no idea why it decided to suddenly work but at least it is now. Yay.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Checking buffs periodically


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