Thread Tools Display Modes
07-25-10, 04:53 AM   #1
Lemmiwinks
A Defias Bandit
Join Date: Jul 2009
Posts: 3
kgPanels color & texture switching

Hello,

right now, I use this script for changing a panel's color depending on target's class (in OnUpdate):
Code:
local _, class = UnitClass("target");
	if class == "WARRIOR" then
        self.bg:SetVertexColor(0.95, 0.23, 0.23, self.bg:GetAlpha())
	elseif class == "PRIEST" then
        self.bg:SetVertexColor(1, 0.96, 0.98, self.bg:GetAlpha())
	elseif class == "MAGE" then
        self.bg:SetVertexColor(0.00, 1, 1, self.bg:GetAlpha())
	elseif class == "DRUID" then
        self.bg:SetVertexColor(1, 0.49, 0.04, self.bg:GetAlpha())
	elseif class == "PALADIN" then
        self.bg:SetVertexColor(0.92, 0.22, 0.46, self.bg:GetAlpha())
	elseif class == "HUNTER" then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
	elseif class == "ROGUE" then
        self.bg:SetVertexColor(1, 0.94, 0.16, self.bg:GetAlpha())
	elseif class == "SHAMAN" then
        self.bg:SetVertexColor(0.13, 0.42, 1, self.bg:GetAlpha())
	elseif class == "WARLOCK" then
        self.bg:SetVertexColor(0.36, 0.18, 1, self.bg:GetAlpha())
        elseif class == "DEATHKNIGHT" then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
	end
Works perfectly, except for NPCs since they are usually 3 classes - warrior, paladin and mage.

What I want to do is to make it show color depending on it's reaction (friendly, neutral, hostile etc.)

So I wrote this...
Code:
local _, reaction = UnitReaction("target", "player");
    if reaction == "1" then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
        elseif reaction == "2" then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
        elseif reaction == "3" then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
        elseif reaction == "4" then
        self.bg:SetVertexColor(1, 0.49, 0.04, self.bg:GetAlpha())
        elseif reaction == "5" then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
        elseif reaction == "6" then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
        elseif reaction == "7" then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
        elseif reaction == "8" then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
    end
...what unfortunately doesn't work at all. What am I doing wrong and how can I merge this script with the one above?


My second question is how to make a (different) panel switch texture - again, depending on class, but as for NPCs - depending on classification (normal, rare, elite, boss). I have really no idea how the script should look like...


Thanks in advance!
  Reply With Quote
07-25-10, 11:13 AM   #2
MidgetMage55
Grinch!
 
MidgetMage55's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,498
Not sure if you can make the panel change texture but you can make the panels show and hide based on different parameters. So in the case of elite and so on you would make several panels and have certain ones show for different levels of rarity.

Sadly when it comes to scripts I always have to ask here to get them done but I figured this might at least give you some ideas.
__________________

I think Hong Kong Phooey was a ninja AND a pirate. That was just too much awesome. - Yhor
  Reply With Quote
07-25-10, 01:30 PM   #3
Starinnia
Ninja Code Monkey
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 84
UnitReaction only has one return value, which in your code is going into _ not reaction.

Also, the return is a number, not a string so remove the quotes around the numbers you are doing equality tests against.

Code:
local reaction = UnitReaction("target", "player");
    if reaction == 1 then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
    elseif reaction == 2 then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
    elseif reaction == 3 then
        self.bg:SetVertexColor(1, 0.00, 0.00, self.bg:GetAlpha())
    elseif reaction == 4 then
        self.bg:SetVertexColor(1, 0.49, 0.04, self.bg:GetAlpha())
    elseif reaction == 5 then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
    elseif reaction == 6 then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
    elseif reaction == 7 then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
    elseif reaction == 8 then
        self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha())
    end
Haven't tested this of course, but it fixes the two things I noticed.
  Reply With Quote
07-25-10, 01:52 PM   #4
Lemmiwinks
A Defias Bandit
Join Date: Jul 2009
Posts: 3
Originally Posted by MidgetMage55 View Post
Not sure if you can make the panel change texture but you can make the panels show and hide based on different parameters. So in the case of elite and so on you would make several panels and have certain ones show for different levels of rarity.

Sadly when it comes to scripts I always have to ask here to get them done but I figured this might at least give you some ideas.
Yeah, I was actually thinking about something similar - to anchor individual panels to STUF's labels which would be shown only in the exact situation. Seemed kinda messy to me, but I guess I'll give it a shot

Originally Posted by Starinnia View Post
UnitReaction only has one return value, which in your code is going into _ not reaction.

Also, the return is a number, not a string so remove the quotes around the numbers you are doing equality tests against.

Code:
...
Haven't tested this of course, but it fixes the two things I noticed.
Zomg it works!

Well thanks a lot, I think I've got the right direction now...
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » kgPanels color & texture switching


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