WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Macro Help (https://www.wowinterface.com/forums/forumdisplay.php?f=140)
-   -   Detecting the Group Position of an Arena Oppenent (https://www.wowinterface.com/forums/showthread.php?t=49778)

Sylen 08-22-14 11:41 AM

Detecting the Group Position of an Arena Oppenent
 
Hey, i got the following macro:
Code:

/focus [@arena1]
Due to macro space problems i usually have to edit the macro for the case that the enemy healer is arena2 or arena3 (etc.).
What i thought about doing is, writing a script which detects the positon of the healer in the enemy arena team and then edits my macro automatically for me. I am aware that this is only working outside of combat, which is fine, because i just want it to work during the preparation time. Also i dont mind if i have to fire the script manually while waiting in the prep zone.
Because Blizzard already implemented the detection of the enemy specs during the prep phase i thought i could use this to filter the enemy team.
The idea is to listen for the event that fires when information about arena opponents are available. Then use it to get information about enemy specializations. In the end filter the information to get the postion of the healer in the enemy team.
Code:

local f=CreateFrame("Frame")
        f:RegisterEvent("ARENA_PREP_OPPONENT_SPECIALIZATIONS")
       
f:SetScript("OnEvent",function(self,event,...)       
        local numOpps=GetNumArenaOpponentSpecs()
        for i=1,numOpps do               
                local specID=GetArenaOpponentSpec(i)               
                local _,spec,_,_,_,role,_=GetSpecializationInfoByID(specID)                       
                if specID>0 and role="HEALER" then       
                        --/run index=GetMacroIndexByName("name"); print(i) use this to get macroIndex
                        EditMarco(index,nil,nil,"/focus [@arena"..i.."]",1,1)                       
                end               
        end
end)

Links to the functions/events i used in my code:

Phanx 08-22-14 02:19 PM

A few problems with your code that should be raising errors in-game:
  • You misspelled "EditMacro" as "EditMarco".
  • You're referring to a variable "index" which you don't define anywhere.

Other than that you're definitely on the right track. I'd suggest checking for InCombatLockdown() before proceeding with anything else in the event handler, just in case. I'd also use some nice variables at the top to contain the desired macro name and template, so it's easier to customize them, eg.

Code:

local MACRO_NAME = "FocusHealer"
local MACRO_BODY = "/focus [@arena%d]"

Then in your event handler you can pass the desired text as "string.format(MACRO_BODY, i)". You can also just pass the macro name to EditMacro instead of an index; I'd suggest doing that for the sake of simplicity and avoiding an extra function call.

Finally, go get BugSack. The default error display, even if you have it enabled, is simply not good enough for addon development, as it is incapable of showing errors that occur early in the loading sequence -- and that's where most of your errors will occur during development. Being able to see the error messages your code is raising is invaluable, as the message will tell you exactly what the problem is, and exactly where in your code it is.


All times are GMT -6. The time now is 08:09 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI