Quantcast
KGPanels Scripts target - WoWInterface
Thread Tools Display Modes
11-30-10, 07:30 PM   #1
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
KGPanels Scripts target

HIyas, Im trying to make a panel (for target UF to be class colored). Meaning, does anyone know the script to make a panel the TARGETS class color? My thanks, in advance for any and all help~

Fake edit: I tried the page at wowace, but no one ever answers questions there >.<
  Reply With Quote
11-30-10, 09:49 PM   #2
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Writing one, just a sec.

Edit:
Code:
-- OnLoad
self:RegisterEvent("UNIT_TARGET")


-- OnEvent
if (event=="UNIT_TARGET") then
local _, class = UnitClass("target")
	if (class=="DEATHKNIGHT") then
		self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
	elseif (class=="DRUID") then
		self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
	elseif (class=="HUNTER") then
		self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
	elseif (class=="MAGE") then
		self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
	elseif (class=="PALADIN") then
		self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
	elseif (class=="PRIEST") then
		self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
	elseif (class=="ROGUE") then
		self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
	elseif (class=="SHAMAN") then
		self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
	elseif (class=="WARLOCK") then
		self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
	elseif (class=="WARRIOR") then
		self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
	end
end

Last edited by Waky : 11-30-10 at 09:55 PM.
  Reply With Quote
11-30-10, 10:02 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,757
Originally Posted by Waky View Post
Writing one, just a sec.

Edit:
Code:
-- OnLoad
self:RegisterEvent("PLAYER_TARGET_CHANGED")
Fixed. That one there will only fire for your target.

/edit: you also need to change the OnEvent (btw, checking for the event isn't needed since we're only registering for one event anyway)

Code:
-- OnEvent
local _, class = UnitClass("target")
if class then
	if (class=="DEATHKNIGHT") then
		self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
	elseif (class=="DRUID") then
		self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
	elseif (class=="HUNTER") then
		self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
	elseif (class=="MAGE") then
		self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
	elseif (class=="PALADIN") then
		self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
	elseif (class=="PRIEST") then
		self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
	elseif (class=="ROGUE") then
		self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
	elseif (class=="SHAMAN") then
		self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
	elseif (class=="WARLOCK") then
		self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
	elseif (class=="WARRIOR") then
		self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
	end
end
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh


Last edited by Seerah : 11-30-10 at 10:05 PM.
  Reply With Quote
11-30-10, 10:12 PM   #4
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Pssh :P Thanks Seerah
  Reply With Quote
11-30-10, 10:14 PM   #5
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
My thanks, ever so much, both of you~
  Reply With Quote
01-26-11, 09:34 PM   #6
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Originally Posted by Seerah View Post
Fixed. That one there will only fire for your target.

/edit: you also need to change the OnEvent (btw, checking for the event isn't needed since we're only registering for one event anyway)

Code:
-- OnEvent
local _, class = UnitClass("target")
if class then
	if (class=="DEATHKNIGHT") then
		self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
	elseif (class=="DRUID") then
		self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
	elseif (class=="HUNTER") then
		self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
	elseif (class=="MAGE") then
		self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
	elseif (class=="PALADIN") then
		self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
	elseif (class=="PRIEST") then
		self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
	elseif (class=="ROGUE") then
		self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
	elseif (class=="SHAMAN") then
		self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
	elseif (class=="WARLOCK") then
		self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
	elseif (class=="WARRIOR") then
		self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
	end
end
Sigh...I need to wear a helmet in public, I suppose ( my brain is mushy)...how would I apply this to BORDER of targets panel?
  Reply With Quote
01-26-11, 11:04 PM   #7
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
A bit more compact, should work:

-- OnEvent
Code:
local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class]
self.bg:SetVertexColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
As for borders.

-- OnEvent
Code:
local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class]
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
  Reply With Quote
01-26-11, 11:32 PM   #8
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
How lame is it that I spent 2.5 hours trying to figure this out, lol?
My thanks, Nibleheim, it's much appreciated~
  Reply With Quote
01-27-11, 12:00 AM   #9
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
This is doing the same thing.....it's fine if I click on target to target, but everytime I DEselect a target (no target at all) it throws a huge error >.<


Message: [string "a_OnEvent"]:3: attempt to index local 'Color' (a nil value)
Time: 01/27/11 00:57:24
Count: 3
Stack: [string "a_OnEvent"]:3: in function <[string "a_OnEvent"]:1>
[C]: in function `CameraOrSelectOrMoveStop'
[string "CAMERAORSELECTORMOVE"]:4: in function <[string "CAMERAORSELECTORMOVE"]:1>

Locals: self = kgPanel1 {
0 = <userdata>
missing_parent_at_load = false
missing_anchor_at_load = false
text = <unnamed> {
}
bg = <unnamed> {
}
scripts_loaded = false

Is the gist of it.

Last edited by Kendian : 01-27-11 at 12:05 AM.
  Reply With Quote
01-27-11, 01:07 AM   #10
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Kendian View Post
This is doing the same thing.....it's fine if I click on target to target, but everytime I DEselect a target (no target at all) it throws a huge error >.<


Message: [string "a_OnEvent"]:3: attempt to index local 'Color' (a nil value)
Time: 01/27/11 00:57:24
Count: 3
Stack: [string "a_OnEvent"]:3: in function <[string "a_OnEvent"]:1>
[C]: in function `CameraOrSelectOrMoveStop'
[string "CAMERAORSELECTORMOVE"]:4: in function <[string "CAMERAORSELECTORMOVE"]:1>

Locals: self = kgPanel1 {
0 = <userdata>
missing_parent_at_load = false
missing_anchor_at_load = false
text = <unnamed> {
}
bg = <unnamed> {
}
scripts_loaded = false

Is the gist of it.
Ahh, thought you were already accounting for no target situations. Here you go:

Code:
if UnitExists("target") then
  local _, Class = UnitClass("target")
  local Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
  self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
end
  Reply With Quote
01-27-11, 01:18 AM   #11
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
You know, may as well go all the way

Colored by Pet, Player, Hostility.

Code:
local Color = {r = 1, g = 1, b = 1};
	
if UnitExists("target") then
	if ( UnitExists("pet") and UnitIsUnit("target", "pet") ) then
		Color = {r = 1, g = 1, b = 1}
	elseif UnitIsPlayer("target") then
		local _, class = UnitClass("target");
		Color = RAID_CLASS_COLORS[class];
	else
		if UnitIsEnemy("player", "target") then
			Color = {r = 1, g = 0, b = 0}
		elseif UnitCanAttack("player", UFD.unitname) then
			Color = {r = 1, g = 1, b = 0}
		else
			Color = {r = 0, g = 1, b = 0}
		end
	end
end
	
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
  Reply With Quote
01-27-11, 01:55 AM   #12
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
That worked perfectly. You have my thanks, and my gratitude, hero~
  Reply With Quote
01-27-11, 05:19 AM   #13
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Rofl, now this got me thinking if theres a script to show pets happiness?

Edit: To change a panels color depending on pets happiness, i.e red/yellow/green.

Last edited by Kendian : 01-27-11 at 05:41 AM.
  Reply With Quote
01-27-11, 01:48 PM   #14
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Kendian View Post
Rofl, now this got me thinking if theres a script to show pets happiness?

Edit: To change a panels color depending on pets happiness, i.e red/yellow/green.
There's a script for almost anything

Code:
local Color = {r = 1, g = 1, b = 1}
if UnitExists("pet") then
	local happiness = GetPetHappiness()
	if happiness == 1 then
		Color = {r = 1, g = 0, b = 0}
	elseif happiness == 2 then
		Color = {r = 1, g = 1, b = 0}
	elseif happiness == 3 then
		Color = {r = 0, g = 1, b = 0}
	end
end
self:SetBackdropBorderColor(Color.r, Color.g, Color.b)
  Reply With Quote
01-27-11, 04:52 PM   #15
Othgar
"That" Guy
 
Othgar's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2010
Posts: 228
Originally Posted by Nibelheim View Post
There's a script for almost anything
So then would there be a script that could hide a panel when you're not moving, but show the panel when you are moving? I was thinking of this earlier for a minimap mod, but couldn't come up with a way to do it. Closest I got was
Code:
if movementspeed == 0 then
hide
else show
but I've said it before and I'll say it again....I suck with lua...for now
__________________


  Reply With Quote
01-27-11, 06:13 PM   #16
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Othgar View Post
So then would there be a script that could hide a panel when you're not moving, but show the panel when you are moving? I was thinking of this earlier for a minimap mod, but couldn't come up with a way to do it. Closest I got was
Code:
if movementspeed == 0 then
hide
else show
but I've said it before and I'll say it again....I suck with lua...for now
Yeah, that's doable.

Code:
local FrameToHide = Minimap
local MovementTimer = CreateFrame("Frame")
MovementTimer.UpdateInterval = 0.1
MovementTimer.ToggleDelay = 1
MovementTimer.Elapsed = 0
MovementTimer.StoppedElapsed = 0
MovementTimer.LastPosition = {x = 0, y = 0}
MovementTimer:Show()
MovementTimer:SetScript("OnUpdate", function(self, elapsed)
	MovementTimer.Elapsed = MovementTimer.Elapsed + elapsed
	if MovementTimer.Elapsed >= MovementTimer.UpdateInterval then
		local x, y = GetPlayerMapPosition("Player")
		if x == MovementTimer.LastPosition.x and y == MovementTimer.LastPosition.y then
			MovementTimer.StoppedElapsed = MovementTimer.StoppedElapsed + MovementTimer.Elapsed
			if MovementTimer.StoppedElapsed >= MovementTimer.ToggleDelay then
				FrameToHide:Hide()
			end
		else
			MovementTimer.StoppedElapsed = 0
			if not FrameToHide:IsShown() then FrameToHide:Show() end
		end
		MovementTimer.LastPosition.x = x
		MovementTimer.LastPosition.y = y
		MovementTimer.Elapsed = 0
	end
end)
If you want to hide a kgPanel with this code, then you'll need to create another kgPanel with this code in it's OnLoad section. And, instead of the top line local FrameToHide = Minimap, use local FrameToHide = kgPanels:FetchFrame("my panel") where mypanel is what you named the panel you want to hide in kgPanels.

Reason you need another panel, is that when you hide a frame, it's OnUpdate scripts no longer work.

Adjust MovementTimer.ToggleDelay to your liking. It's how long in seconds after you stop to hide the Minimap.

Last edited by Nibelheim : 01-27-11 at 06:22 PM.
  Reply With Quote
01-27-11, 10:29 PM   #17
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
The pet panel didnt work ( in onload/onevent/onupdate) but it showed no errors, so it was ME that did something wrong, lol. I'm not getting it, and that frustrates me SOOOO much, rofl. Anyhow, I did want to say thank you, the time and effort was MUCH appreciated =)
  Reply With Quote
01-27-11, 10:38 PM   #18
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Kendian View Post
The pet panel didnt work ( in onload/onevent/onupdate) but it showed no errors, so it was ME that did something wrong, lol. I'm not getting it, and that frustrates me SOOOO much, rofl. Anyhow, I did want to say thank you, the time and effort was MUCH appreciated =)
Woops, forgot to give you the Events.

-- OnLoad
Code:
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_PET")
self:RegisterEvent("UNIT_POWER")
-- OnEvent
Code:
local Color = {r = 1, g = 1, b = 1}
if UnitExists("pet") then
	local happiness = GetPetHappiness()
	if happiness == 1 then
		Color = {r = 1, g = 0, b = 0}
	elseif happiness == 2 then
		Color = {r = 1, g = 1, b = 0}
	elseif happiness == 3 then
		Color = {r = 0, g = 1, b = 0}
	end
end
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())

Last edited by Nibelheim : 01-27-11 at 10:41 PM.
  Reply With Quote
01-27-11, 11:56 PM   #19
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Simply said, you rock. Thanks again!

Still can't get it to fire, tho. >.<
Was going to put a cropped screenie here to show you, but am not intelligent to figure out how~

Last edited by Kendian : 01-28-11 at 12:12 AM.
  Reply With Quote
01-28-11, 01:14 AM   #20
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Kendian View Post
Simply said, you rock. Thanks again!

Still can't get it to fire, tho. >.<
Was going to put a cropped screenie here to show you, but am not intelligent to figure out how~
Hmm, there's no reason it shouldn't work. Does your panel have a border? Try changing the last line to:

Code:
self.bg:SetVertexColor(Color.r, Color.g, Color.b, 1)

Last edited by Nibelheim : 01-28-11 at 01:25 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KGPanels Scripts target

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