Reply
 
Thread Tools Display Modes
Unread 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.
kerouan is offline   Reply With Quote
Unread 11-15-12, 11:24 PM   #2
Ekaterina
A Cyclonian
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 43
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.
Ekaterina is offline   Reply With Quote
Unread 11-16-12, 03:03 AM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,136
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
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-16-12, 06:49 AM   #4
kerouan
A Defias Bandit
Join Date: Oct 2012
Posts: 2
This worked great! Thank you!
kerouan is offline   Reply With Quote
Reply

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

Thread Tools
Display Modes

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