RosterLib-2.0

From WowAce Wiki
Jump to: navigation, search
Ability Vanish.png This addon page is not claimed.
Please see Unclaimed Addon Pages for more details.

RosterLib-2.0 is a library to provide a complete unit roster (solo, party, raid), with and without pets. All units are cached. The following data is available for each unit: name, unitid, class, subgroup and rank. A custom event will trigger when the roster changes and pass a table of changed units as argument. These objects also contain the old information, so you can easily compare old and new to see what changed (new subgroup, new rank because promoted,...).

As you can extend that roster table with your own data (e.g. .hasAggro, .isFriend, .pvprank, .race,...), you probably won't need to store your own roster table anymore. Also you won't need to watch for roster related events, but only for the one RosterLib triggers.

RosterLib requires AceLibrary, AceOO-2.0 and AceEvent-2.0.

Example

function myAddon:OnInitialize()
	self.rosterlib = AceLibrary("RosterLib-2.0")
end

function myAddon:OnEnable()
	self:RegisterEvent("RosterLib_RosterChanged")
end

function myAddon:RosterLib_RosterChanged(tbl)
	self:Debug("---- Event: RosterLib_RosterChanged")
	for n in tbl do
		local u = tbl[n]
		if not u.name then
			self:Debug(u.oldname .. " left.")
		elseif not u.oldname then
			self:Debug(u.name .. " joined.")
		elseif u.subgroup ~= u.oldsubgroup then
			self:Debug(u.name.." now in subgroup "..u.subgroup)
		end
	end
end

function myAddon:UpdateFood(name)
	local u = self.rosterlib:GetUnitObjectFromName(n)
	if not u then return end
	if u.class = "WARRIOR" then
		u.food = "meat"
	else
		u.food = "vegetables"
	end
end

function myAddon:PrintFood()
	for u in self.rosterlib:IterateRoster() do   -- we're skipping pets.
		if u.food == "meat" then
			self:Print(u.name .. " prefers meat")
		elseif u.food == "vegetables" then
			self:Print(u.name .. " is vegetarian")
		else
			self:Print("no idea what " .. u.name .. " prefers")
		end
	end
end

API Documentation

:GetUnitIDFromName(name)

Get the unit id for the unit with the requested name.

Args

nameÂ
string - unit name

Returns

string - unit id of the requested unit or nil if the unit is not found

Remarks

Problems may arise if two pets in the party/raid have the same name.

Example

local unitid = RosterLib:GetUnitIDFromName(name)
if unitid ~= nil then
    FollowUnit(unitid)
end

:GetUnitIDFromUnit(unit)

Get the unit id for the requested unit.

Args

unitÂ
string - unit id

Returns

string - unit id of the requested unit or nil if the unit is not found

Remarks

The unitid returned is the unit id stored in the roster.

Example

local unitid = RosterLib:GetUnitIDFromUnit("target")
if unitid ~= nil then
    print("Target is also ".. unitid)
end

:GetUnitObjectFromName(name)

Get the unit object for the unit with the requested name.

Args

nameÂ
string - unit name

Returns

table - unit object for the requested unit or nil if the unit is not found

Remarks

Problems may arise if two pets in the party/raid have the same name.

The unit object by default has the following fields:

name
UnitName
unitid
unitid
class
UnitClass or "PET"
rank
raid rank
subgroup
raid subgroup
online
UnitIsConnected

Example

local unit = RosterLib:GetUnitObjectFromName(name)
if unit ~= nil then
    print(name .." is in subgroup ".. unit.subgroup)
end

:GetUnitObjectFromUnit(unit)

Get the unit object for the requested unit.

Args

unitÂ
string - unit id

Returns

table - unit object for the requested unit or nil if the unit is not found

Remarks

Example

local unit = RosterLib:GetUnitObjectFromUnit("target")
if unit ~= nil then
    print(unit.name .." is in subgroup ".. unit.subgroup)
end

:IterateRoster(pets)

Iterate over every unit in the party/raid, optionally including pets.

Args

petsÂ
boolean - should pets be included?

Returns

function - an iterator that can be used in a for loop.

Remarks

Example

local rogues = {}
-- just looking for rogues so we can tell IterateRoster to skip pets
for unit in RosterLib:IterateRoster(false) do
    if unit.class == "ROGUE" then
        table.insert(rogues, unit)
    end
end