Quantcast

Implement unit.IsDead() script condition.

Johnny C. Lam [04-21-14 - 05:01]
Implement unit.IsDead() script condition.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1299 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
conditions/IsDead.lua
conditions/files.xml
diff --git a/conditions/IsDead.lua b/conditions/IsDead.lua
new file mode 100644
index 0000000..f77d6ea
--- /dev/null
+++ b/conditions/IsDead.lua
@@ -0,0 +1,40 @@
+--[[--------------------------------------------------------------------
+    Ovale Spell Priority
+    Copyright (C) 2014 Johnny C. Lam
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License in the LICENSE
+    file accompanying this program.
+--]]--------------------------------------------------------------------
+
+local _, Ovale = ...
+
+do
+	local OvaleCondition = Ovale.OvaleCondition
+
+	local API_UnitIsDead = UnitIsDead
+	local ParseCondition = OvaleCondition.ParseCondition
+	local TestBoolean = OvaleCondition.TestBoolean
+
+	--- Test if the target is dead.
+	-- @name IsDead
+	-- @paramsig boolean
+	-- @param yesno Optional. If yes, then return true if the target is dead. If no, then return true if it isn't dead.
+	--     Default is yes.
+	--     Valid values: yes, no.
+	-- @param target Optional. Sets the target to check. The target may also be given as a prefix to the condition.
+	--     Defaults to target=player.
+	--     Valid values: player, target, focus, pet.
+	-- @return A boolean value.
+	-- @usage
+	-- if pet.IsDead() Spell(revive_pet)
+
+	local function IsDead(condition)
+		local yesno = condition[1]
+		local target = ParseCondition(condition)
+		local boolean = API_UnitIsDead(target)
+		return TestBoolean(boolean, yesno)
+	end
+
+	OvaleCondition:RegisterCondition("isdead", false, IsDead)
+end
\ No newline at end of file
diff --git a/conditions/files.xml b/conditions/files.xml
index d73e298..6087ce7 100644
--- a/conditions/files.xml
+++ b/conditions/files.xml
@@ -46,6 +46,7 @@
 	<Script file="InFlightToTarget.lua" />
 	<Script file="InRange.lua" />
 	<Script file="IsAggroed.lua" />
+	<Script file="IsDead.lua" />
 	<Script file="IsEnraged.lua" />
 	<Script file="IsFeared.lua" />
 	<Script file="IsFriend.lua" />