MobHealth3 API Documentation

From WowAce Wiki
Jump to: navigation, search

Checking for MobHealth3

if MobHealth3 then
    DoMagicStuffs()
else
    DoNotDoMagicStuffs()
end

It's that simple!

Methods

MobHealth3:GetUnitHealth(unit[,current][, max][, name][, level])

Returns the current and max health of the specified unit

Args

unit 
The unitID you want health for
[current] 
(optional) The value of UnitHealth(unit). Passing this if your mod knows it saves MH3 from having to call UnitHealth itself
[max] 
(optional) The value of UnitHealthMax(unit). Passing this if your mod knows it saves MH3 from having to call UnitHealthMax itself
[name] 
(optional) The name of the unit. Passing this if your mod knows it saves MH3 from having to call UnitName itself
[level] 
(optional) The level of the unit. Passing this if your mod knows it saves MH3 from having to call UnitLevel itself

Returns

If the specified unit is alive, hostile and its true max health unknown, the absolute current and max value based on the cache's current entry If the specified unit's friendly or data was not found, returns UnitHealth(unit) and UnitHealthMax(unit)

A third return value is a boolean stating whether an estimation was found

Remarks

Remember, args 2-5 are optional and passing the args if your mod already knows them saves MH3 from having to find the data itself Don't pass level as a string. Please. MobHealth3 does the target-validity checking for you

Example

function YourUnitFrames:UpdateTargetFrame()
	local name, level = UnitName("target"), UnitLevel("target")
	local cur, max, found
	if MobHealth3 then
		cur, max, found = MobHealth3:GetUnitHealth("target", UnitHealth("target"), 
			UnitHealthMax("target"), name, level)
	else
		cur, max = UnitHealth("target"), UnitHealthMax("target")
	end
	YourTargetFrame.HealthText:SetText(cur .. "/" .. max)
	YourTargetFrame.NameText:SetText(name)
	YourTargetFrame.LevelText:SetText(level)
end