From d62b6f20545dd5f18b5e71884214e9a2ac17ac9a Mon Sep 17 00:00:00 2001 From: Scott King Date: Sun, 12 Jan 2014 21:37:34 -0700 Subject: [PATCH] Version 2 - added class detection --- PortraitHealth.lua | 61 +++++++++++++++++++++++++++++++++++++++++++++++----- PortraitHealth.toc | 2 +- PortraitHealth.xml | 1 + 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/PortraitHealth.lua b/PortraitHealth.lua index b2d5f55..56984ee 100644 --- a/PortraitHealth.lua +++ b/PortraitHealth.lua @@ -1,19 +1,70 @@ + +classDisplayName, class, classID = UnitClass("player"); +PlayerClass = classID; + +-- Class ID Listing + +-- Warrior 1 +-- Paladin 2 +-- Hunter 3 +-- Rogue 4 +-- Priest 5 +-- Death Knight 6 +-- Shaman 7 +-- Mage 8 +-- Warlock 9 +-- Monk 10 +-- Druid 11 + + function HealthPercentage() + -- health value to display. whole numbers only. - local TargetPercentHealth = math.ceil((UnitHealth("target") / UnitHealthMax("target") * 100)); + TargetPercentHealth = math.ceil((UnitHealth("target") / UnitHealthMax("target") * 100)); + -- Class detection - -- recolor text at 35% (future idea: class detection) - if TargetPercentHealth < 35 then + if PlayerClass == 1 and TargetPercentHealth < 20 then -- Warrior PortraitHealth_Health:SetTextColor(1,0,0); - else + + elseif PlayerClass == 2 and TargetPercentHealth <= 20 then -- Paladin + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 3 and TargetPercentHealth <= 20 then -- Hunter + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 4 and TargetPercentHealth < 35 then -- Rogue + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 5 and TargetPercentHealth <= 25 then -- Priest + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 6 and TargetPercentHealth < 35 then -- Death Knight + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 9 and TargetPercentHealth <= 25 then -- Warlock + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 10 and TargetPercentHealth <= 10 then -- Monk + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif PlayerClass == 11 and TargetPercentHealth <= 25 then -- Priest + PortraitHealth_Health:SetTextColor(1,0,0); + + elseif TargetPercentHealth <= 10 then -- Other classes + PortraitHealth_Health:SetTextColor(1,0,0); + + else PortraitHealth_Health:SetTextColor(1,1,0); end + -- change the portrait to show current health if UnitIsDead("target") then PortraitHealth_Health:SetText('Dead'); else PortraitHealth_Health:SetText(TargetPercentHealth .. '%'); end -end \ No newline at end of file + +end + diff --git a/PortraitHealth.toc b/PortraitHealth.toc index 62e6d18..ac56163 100644 --- a/PortraitHealth.toc +++ b/PortraitHealth.toc @@ -2,6 +2,6 @@ ## Title: Portrait Health ## Notes: See the health of your target as a percentage in the target frame portrait. ## Author: Cilcraft -## Version: 1.1 +## Version: 2.0 PortraitHealth.lua PortraitHealth.xml diff --git a/PortraitHealth.xml b/PortraitHealth.xml index e7e75cc..9d9a242 100644 --- a/PortraitHealth.xml +++ b/PortraitHealth.xml @@ -32,6 +32,7 @@ self:RegisterEvent("UNIT_HEALTH"); self:RegisterEvent("PLAYER_TARGET_CHANGED"); + self:RegisterEvent("PLAYER_ENTERING_WORLD"); HealthPercentage(); -- 1.7.9.5