Quantcast

Enable or disable sound with slash command

Scott King [07-03-15 - 05:44]
Enable or disable sound with slash command
Filename
PortraitHealth.lua
diff --git a/PortraitHealth.lua b/PortraitHealth.lua
index 060de27..2338fc6 100755
--- a/PortraitHealth.lua
+++ b/PortraitHealth.lua
@@ -7,6 +7,7 @@ PlayerClassNameIndex = class;
 PH_v = '3.0'; -- version number
 limit1 = 0;
 executeSound = "Sound\\interface\\AuctionWindowClose.ogg";
+PH_sound = 0;

 PH_p = {}			-- Class:			    ID:
 PH_p[1] = 20		-- Warrior 			1
@@ -52,12 +53,22 @@ function PH_SlashCommandHandler( msg, class )
 			DEFAULT_CHAT_FRAME:AddMessage("Addon version |cFFFFFF00" ..PH_v.. "|r");
 			DEFAULT_CHAT_FRAME:AddMessage("Execute at |cFFFF0000"..PH_p[class].."%|r \(|c"..x.colorStr..""..PlayerClassName.."|r\)");

+    elseif msg == 'sound on' then
+      DEFAULT_CHAT_FRAME:AddMessage("Sound enabled.");
+      PH_sound = 1;
+
+    elseif msg == 'sound off' then
+      DEFAULT_CHAT_FRAME:AddMessage("Sound disabled.");
+      PH_sound = 0;
+
 		-- display list of available commands
 		elseif msg == '' then
 			DEFAULT_CHAT_FRAME:AddMessage( "|cffffff00Portrait Health "..PH_v.."|r commands:");
 			DEFAULT_CHAT_FRAME:AddMessage( "Type |cff00aaff/ph|r before the command. Ex: |cff00aaff/ph off|r disables the health display.");
 			DEFAULT_CHAT_FRAME:AddMessage( " - |cff00aaffoff|r to disable target health display.");
 			DEFAULT_CHAT_FRAME:AddMessage( " - |cff00aaffon|r to re-enable.");
+      DEFAULT_CHAT_FRAME:AddMessage( " - |cff00aaffsound off|r to disable execute sound notifier.");
+      DEFAULT_CHAT_FRAME:AddMessage( " - |cff00aaffsound on|r to enable execute sound notifier.");
 			DEFAULT_CHAT_FRAME:AddMessage( " - |cff00aaffinfo|r for information about your current settings.");
 	end
 end
@@ -86,70 +97,70 @@ function HealthPercentage(event)

 	if PlayerClass == 1 and TargetPercentHealth < 20 then 			-- Warrior
 		PortraitHealth_Health:SetTextColor(1,0,0);
-    if not UnitIsDead("target") and limit1 == 0 then
+    if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 then
           PlaySoundFile(executeSound);
           limit1 = 1;
         end

 		elseif PlayerClass == 4 and TargetPercentHealth < 35 then 	-- Rogue
 				PortraitHealth_Health:SetTextColor(1,0,0);
-        if not UnitIsDead("target") and limit1 == 0 then
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 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
+        if not UnitIsDead("target") and limit1 == 0 and PH_sound == 1 then
           PlaySoundFile(executeSound);
           limit1 = 1;
         end