maybe try something like this:
Code:
function MHealth_OnLoad()
this:RegisterEvent("UNIT_HEALTH");
this:RegisterEvent("UNIT_MAXHEALTH");
this:RegisterEvent("PLAYER_TARGET_CHANGED");
message("Loaded");
end
function MHealth_OnEvent()
if (event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH") and (arg1 == "target") then MHealth_OnUpdate(); end
if (event == "PLAYER_TARGET_CHANGED") then MHealth_OnUpdate(); end
end
function MHealth_OnUpdate();
local health = {};
if UnitExists("target") then
health.c = MobHealth_GetTargetCurHP();
health.m = MobHealth_GetTargetMaxHP();
if (health.c == nil) then health.c = 0;
if (health.m == nil) then health.m = 0;
health.t = string.format("%d / %d", health.c, health.m);
MHealthText:SetText(health.t);
else
MHealthText:SetText("none");
end
end
extra check for target in the OnEvent insures that the update doesn't get called on ALL health updates (like your own), only the mobs. Also put a check in there to see if the health returned nil, and it gets set to 0 if it did. Let me know if that helps at all...