WoW:USERAPI GuildNameToIndex: Difference between revisions

m
no edit summary
(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...')
 
mNo edit summary
Line 3: Line 3:
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 [[API GuildRoster|GuildRoster]]() and local to each machine.
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 [[API GuildRoster|GuildRoster]]() and local to each machine.


''&lt;PREFIX&gt;''_GuildNameToIndex(name [, searchOffline])
GuildNameToIndex(name [, searchOffline])


== Function Parameters ==
== Function Parameters ==
=== Arguments ===
=== Arguments ===


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


=== Returns ===
=== 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 "")
:;index: Number - A number between 1 and the size of the guild (inclusive) if the player is found. Nil 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 ""), however it is best you check for a return value before calling them (use better coding standards than Blizzard did!)
 


== Example ==
== Example ==
  ''&lt;PREFIX&gt;''_GuildNameToIndex("bob")
  local bob_i = GuildNameToIndex("bob")
  ''&lt;PREFIX&gt;''_GuildNameToIndex("bob", true)
  local offline_bob_i = GuildNameToIndex("bob", true)


==Code==
==Code==


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


__NOTOC__
__NOTOC__
[[Category:User defined functions]]
Anonymous user