Thread Tools Display Modes
11-15-12, 09:29 AM   #1
kerouan
A Defias Bandit
Join Date: Oct 2012
Posts: 2
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.
  Reply With Quote
11-15-12, 11:24 PM   #2
Ekaterina
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 65
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

Last edited by Ekaterina : 11-15-12 at 11:26 PM. Reason: to correct FFA fail.
  Reply With Quote
11-16-12, 03:03 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
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
11-16-12, 06:49 AM   #4
kerouan
A Defias Bandit
Join Date: Oct 2012
Posts: 2
This worked great! Thank you!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » kgpanels script to display pvp icon?


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