WoW:USERAPI GuildNameToIndex

Revision as of 11:36, 22 June 2009 by WoWWiki>Condo2k4 (Created page with '{{userfunc}} <!-- Leave this line in! --> A simple function that takes a players name and returns their index within the currently stored Guild Roster. Note that the index for a...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions

A simple function that takes a players name and returns their index within the currently stored Guild Roster. Note that the index for a player in each Guild Roster will depend on how it is sorted and can be different from player to player. The index only remains constant between all calls to GuildRoster() and local to each machine.

<PREFIX>_GuildNameToIndex(name [, searchOffline])

Function Parameters

Arguments

name
String - The name of the player to search for. Is case-insensitive.
searchOffline
Boolean - Whether to search the offline players for this player. Default is false.

Returns

index
Number - A number between 1 and the size of the guild (inclusive) if the player is found. 0 if they are not found. Note, most predefined guild functions do not error if passed an index of 0 and will return a null result (such a nil, 0, false or "")


Example

<PREFIX>_GuildNameToIndex("bob")
<PREFIX>_GuildNameToIndex("bob", true)

Code

local function <PREFIX>_GuildNameToIndex(name, searchOffline)
    local index = GetNumGuildMembers(searchOffline or false);
    while(index~=0) do
        local gName = GetGuildRosterInfo(index);
        if( string.lower(gName) == string.lower(name) ) then
            return index;
        end
        index = index - 1;
    end
    return 0;
end