View Single Post
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