Quantcast

divide by zero fix

Sidoine De Wispelaere [11-12-11 - 19:16]
divide by zero fix

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@426 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Condition.lua
diff --git a/Condition.lua b/Condition.lua
index 64bf768..8411bf1 100644
--- a/Condition.lua
+++ b/Condition.lua
@@ -715,10 +715,16 @@ Ovale.conditions=
 	-- 2 : the limit, in percent
 	LifePercent = function(condition)
 		local target = getTarget(condition.target)
+		if UnitHealthMax(target) == nil or UnitHealthMax(target) == 0 then
+			return nil
+		end
 		return compare(UnitHealth(target)/UnitHealthMax(target), condition[1], condition[2]/100)
 	end,
 	lifePercent = function(condition)
 		local target = getTarget(condition.target)
+		if UnitHealthMax(target) == nil or UnitHealthMax(target) == 0 then
+			return nil
+		end
 		return 100 * UnitHealth(target)/UnitHealthMax(target), 0, 0
 	end,
 	-- Test if a list item is selected
@@ -752,11 +758,19 @@ Ovale.conditions=
 		return GetManaAndRate(false)
 	end,
 	ManaPercent = function(condition)
-		return compare(UnitPower("player")/UnitPowerMax("player"), condition[1], condition[2]/100)
+		local target = getTarget(condition.target)
+		if UnitPowerMax(target) == 0 then
+			return nil
+		end
+		return compare(UnitPower(target)/UnitPowerMax(target), condition[1], condition[2]/100)
 	end,
 	manaPercent = function(condition)
+		local target = getTarget(condition.target)
+		if UnitPowerMax(target) == 0 then
+			return nil
+		end
 		local value, t, rate = GetManaAndRate(false)
-		local conversion = 100/UnitPowerMax("player")
+		local conversion = 100/UnitPowerMax(target)
 		return value * conversion, t, rate * conversion
 	end,
 	MaxHealth = function(condition)