WoWInterface

WoWInterface (http://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (http://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   kgpanels script to display pvp icon? (http://www.wowinterface.com/forums/showthread.php?t=45155)

kerouan 11-15-12 09:29 AM

kgpanels script to display pvp icon?
 
Hi. What I'm looking to do is the following:
  • Display a panel when i select a target and the target is pvp (or ffa) flagged.
  • If i select a target that isn't flagged, it will not display anything.
  • Display a different background artwork if the unit is Horde, Alliance, or FFA.

The FFA options are much lower importance than the horde/alliance artwork.

I've tried messing with some of the code from this thread (http://us.battle.net/wow/en/forum/topic/5825572723) but was never able to get anything to actually display.

Ekaterina 11-15-12 11:24 PM

Hi,
Try this - which is modified code from the forum post you linked.

In your onload script:
Lua Code:
  1. self:RegisterEvent("PLAYER_ENTERING_WORLD")
  2. self:RegisterEvent("PLAYER_TARGET_CHANGED")
  3.  
  4. self:Hide()

In your onevent script:
Lua Code:
  1. local FFA_PVP_TEXTURE = "Interface\\TargetingFrame\\UI-PVP-FFA" -- The paths to the textures to be used when the player is flagged for FFA/regular PvP.
  2. local REG_PVP_TEXTURE = "Interface\\TargetingFrame\\UI-PVP-%f"  -- %f in both paths will be replaced with either Horde or Alliance, depending on the player's faction.
  3.  
  4.  self:Hide()
  5. local faction = UnitFactionGroup("target")    
  6.  
  7. if UnitIsPVPFreeForAll("target") then        
  8.     self.bg:SetTexture(FFA_PVP_TEXTURE)        
  9.     self:Show()
  10. elseif UnitIsPVP("target") then        
  11.     self.bg:SetTexture(REG_PVP_TEXTURE:gsub("%%f", faction))        
  12.     self:Show
  13. end

Ekat

Phanx 11-16-12 03:03 AM

You could make that more efficient by (1) using either simple string concatenation, or string.format with the standard substitution token %s, instead of using the more expensive string.gsub with the custom substitution token %f (which is actually a real Lua pattern token indicating a floating-point numeric value), and (2) only hiding the frame if it's actually supposed to be hidden, instead of unconditionally hiding it and then conditionally showing it again immediately afterward.

Also, it's a good practice to only declare variables (I'm looking at your "faction" variable) in the most limited scope where they are useful, and in this case since the value from UnitFactionGroup will only be used once, there's not even any need to store it in a variable. Same goes for the texture paths; there's no reason to assign them both to variables when only one might be used. I'm guessing this script was originally adapted from an arena macro; the authors of those are notorious for misunderstanding the purpose of variables, and assigning everything to a variable even when it's only used once (or not at all) and actually takes up more space in their macro.

OnLoad:
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:Hide()

OnEvent:
Code:

if UnitIsPVPFreeForAll("target") then
        self.bg:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA")
        self:Show()
elseif UnitIsPVP("target") then
        self.bg:SetTexture("Interface\\TargetingFrame\\UI-PVP-" .. UnitFactionGroup("target"))
        self:Show()
else
        self:Hide()
end


kerouan 11-16-12 06:49 AM

This worked great! Thank you!


All times are GMT -6. The time now is 10:35 AM.

vBulletin © 2014, Jelsoft Enterprises Ltd
©2012 ZAM Network LLC