1. #1
    Deleted

    LUA Help - Unit Buff

    I've been trying to write a simple addon script to place a raid marker on the targets of a spell (e.g. Wild Growth). However - I'm having a small problem. I will correctly be marked when I receive Wild Growth, but other raid members will not.

    I've checked the values of the variables before calling UnitBuff (they seem sensible), but it doesn't return true (even when they definitely have the Wild Growth buff active).

    The code is below (I've never written any LUA before so please excuse the standard...) Can anyone help please?

    Code:
    local frame = CreateFrame("Frame", "PastaAddonFrame");
    frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
    
    --Set counter for raid marker
    local raidMarkIndex = 1
    
    frame:SetScript("OnEvent", function(self, event, unit, spellName, ...)
    
        if ((event == "UNIT_SPELLCAST_SUCCEEDED") and (spellName == "Wild Growth")) then
    
            --Check raid members
            for i=1,25 do
                local raidUnit = "raid"..i
                if UnitExists(raidUnit) then
                                  
                    --If member has buff, mark
                    if UnitBuff(raidUnit, spellName) then
    
                        --Set raid marker
                        SetRaidTarget(raidUnit, raidMarkIndex)
    
                        --Increment raid mark index
                        raidMarkIndex = raidMarkIndex + 1
                            
                        --Reset raid mark index after 6
                        if raidMarkIndex > 6 then
                            raidMarkIndex = 1
                        end
                    end
                end
            end
        end
    end)

  2. #2
    it's probably that the buff isn't active on the player at the time of the event. the basic structure for this would be using UNIT_AURA instead of UNIT_SPELLCAST_SUCCEEDED.

    use this as your OnEvent script

    Code:
    function(self,event,...)
        if event="UNIT_AURA" then
            local unit=...
            if UnitBuff(unit,"Wild Growth") then
                --whatever
            end
        end
    end
    it might give you somewhat better performance to use combat log events instead, but that's probably not an issue right now
    Last edited by pnutbutter; 2013-09-26 at 07:13 PM.

  3. #3
    Deleted
    Quote Originally Posted by pnutbutter View Post
    *snip*
    Thanks for the advice. I've changed it as you suggest and it works a bit better, but still not quite right. The marks now go on everyone who has wild growth, but they are changing on every tick of the buff, rather than every new application.

    Off the top of my head I wonder if you could put a duration check in there to work this out, is that possible? Is there a cleaner way of doing it?

    Code:
    local frame = CreateFrame("Frame", "PastaAddonFrame");
    frame:RegisterEvent("UNIT_AURA");
    
    --Set counter for raid marker
    local raidMarkIndex = 1
    
    frame:SetScript("OnEvent", function(self, event, unit, ...)
    
        if (event == "UNIT_AURA") then
                    
                    --If member has buff, mark
                    if UnitBuff(unit, "Wild Growth") then
    
                        --Set raid marker
                        SetRaidTarget(unit, raidMarkIndex)
    
                        --Increment raid mark index
                        raidMarkIndex = raidMarkIndex + 1
                            
                        --Reset raid mark index after 6
                        if raidMarkIndex > 6 then
                            raidMarkIndex = 1
                        end
                    end
        end
    end)

  4. #4
    Yeah, that's an option. Instead of just checking the existence of return values from UnitBuff you can do something like
    Code:
    local duration, expirationTime=select(6, UnitBuff(unit, "Wild Growth"))
        if duration and expirationTime and floor((expirationTime - duration - GetTime())+0.5)==0 then
            SetRaidTarget(unit, raidMarkIndex)
            raidMarkIndex = raidMarkIndex % 6 + 1 
        end
    end
    where "floor(n+0.5)" is the janky Lua way of doing round(n) because sometimes if you don't round time values you'll get 0.0000000000000003 or something, and "raidMarkIndex % 6" allows you to remove the entire "if raidMarkIndex > 6" chunk

    Keep in mind that this will still re-mark a player if their Wild Growth buff is refreshed. Another way to do it would be keeping active units in memory and then in your OnEvent check if that unit is one of the active units.
    Last edited by pnutbutter; 2013-09-26 at 09:59 PM.

Posting Permissions

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