9c6a1a5 - Don't show healthstone warning if you are dead
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 29 Apr 2018 16:49:31 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 29 Apr 2018 16:49:31 +0000
OmaTMW/Healthstone.lua

index 7a8398f..548d1ed 100644 (file)
@@ -2,6 +2,7 @@
 local _;
 local frame = CreateFrame("Frame", "OmaHStone", UIParent);
 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
+local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
 
 local function healthstone()
     frame:SetPoint("TOP");
@@ -18,12 +19,10 @@ local function healthstone()
     frame:Hide();
 
     frame:SetScript("OnEvent", function(self, event)
-        if event == "UNIT_HEALTH" or event == "UNIT_HEALTH_FREQUENT" then
-            if UnitHealth("player")/UnitHealthMax("player") < 0.3 then
-                frame:Show();
-            else
-                frame:Hide();
-            end
+        if not UnitIsDeadOrGhost("player") and UnitHealth("player")/UnitHealthMax("player") < 0.3 then
+            frame:Show();
+        else
+            frame:Hide();
         end
     end);
     frame:UnregisterAllEvents();
@@ -31,9 +30,5 @@ local function healthstone()
     frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player");
 end
 
+frame:SetScript("OnEvent", healthstone);
 frame:RegisterEvent("PLAYER_LOGIN");
-frame:SetScript("OnEvent", function(self, event)
-    if event == "PLAYER_LOGIN" then
-        return healthstone();
-    end
-end);