Thread Tools Display Modes
12-15-13, 02:18 PM   #1
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
Looking for help : lua snippet for debuff on raid / party member

Hi there!

After a full day looking for a way adapt a tellmewhen icon to WA it seems that I have to use a personnal lua trigger. Hoping i'll found some help here.

In a few words I want an icon showing my purify spell if not on cooldown and if me / party member / raid member have a magic dispelable debuff.

I found UnitDebuff fonction that can return dispelType and this kind of snippet
Code:
/script local i=1;for r=1,GetNumRaidMembers() do if (UnitGroupRolesAssigned("raid"..r) == "HEALER") then SetRaidTarget("raid"..r, i);i=i+1 end end
to browse the whole raid but I don't kwow how to combine them and I need the function to stop as soon as a debuff is found whereas the snippet continue until the last raid member and to run only when spell is off cooldown.

Any idea?

Thanks!

PS : sorry for my english

Edit : forgot about spell cooldown part, I can use WA preset trigger for this part (I think).

Last edited by linalawl : 12-16-13 at 04:12 AM.
  Reply With Quote
12-15-13, 04:39 PM   #2
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
Sounds pretty fishy
If u want target person wich debuff u can dispell, try change
UnitGroupRolesAssigned("raid"..r) == "HEALER"
with
if UnitAura("raid"..r, index, HARMFUL RAID) ~= nil (probably some other check here, not nil )
and loop index thru 40? max auras on target, should be faster then getting dispel type
  Reply With Quote
12-15-13, 05:57 PM   #3
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
The lua code was just to illustrate the way I found to browse the entire raid ^^
  Reply With Quote
12-16-13, 01:08 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by linalawl View Post
In a few words I want an icon showing my purify spell if not on cooldown and if me / party member / raid member have a magic dispelable debuff. .. and I need the function to stop as soon as a debuff is found whereas the snippet continue until the last raid member and to run only when spell is off cooldown.
I'm not sure what WeakAuras trigger functions need to return; the following code assumes it should return true if the trigger should activate, nil or false otherwise. The returns are highlighted in blue, so you can easily find them if you need to change what they return.

If you don't need to check the spell cooldown in the function, remove the first two lines.

Code:
local start, duration, enabled = GetSpellCooldown(527)
if start > 0 or duration > 0 then return end

for j = 1, 40 do
	local debuff, _, _, _, debuffType = UnitDebuff("player", j)
	if not debuff then break end
	if debuffType == "Disease" or debuffType == "Magic" then
		return true
	end
end

local ubase = IsInRaid() and "raid" or "party"
for i = 1, GetNumGroupMembers() do
	local unit = ubase..i
	for j = 1, 40 do
		local debuff, _, _, _, debuffType = UnitDebuff(unit, j)
		if not debuff then break end
		if debuffType == "Disease" or debuffType == "Magic" then
			return true
		end
	end
end
__________________
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
12-16-13, 03:09 AM   #5
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
i know linalawl
i am saying, that if information on http://wowprogramming.com/docs/api/UnitAura is correct, filter HARMFUL RAID should be faster then getting dispelType and then crosscheck it with your character

not the case if you want it for 1 class i guess
  Reply With Quote
12-16-13, 04:04 AM   #6
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
Red face

@Phanx : thanks a lot! it works like a charm! (true was the excepted return).

@Mazzop : I think I misunderstood you because of my gap in english. Sorry for that!

Thanks again guys!

Have a nice week

Edit : Oups. It works for debuff on me but not for the group
Got this error :
Code:
[string "return for j = 1, 40 do..."}1: unexpected symbol near "for"

Last edited by linalawl : 12-16-13 at 04:15 AM.
  Reply With Quote
12-16-13, 04:45 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Are you sure you copied and pasted correctly, and didn't change anything? "return for" doesn't appear anywhere in the code I posted, and shouldn't. It seems like maybe you accidentally removed the "end" at the end of the second line?
__________________
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
12-16-13, 05:03 AM   #8
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
Just fixed!

First : I had to make 2 icons in wa; one for each function

Second : I had to add function() and end for each

For me :

Code:
function()
    for j=1, 40 do
        local debuff, _, _, _, debuffType = UnitDebuff("player", j)
        if not debuff then break end
        if debuffType == "Curse" or debuffType == "Magic" then
            return true
        end
    end 
end
For raid :
Code:
function()
    local ubase = IsInRaid() and "raid" or "party"
    for i = 1, GetNumGroupMembers() do
        local unit = ubase..i
        for j = 1, 40 do
            local debuff, _, _, _, debuffType = UnitDebuff(unit, j)
            if not debuff then break end
            if debuffType == "Curse" or debuffType == "Magic" then
                return true
            end
        end
    end
end
Disease -> Curse because I was on my mage
  Reply With Quote
12-16-13, 05:55 AM   #9
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
One more question

I want to add a range condition. This is what I have :

Code:
function()
    local ubase = IsInRaid() and "raid" or "party"
    for i = 1, GetNumGroupMembers() do
        local unit = ubase..i
        for j = 1, 40 do
            local debuff, _, _, _, debuffType = UnitDebuff(unit, j)
            if not debuff then break end

            if ((debuffType == "Curse" or debuffType == "Magic") and (IsSpellInRange(475, spell, unit)))
            then
                return true
            end
        end
    end
end
I'm trying on friends in duel so this is the question : does IsSpellInRange consider ppl in duel as invalid unit and so return nil in this case? Because right now it only works with
Code:
(IsSpellInRange(475, spell, unit)==nil
  Reply With Quote
12-16-13, 06:06 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1) IsSpellInRange will return nil if either (a) the unit is too far away to cast the given spell on, or (b) the unit is not a valid target for the spell. While you're dueling someone, you can't cast a friendly dispel on them, so IsSpellInRange for Purify will correctly return nil.

2) However, the way you're calling InSpellInRange will fail even on a friendly unit, because you're passing the wrong arguments. Right now you're passing "475, spell, unit" but nowhere in your code is a variable "spell" defined, so you're effectively passing "475, nil, raid4" (if it's checking the raid4 unit, for example). IsSpellInRange expects either a spell name (not an ID) plus a unit, or a spellbook index plus a spell type ("spell" or "pet" with quotes to make them strings) plus a unit. Finding the spellbook index is more work, so you should just use the name.

3) Finally, rather than scanning auras and then checking the range, you should check the range first, so you can skip scanning the auras at all if the unit is out of range.

Code:
function()
	local ubase = IsInRaid() and "raid" or "party"
	for i = 1, GetNumGroupMembers() do
		local unit = ubase..i
		if IsSpellInRange("Purify", unit) then
			for j = 1, 40 do
				local debuff, _, _, _, debuffType = UnitDebuff(unit, j)
				if not debuff then break end
				if debuffType == "Curse" or debuffType == "Magic" then
					return true
				end
			end
		end
	end
end
__________________
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
12-16-13, 06:55 AM   #11
linalawl
A Murloc Raider
Join Date: Dec 2013
Posts: 9
Thank you for this explanations!

I've made the changes, just have to test it in raid (and my untrigger snippet )
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Looking for help : lua snippet for debuff on raid / party member


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