Its half baked only because you're limiting yourself, and thinking Blizzard is giving us more than they are. I haven't played much with anything other than the API (do the target marks go away when the unit is dead?) but you just have to do it manually. [b]Blizzard is not currently giving us a method to make "saving" targets a reality-- you still have to manually target the unit or find it within your range in order to re-acquire the unit. I've written some code that makes the raid targeting system a little smarter (i.e. it can tell you which targets you've ASSIGNED).
The following code should handle close to what you're looking for. I haven't tested this in game, but its syntactically correct and it should work-- and possibly extend the functionality of the command a bit more. The code is primitive, but I want to make sure it works before I provide anything more optimized. In the case that a raid target is lost upon death, then we'd need to monitor that event and clear the flag there as well, but for now you can just manuall call RaidTarget:Reset() to reset the internal table. This package provides the following functions:
RaidTarget:Set("unit" [,index]) - Sets the raid target index of unit
success = RaidTarget:SmartSet("unit") - Sets the unit to the first available raid target.
RaidTarget:Get("unit") - Returns the raid target index if it exists for unit
RaidTarget:Clear("unit") - An alias to SetRaidTargetIndex("unit", nil)
RaidTarget:Reset() - Resets the internal counter
RaidTarget:ClearAllTargets() - Attempts to clear ALL targets currently set, may not be successful but it tries
statusTable = RaidTarget:Status() - Returns the internal status table
where statusTable is of the form {true,false,true,true,false,false,false,false}
Code:
RaidTarget = {
tbl = {false, false, false, false, false, false, false, false},
Set = function(self, unit, index)
local index = tonumber(index)
if index then
self.tbl[index] = true
else
local oldIndex = GetRaidTargetIndex(unit)
if oldIndex then
self.tbl[oldIndex] = false
end
end
end,
SmartSet = function(self, unit)
for i=1,8 do
if not self.tbl[i] then
self:Set(unit, i)
return true
end
end
end,
Get = function(self, unit)
return GetRaidTargetIndex(unit)
end,
Clear = function(self, unit)
local index = self:Get(unit)
if index then
tbl[index] = false
SetRaidTargetIndex(unit, nil)
end
end,
Status = function(self)
return self.tbl
end,
Reset = function(self)
for i=1,8 do
self.tbl[i] = false
end
end,
ClearAllTargets = function(self)
-- Check if we're in a raid
local num = GetNumRaidMembers()
if num > 0 then
for i=1,num do
local player = "raid"..i
local pet = "raidpet"..i
local playertarget = "raid"..i.."target"
local pettarget = "raidpet"..i.."target"
if GetRaidTargetIndex(player) then self:Clear(player) end
if GetRaidTargetIndex(pet) then self:Clear(pet) end
if GetRaidTargetIndex(playertarget) then self:Clear(playertarget) end
if GetRaidTargetIndex(pettarget) then self:Clear(pettarget) end
end
end
end,
}