1. #1

    Creating an addon

    I'm attempting to create an addon that outputs to my specific channel when certain spells are successfully cast, I'm not good with Lua personally, but I've been trying to get into it and start writing/fixing some of the addons that I really enjoy using that have been abandoned by their developers.

    Just need the basic idea with the code that could fire on successful cast of (for the sake of simplicity) Lightning bolt, Healing Wave, and Healing Rain. I know how to write the toc, just need to see how I'd go about writing this so hopefully I can start trial and error to be able to fix addons

  2. #2
    Deleted
    To listen to events, you always need a frame - it doesn't need to be shown, it just needs to be there. Use CreateFrame for this purpose.
    Code:
    local f = CreateFrame("Frame")
    2. Next, you have to register for the applicable events (using :RegisterEvent). In this case, we want to listen for COMBAT_LOG_EVENT_UNFILTERED
    Code:
    f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    3. Afterwards, you have to create the OnEvent handler script on your frame. We'll use :SetScript to do that.
    Code:
    f:SetScript("OnEvent", function(self, event, ...)
    The ... parameter in the function definition above is special in that it takes all function arguments not handled otherwise into a list object. To take arguments from this list, we use select.

    4. We want to filter only spells cast by the player. We achieve this by matching arg4 (srcGUID) against the player's GUID. To prevent calling UnitGUID too often, we will cache this result in our frame table.
    Code:
        self.pguid = self.pguid or UnitGUID("player")
        if (self.pguid == (select(4,...))) then
    5. We need to check for successful spell casts - for instant casts, this means that arg2 of COMBAT_LOG_EVENT_UNFILTERED will be "SPELL_CAST_SUCCESS", for cast time spells it will be "SPELL_CAST_START".
    Code:
            local subType = (select(2,...))
            if (subType == "SPELL_CAST_START") or (subType == "SPELL_CAST_SUCCESS") then
    6. We want to specifically check for certain spells. We'll fetch the spell ID (arg12) into a local, then check it against the spell IDs and check it against the IDs for the spells we want to announce.
    For simplicity's sake, I'm going to output the spell name using print.
    Code:
                local spellID = (select(12,...))
                if spellID == 403 then
                    print("Lightning Bolt!")
                elseif spellID == 331 then
                    print("Healing Wave!")
                elseif spellID == 73920 then
                    print("Healing Rain!")
                end
    7. Close all the end's and brackets.
    Code:
            end
        end
    end)

  3. #3
    Very interesting, doesn't seem too hard to work out when you get the hang of it. Thanks a lot for taking your time and writing this out for me.

    ---------- Post added 2011-08-30 at 07:16 PM ----------

    How would I go about making the addon fire when anyone in my party/raid used said skills?

  4. #4
    Deleted
    Replace the GUID check with
    Code:
    UnitInParty((select(5,...)))

  5. #5
    Thanks again, I think I have it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •