Thread Tools Display Modes
09-18-14, 03:32 PM   #1
remusa
A Defias Bandit
Join Date: Sep 2014
Posts: 2
Set raid icons with successful spell

Hello everybody, I've been using the addon "Arena Raid Icons" or scripts to put raid icons on party members in arena. I modified the script trying to make it set icons when I use an ability (for abilities that remove raid icons, I think vanish,shadowmeld,etc. still do this).

If I use a macro with "SetRaidTarget" it doesn't toggle the icon, "SetRaidTargetIcon" does. I'm using SetRaidTarget in the script but it keeps toggling on and off whenever I use an ability, I'd like any help in order to avoid this.

Here's the code:
Code:
    local f = CreateFrame("Frame")
    local MAGE = GetSpellInfo(61316)            --Dalaran Brilliance
    local ROGUE = GetSpellInfo(1784)            --Stealth
    local MONK = GetSpellInfo(115921)           --Legacy of the White Tiger
    local PRIEST = GetSpellInfo(21562)          --Power Word: Fortitude
    local SHAMAN = GetSpellInfo(52127)          --Water Shield
    local DRUID = GetSpellInfo(1126)            --Mark of the Wild
    local PALADIN = GetSpellInfo(20217)         --Blessing of Kings
    local DEATHKNIGHT = GetSpellInfo(57330)     --Horn of Winter
    local WARLOCK = GetSpellInfo(109773)        --Dark Intent
    local WARRIOR = GetSpellInfo(6673)          --Battle Shout
    local HUNTER = GetSpellInfo(13165)          --Aspect of the Hawk
    f:RegisterEvent("UNIT_SPELLCAST_SENT")
    f:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
    f:SetScript("OnEvent",
    function(self, event, arg1, arg2)
        if arg1 == "player" and (arg2 == MAGE) then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=6,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == ROGUE then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == MONK then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == PRIEST then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=6,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == SHAMAN then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == DRUID then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == PALADIN then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=2,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == DEATHKNIGHT then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == WARLOCK then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=6,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == WARRIOR then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        elseif arg1 == "player" and arg2 == HUNTER then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                members = GetNumGroupMembers();
                ci={ROGUE=1,DRUID=2,WARLOCK=2,PALADIN=3,HUNTER=4,MONK=2,PRIEST=5,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
                SetRaidTarget('player',ci[select(2,UnitClass('player'))])
                for i=1,(members-1) do
                    SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
                end
            end
        end
    end
    )
  Reply With Quote
09-18-14, 03:45 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Calling SetRaidTarget on a unit that already has that particular icon above its head will clear its icon.

You can check whether it already has an icon set using GetRaidTargetIndex(unit), and if the icon number returned matches the one you're trying to set then your script needs to bail out.

Either you're calling SetRaidTarget before the icon is cleared, or it isn't actually being cleared in the first place.

There's an event called RAID_TARGET_UPDATE that fires when an icon changes, you might want to just watch that and reassign your icons if they need it.

Last edited by semlar : 09-18-14 at 03:47 PM.
  Reply With Quote
09-18-14, 05:22 PM   #3
remusa
A Defias Bandit
Join Date: Sep 2014
Posts: 2
So it would be something like this? (I'm terrible at lua, sorry in advance )


Code:
function icons()
    if(GetRaidTargetIndex("player")~=5) then
        members = GetNumGroupMembers();
        ci={ROGUE=1,DRUID=2,WARLOCK=3,PALADIN=3,HUNTER=4,MONK=4,PRIEST=6,MAGE=5,SHAMAN=6,WARRIOR=7,DEATHKNIGHT=8}
        SetRaidTarget('player',ci[select(2,UnitClass('player'))])
        for i=1,(members-1) do
            SetRaidTarget('party'..i,ci[select(2,UnitClass('party'..i))])
        end
    end
end

local f = CreateFrame("Frame")
    local MAGE = GetSpellInfo(61316)        --Dalaran Brilliance
    f:RegisterEvent("UNIT_SPELLCAST_SENT")
    f:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
    f:RegisterEvent("RAID_TARGET_UPDATE")
    f:SetScript("OnEvent",
    function(self, event, arg1, arg2)
        if arg1 == "player" and (arg2 == MAGE) then
            if event == "UNIT_SPELLCAST_SUCCEEDED" then
                icons()
            end
    end)
  Reply With Quote
09-18-14, 06:19 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You can try this, it's dry-coded so I might have missed something.
Lua Code:
  1. local ClassIcons = { -- [class] = raid target index
  2.     ROGUE = 1,
  3.     DRUID = 2,
  4.     WARLOCK = 3,
  5.     PALADIN = 3,
  6.     HUNTER = 4,
  7.     MONK = 4,
  8.     PRIEST = 6,
  9.     MAGE = 5,
  10.     SHAMAN = 6,
  11.     WARRIOR = 7,
  12.     DEATHKNIGHT = 8,
  13. }
  14.  
  15. local function SetIcon(unit) -- Set raid icon based on class without canceling it
  16.     local _, class = UnitClass(unit)
  17.     local icon = class and ClassIcons[class]
  18.     if icon and GetRaidTargetIndex(unit) ~= icon then
  19.         SetRaidTarget(unit, icon)
  20.     end
  21. end
  22.  
  23. local IgnoreUpdate = false
  24. local f = CreateFrame('frame')
  25. f:SetScript('OnEvent', function(self, event, ...)
  26.     if IgnoreUpdate or select(2, GetInstanceInfo()) ~= 'arena' then return end -- Busy or not in arena
  27.     IgnoreUpdate = true
  28.     for i = 1, GetNumGroupMembers() - 1 do SetIcon('party' .. i) end
  29.     SetIcon('player')
  30.     IgnoreUpdate = false
  31. end)
  32. f:RegisterEvent('RAID_TARGET_UPDATE')
  33. f:RegisterEvent('PLAYER_ENTERING_WORLD')

edit: I may have misunderstood what you're trying to do. I wrote this based on your code, which sets icons on every arena member based on their class, but your description makes it sound like you want to set an icon on someone when they cast a specific spell.

Maybe you can clarify what you're after.

Also some of the classes have the same raid icon, and of course you can have two of the same class in the group, so I'm not sure how you want it to behave if there's a conflict.

Last edited by semlar : 09-18-14 at 06:41 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Set raid icons with successful spell


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