Quantcast

Added a sound when execute phase is reached

Scott King [07-03-15 - 05:32]
Added a sound when execute phase is reached
Filename
PortraitHealth.lua
PortraitHealth.xml
diff --git a/PortraitHealth.lua b/PortraitHealth.lua
index 82041d4..060de27 100755
--- a/PortraitHealth.lua
+++ b/PortraitHealth.lua
@@ -5,19 +5,21 @@ PlayerClass = classID;
 PlayerClassName = classDisplayName;
 PlayerClassNameIndex = class;
 PH_v = '3.0'; -- version number
-
-PH_p = {}			-- Class:			ID:
-PH_p[1] = "20" 		-- Warrior 			1
-PH_p[2] = "20" 		-- Paladin 			2
-PH_p[3] = "20" 		-- Hunter 			3
-PH_p[4] = "35" 		-- Rogue			4
-PH_p[5] = "20" 		-- Priest			5
-PH_p[6] = "35" 		-- Death Knight		6
-PH_p[7] = "10" 		-- Shaman			7
-PH_p[8] = "10" 		-- Mage				8
-PH_p[9] = "25" 		-- Warlock			9
-PH_p[10] = "10" 	-- Monk				10
-PH_p[11] = "25" 	-- Druid			11
+limit1 = 0;
+executeSound = "Sound\\interface\\AuctionWindowClose.ogg";
+
+PH_p = {}			-- Class:			    ID:
+PH_p[1] = 20		-- Warrior 			1
+PH_p[2] = 20 		-- Paladin 			2
+PH_p[3] = 20 		-- Hunter 			3
+PH_p[4] = 35 		-- Rogue			  4
+PH_p[5] = 20 		-- Priest			  5
+PH_p[6] = 35 		-- Death Knight	6
+PH_p[7] = 10 		-- Shaman			  7
+PH_p[8] = 10 		-- Mage				  8
+PH_p[9] = 25 		-- Warlock			9
+PH_p[10] = 10 	-- Monk				  10
+PH_p[11] = 25 	-- Druid			  11

 -- Welcome message
 function PH_OnLoad()
@@ -60,47 +62,97 @@ function PH_SlashCommandHandler( msg, class )
 	end
 end

+--function PHChanged_OnLoad()
+--     this:RegisterEvent("PLAYER_TARGET_CHANGED");
+--end
+
 -- Set the text color and update health output
-function HealthPercentage()
+function HealthPercentage(event)

 	-- Health value to display. Whole numbers only.
 	TargetPercentHealth = (UnitHealth("target") / UnitHealthMax("target") * 100);

+  -- Reset notifier when target changes or the target's health increases beyond the execute range
+  if event == "PLAYER_TARGET_CHANGED" then
+    limit1 = 0;
+  end
+
+  if TargetPercentHealth > PH_p[classID] then
+    limit1 = 0;
+  end
+
+
 	-- Class detection

 	if PlayerClass == 1 and TargetPercentHealth < 20 then 			-- Warrior
 		PortraitHealth_Health:SetTextColor(1,0,0);
-    PlaySoundFile("Sound\\interface\\AuctionWindowClose.ogg");
+    if not UnitIsDead("target") and limit1 == 0 then
+      PlaySoundFile(executeSound);
+      limit1 = 1;
+    end

 		elseif PlayerClass == 2 and TargetPercentHealth <= 20 then 	-- Paladin
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 3 and TargetPercentHealth <= 20 then 	-- Hunter
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 4 and TargetPercentHealth < 35 then 	-- Rogue
 				PortraitHealth_Health:SetTextColor(1,0,0);
-        if not UnitIsDead("target") then
-          PlaySoundFile("Sound\\interface\\AuctionWindowClose.ogg");
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
         end

 		elseif PlayerClass == 5 and TargetPercentHealth < 20 then 	-- Priest
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 6 and TargetPercentHealth < 35 then 	-- Death Knight
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 9 and TargetPercentHealth < 20 then 	-- Warlock
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 10 and TargetPercentHealth <= 10 then -- Monk
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif PlayerClass == 11 and TargetPercentHealth <= 25 then -- Druid
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 		elseif TargetPercentHealth <= 10 then						-- Other classes
 				PortraitHealth_Health:SetTextColor(1,0,0);
+        if not UnitIsDead("target") and limit1 == 0 then
+          PlaySoundFile(executeSound);
+          limit1 = 1;
+        end

 	else
 		PortraitHealth_Health:SetTextColor(1,1,0);
diff --git a/PortraitHealth.xml b/PortraitHealth.xml
index fd0c447..75abf81 100755
--- a/PortraitHealth.xml
+++ b/PortraitHealth.xml
@@ -36,7 +36,7 @@
 					PH_OnLoad();
 				</OnLoad>
 				<OnEvent>
-					HealthPercentage();
+					HealthPercentage(event);
 				</OnEvent>
 			</Scripts>
 		</Frame>