Quantcast

Message delay

Scott King [07-05-15 - 02:36]
Message delay

Added a message delay so the new commands wouldn't get lost in the
loading spam.
Filename
PortraitHealth.lua
PortraitHealth.xml
diff --git a/PortraitHealth.lua b/PortraitHealth.lua
index 9f63887..5baee65 100755
--- a/PortraitHealth.lua
+++ b/PortraitHealth.lua
@@ -1,12 +1,14 @@
 -- Global information

-classDisplayName, class, classID = UnitClass("player");
-PlayerClass = classID;
-PlayerClassName = classDisplayName;
-PlayerClassNameIndex = class;
-PH_v = '3.0'; -- version number
-limit1 = 0; -- limiter for sounds
-executeSound = "Sound\\interface\\AuctionWindowClose.ogg";
+local classDisplayName, class, classID = UnitClass("player");
+local PlayerClass = classID;
+local PlayerClassName = classDisplayName;
+local PlayerClassNameIndex = class;
+local PH_v = '3.0'; -- version number
+local limit1 = 0; -- limiter for sounds
+local executeSound = "Sound\\interface\\AuctionWindowClose.ogg";
+local total = 0 -- timer start
+local done = 0 -- toggle for timer repeat

 -- check for sound enabled
 if PH_sound == nil then
@@ -32,14 +34,19 @@ PH_p[9] = 25 		-- Warlock			9
 PH_p[10] = 10 	-- Monk				  10
 PH_p[11] = 25 	-- Druid			  11

--- Welcome message
-function PH_OnLoad(elapsed)
+
+-- Welcome message (delay message and check to see if the addon is loaded)
+function PH_onUpdate(self,elapsed)
+    total = total + elapsed
+    if total >= 4 and done == 0 and IsAddOnLoaded("PortraitHealth") then
+      DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Portrait Health "..PH_v.."|r loaded. Type |cff00aaff/ph|r for a list of commands.")
+        done = 1
+    end
+end
+
+function PH_Loading()
   SlashCmdList["PH"] = PH_SlashCommandHandler; -- Add our slash command handler to the list of slash commands
   SLASH_PH1 = "/ph"; -- Associate /ph with the slash command list entry for PORTRAITHEALTH
-	if(IsAddOnLoaded("PortraitHealth")) and elapsed > 5 then
-		DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Portrait Health "..PH_v.."|r loaded. Type |cff00aaff/ph|r for a list of commands.");
-	else
-	end
 end

 -- Slash Commands
@@ -51,10 +58,10 @@ function PH_SlashCommandHandler( msg, class )
 -- show commands
 if msg == '' then
   DEFAULT_CHAT_FRAME:AddMessage( "|cffffff00Portrait Health "..PH_v.."|r commands:");
-  DEFAULT_CHAT_FRAME:AddMessage( "Usage: |cff00aaff/ph <command>|r.");
-  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffshow|r to toggle health display.");
-  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffsound|r to toggle sound at execute phase.");
-  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffinfo|r to show current settings.");
+  DEFAULT_CHAT_FRAME:AddMessage( "Usage: |cff00aaff/ph|r <|cff00aaffcommand|r>");
+  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffshow|r to toggle health display");
+  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffsound|r to toggle sound at execute phase");
+  DEFAULT_CHAT_FRAME:AddMessage(" - |cff00aaffinfo|r to show current settings");
 end

 -- health display toggle
@@ -83,7 +90,7 @@ end

 -- show current settings
 if msg == 'info' then
-  DEFAULT_CHAT_FRAME:AddMessage("Addon version |cFFFFFF00" ..PH_v.. "|r");
+  DEFAULT_CHAT_FRAME:AddMessage("Portrait Health version |cFFFFFF00" ..PH_v.. "|r");
   DEFAULT_CHAT_FRAME:AddMessage("Execute at |cFFFF0000"..PH_p[class].."%|r \(|c"..x.colorStr..""..PlayerClassName.."|r\)");

   if PH_on == 1 then
diff --git a/PortraitHealth.xml b/PortraitHealth.xml
index 4c668e1..fba3876 100755
--- a/PortraitHealth.xml
+++ b/PortraitHealth.xml
@@ -32,8 +32,7 @@
 				<OnLoad>
 					self:RegisterEvent("UNIT_HEALTH");
 					self:RegisterEvent("PLAYER_TARGET_CHANGED");
-					self:RegisterEvent("PLAYER_ENTERING_WORLD");
-					PH_OnLoad(elapsed);
+          PH_Loading();
 				</OnLoad>
 				<OnEvent>
 					HealthPercentage(event);
@@ -41,4 +40,11 @@
 				</OnEvent>
 			</Scripts>
 		</Frame>
+    <Frame>
+      <Scripts>
+        <OnUpdate>
+          PH_onUpdate(self,elapsed);
+        </OnUpdate>
+      </Scripts>
+    </Frame>
 </Ui>