Thread: To Gello
View Single Post
08-08-05, 12:01 PM   #10
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
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...

Last edited by Beladona : 08-08-05 at 01:23 PM.
  Reply With Quote