Thread Tools Display Modes
10-11-12, 06:58 PM   #1
Steeveholt
A Murloc Raider
Join Date: Oct 2012
Posts: 4
Detecting buffs/debuffs: Is this still possible from an addon?

Hello!

I've never written anything in Lua before so obviously nothing for WoW but I have a pretty solid background in C (I study mathematics but I do a lot of programming for simulations) so I thought I'd give writing my own "addon" a shot. Basically what I want to do is lay the groundwork for a system to detect events and react depending on what it is. The basic idea would be something like this:

[Action] happens to [Something] with [Some Parameters] then do [Something]

An obvious one would be to detect if Player gets a debuff, check which one it is, and if it's breakable with Hand of Freedom, alert the player.

Obviously there's a way to detect buffs and debuffs (a lot of addons do it) but is there a event-way to handle them? I'm probably phrasing this really badly, but I feel like Blizzard might've added some kind of restriction to stop people from automating the game process too much.

Looking through WoWWiki I found some basic documentation for the UnitAura API which lets me grab my buffs. There is also the UNIT_AURA event which returns a UnitAura ID. I'm assuming this would work? Listening for a UNIT_AURA even, grab the UnitAura ID, check what it is and react accordingly?

First time doing this so any tip welcomed. Just wondering if this was a good way to go.

Thanks!
  Reply With Quote
10-11-12, 07:05 PM   #2
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
You can be alerted, but it can't do anything automatically for you, and it's limited to not being able to automatically rebind a specific button to change what that button does while being in combat, based on data like auras.
__________________
Profile: Curse | Wowhead
  Reply With Quote
10-11-12, 07:15 PM   #3
Monolit
A Black Drake
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 81
Add-ons can alert you based on aura gain/loss , however they can not perform actions for you.

Using your own example:

Add-on will be able to check what debuff player gets; you can make a list of such debuffs that are breakable with freedom and the add-on will check if the debuff you got is on that list; and finally it can warn you in any shape or form... e.g. screen turning red, shaking, flying ponies, dancing strippers etc..
  Reply With Quote
10-11-12, 07:17 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
In addition to what the above posters said, I point you to this thread of resources for your beginning adventure in coding addons.

http://www.wowinterface.com/forums/s...ad.php?t=43699
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-11-12, 09:50 PM   #5
Steeveholt
A Murloc Raider
Join Date: Oct 2012
Posts: 4
Thanks for the replies everybody. I got some of it to work using pure Lua (not sure I want to get into the xml just yet and I really don't need an interface). Thanks for the links!
  Reply With Quote
10-11-12, 09:59 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Even if you do decide to add an interface, you do not need to use XML. There is only one reason to use XML in WoW, and that is to create secure templates for inheritance; everything else can be done in pure Lua.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-11-12, 10:32 PM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Also, I suggest using WowPedia over WoWWiki as it's more up-to-date: the admins and most editors left WoWWiki in 2010 to form WoWPedia.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
10-12-12, 09:37 AM   #8
Jarod24
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 66
Welcome to the fold Steve.
I myself use wowprogramming.com, WoWWiki, WoWInterface, Curseforge and of corse google.

Yes there are limitations of what you can do in the game. For example events can not make the player automatically cast spells etc. These can only be done by actions initiated by the player (keyboard or mouseclick).


If you are simply interested in finding someting that is already created then you should look at my addon called IfThen: http://www.wowinterface.com/download...11-IfThen.html
It has a IDE and fully documented API to write simple IF-statements to react to events ingame, just like you mentioned in your example.

A quick example of the addon's syntax.
Code:
OnEvent("Buff") AND HasBuff("Heroism") OR HasBuff("Time Warp") THEN Print("!!!==Heroism || Time Warp==!!!");
__________________
Author of IfThen, Links in Chat

Last edited by Jarod24 : 10-12-12 at 09:53 AM. Reason: typoos
  Reply With Quote
10-12-12, 10:25 AM   #9
Coote
A Scalebane Royal Guard
 
Coote's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 440
Welcome to our nightmare, Steve. I think you're gonna like it. I think you're gonna feel you belong.

Most of what I could say has been said (WoWPedia > WoWWikki, check out WoWProgramming), but I'd also recommend popping into IRC if you need questions answered. Even with a solid background in other languages, I recommend to start with something small, if only to get accustomed to Lua, and WoW's API.
__________________

"This is the fifteen-thousandth four hundredth and ninety-eighth occurence".

Last edited by Coote : 10-12-12 at 10:27 AM.
  Reply With Quote
10-12-12, 02:59 PM   #10
Steeveholt
A Murloc Raider
Join Date: Oct 2012
Posts: 4
Originally Posted by Phanx View Post
Even if you do decide to add an interface, you do not need to use XML. There is only one reason to use XML in WoW, and that is to create secure templates for inheritance; everything else can be done in pure Lua.
That's good to know, thanks! And I feel like as someone who has been healing using Grid exclusively since very early in its release I, and everybody I ever kept alive during a raid or a bg, owe you a big thank you!

Originally Posted by Torhal View Post
Also, I suggest using WowPedia over WoWWiki as it's more up-to-date: the admins and most editors left WoWWiki in 2010 to form WoWPedia.
Will do! Thanks.

Originally Posted by Jarod24 View Post
Welcome to the fold Steve.
I myself use wowprogramming.com, WoWWiki, WoWInterface, Curseforge and of corse google.

Yes there are limitations of what you can do in the game. For example events can not make the player automatically cast spells etc. These can only be done by actions initiated by the player (keyboard or mouseclick).


If you are simply interested in finding someting that is already created then you should look at my addon called IfThen: http://www.wowinterface.com/download...11-IfThen.html
It has a IDE and fully documented API to write simple IF-statements to react to events ingame, just like you mentioned in your example.

A quick example of the addon's syntax.
Code:
OnEvent("Buff") AND HasBuff("Heroism") OR HasBuff("Time Warp") THEN Print("!!!==Heroism || Time Warp==!!!");
That is pretty much exactly what I wanted to do. Basically something like this:

Code:
OnEvent("DeBuff") AND DebuffTarget("focus") AND HasDebuff("Chains of Ice") THEN Print("Someone needs a Freedom!")
Similarly, it'd be good to be able to use it to track incoming spells:

Code:
OnEVent("SpellCast") AND SpellTarget("player") and SpellIs("Polymorph") THEN Print("You should probably cast Hand of Sacrifice right about now")
I'll look into your addon! Thanks!

Originally Posted by Coote View Post
Welcome to our nightmare, Steve. I think you're gonna like it. I think you're gonna feel you belong.

Most of what I could say has been said (WoWPedia > WoWWikki, check out WoWProgramming), but I'd also recommend popping into IRC if you need questions answered. Even with a solid background in other languages, I recommend to start with something small, if only to get accustomed to Lua, and WoW's API.
Glad to see the IRC channel is on Freenode. Every time I want to check out some community's IRC channel and it's on another network I never use I end up never going back. I'll add it to my auto-join list!
  Reply With Quote
01-13-13, 01:09 AM   #11
Sieben11
A Deviate Faerie Dragon
Join Date: Jan 2009
Posts: 10
Originally Posted by Steeveholt View Post
Hello!

I've never written anything in Lua before so obviously nothing for WoW but I have a pretty solid background in C (I study mathematics but I do a lot of programming for simulations) so I thought I'd give writing my own "addon" a shot. Basically what I want to do is lay the groundwork for a system to detect events and react depending on what it is. The basic idea would be something like this:

[Action] happens to [Something] with [Some Parameters] then do [Something]

An obvious one would be to detect if Player gets a debuff, check which one it is, and if it's breakable with Hand of Freedom, alert the player.

Obviously there's a way to detect buffs and debuffs (a lot of addons do it) but is there a event-way to handle them? I'm probably phrasing this really badly, but I feel like Blizzard might've added some kind of restriction to stop people from automating the game process too much.

Looking through WoWWiki I found some basic documentation for the UnitAura API which lets me grab my buffs. There is also the UNIT_AURA event which returns a UnitAura ID. I'm assuming this would work? Listening for a UNIT_AURA even, grab the UnitAura ID, check what it is and react accordingly?

First time doing this so any tip welcomed. Just wondering if this was a good way to go.

Thanks!
This may not be exactly what you need. However may give some ideas.

Code:
local Druid_Data = {

    ["Bear Form"] = {
        id = 5487,
        text = "turns into a massive blood thirsty bear."
    },

    ["Aquatic Form"] = {
        id = 1066,
        text = "does " .. Sex1 .. " best to find " .. Sex1 .. " sea legs."
    },

    ["Cat Form"] = {
        id = 768,
        text = "turns into a loveable kitty."
    },

}
Then I took the online samples and worked them to what I'd like. A few varied print functions just to play with things really. It scans through player buffs and if it expires or not. Druid forms do not expire unless canceled. Then collects the information for that seen form from the table. For this one it just simply references what text to return for the seen form in an emote fashion. Not the greatest scripter, so if I made errors or have something to add. Please do. In any case maybe it might give you some thoughts or ideas.

Code:
for i=1,40 do -- collect active buffs
    local buff,_,ico,_,_,dur,ex,_,_,_,id = UnitBuff("player", i, "HELPFUL")
        if buff  then buffs[i] = buff
           --if ex == 0 then Print(buff..": ID: "..Druid_Data[buff].id.." TEXT: "..Druid_Data[buff].text)end
           if ex == 0 and self.form ~= buff then -- check for form & not same form as before
               self.form = buff -- store form
               if InCombatLockDown() and not lock_combat then RunScript(SendChatMessage(Druid_Data[buff].text, "EMOTE", "Common", DEFAULT_CHAT_FRAME))
           end
           --//Print(i.."="..buff..", "..id..", "..ico..", "..dur..", "..format("%.2f",-1*(GetTime()-ex)/60).." minutes left.")
        else -- no more buffs
            if #buffs < 1 then return end -- no buffs
            -- process buffs
            --//for i=1,#buffs do Print(i.."="..buffs[i])end
            local con = table.concat(buffs, ", ") Print("Buffs: "..con)
            --
            buffs = wipe(buffs)
            return
        end
end
As far as events a sample use:
Code:
local MyAddon = CreateFrame('frame')
MyAddon:RegisterEvent("ADDON_LOADED")
MyAddon:SetScript("OnEvent", function(self, event, arg1, arg2, ...) OnEvent(self, event, arg1, arg2, ...) end);
Then something like:
Code:
function OnEvent(self, event, arg1, arg2, ...)

if (event == "ADDON_LOADED") then
    self:UnregisterEvent("ADDON_LOADED")
    self:RegisterEvent("PLAYER_LOGIN")
end
This is all sample stuff from work I was actually doing today for a add-on of mine I began to update. So maybe my pokes and peeks in dark corners might have saved you time.

Last edited by Sieben11 : 01-13-13 at 01:13 AM.
  Reply With Quote
01-13-13, 05:49 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) If you're going to post code, post the entire code. Your snippets are obviously incomplete, as they refer to variables -- such as self and buffs -- that are not defined in anything you posted, and appear to be responding to events that are not registered. Especially when you're trying to help someone who says they've never written Lua before, posting only random snippets is more confusing than helpful.

2) You shouldn't use UNIT_AURA to detect shapeshift forms on the player. There is a dedicated event for that -- UPDATE_SHAPESHIFT_FORM.

3) Things like "ex" are not good choices for variable names. Addons are not macros; you don't need to condense everything to save space. Use a descriptive variable name like "expirationTime" that clearly describes its contents without needing to read the whole function to figure it out.

4) You should never call RunScript in an addon. Just write the code you want to run.

5) You should never specify a specific language with SendChatMessage -- like "Common" -- unless you have a specific purpose for doing so (such as in a role-playing addon) and you are checking the player's faction to pass the appropriate language. Your code, for example, will fail for Horde players, since they cannot speak Common. Instead, you should pass nil, which will cause the message to be sent in the player's default language.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-13, 11:56 AM   #13
Sieben11
A Deviate Faerie Dragon
Join Date: Jan 2009
Posts: 10
Originally Posted by Phanx View Post
1) If you're going to post code, post the entire code. Your snippets are obviously incomplete, as they refer to variables -- such as self and buffs -- that are not defined in anything you posted, and appear to be responding to events that are not registered. Especially when you're trying to help someone who says they've never written Lua before, posting only random snippets is more confusing than helpful.

2) You shouldn't use UNIT_AURA to detect shapeshift forms on the player. There is a dedicated event for that -- UPDATE_SHAPESHIFT_FORM.

3) Things like "ex" are not good choices for variable names. Addons are not macros; you don't need to condense everything to save space. Use a descriptive variable name like "expirationTime" that clearly describes its contents without needing to read the whole function to figure it out.

4) You should never call RunScript in an addon. Just write the code you want to run.

5) You should never specify a specific language with SendChatMessage -- like "Common" -- unless you have a specific purpose for doing so (such as in a role-playing addon) and you are checking the player's faction to pass the appropriate language. Your code, for example, will fail for Horde players, since they cannot speak Common. Instead, you should pass nil, which will cause the message to be sent in the player's default language.
1) Sorry for that, did think I was being helpful. =/

2) UNIT_AURA is a constant thing my add-on looks for, so figured why not use it there. Maybe one the less understood changes. Though it'll be examining many different druid related types. It just picks out form types from buffs. And compares it against the stored. If they are not the same, to updating it with the new seen form. Maybe a bit backwards. Then if humanoid checks are the only thing passed into UPDATE_SHAPESHIFT_FORM.

3) I usually use simple names mainly for myself. I have used myriads of shorthand, used to in the military and college. Its my own shorthand that I understand. Though if I want others to understand maybe should write it out.

4) Saw that error, thanks.

5) Thanks for the information on Common. It is a RP add-on. Will use nil as suggested.

Last edited by Sieben11 : 01-14-13 at 12:04 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Detecting buffs/debuffs: Is this still possible from an addon?

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