|
|
| Line 1: |
Line 1: |
| {{wowapi}} __NOTOC__ | | {{wowapi}} __NOTOC__ |
| Returns the number of guild members. | | Returns the total and online number of guild members. |
| numGuildMembers = GetNumGuildMembers([includeOffline]); | | numTotalMembers, numOnlineMembers = GetNumGuildMembers(); |
|
| |
|
| ==Parameters== | | ==Parameters== |
| ===Arguments===
| |
| :;includeOffline : Boolean - include offline players in the headcount?
| |
| ===Returns=== | | ===Returns=== |
| :;numGuildMembers : Integer - number of people in the guild (online / both online and offline) or 0 if the player is not in a guild. | | :;numTotalMembers : Integer - total number of people in the guild, or 0 if player is not in a guild. |
| | :;numOnlineMembers : Integer - number of online people in the guild, or 0 if the player is not in a guild. |
|
| |
|
| ==Example== | | ==Example== |
| local numOnline, numTotal = (GetNumGuildMembers()), (GetNumGuildMembers(true)); | | local numTotal, numOnline = GetNumGuildMembers(); |
| DEFAULT_CHAT_FRAME:AddMessage(numTotal .. " guild members: " .. numOnline .. " online, " .. (numTotal - numOnline) .. " offline."); | | DEFAULT_CHAT_FRAME:AddMessage(numTotal .. " guild members: " .. numOnline .. " online, " .. (numTotal - numOnline) .. " offline."); |
| ===Result=== | | ===Result=== |
| Line 17: |
Line 16: |
| ==Notes== | | ==Notes== |
| You may need to call [[API_GuildRoster|GuildRoster()]] first in order to obtain correct data. May return wrong values immediately after quitting a guild. Maximum returned value is 500. | | You may need to call [[API_GuildRoster|GuildRoster()]] first in order to obtain correct data. May return wrong values immediately after quitting a guild. Maximum returned value is 500. |
|
| |
| There is another problem with the return values as they depend on [[API_SetGuildRosterShowOffline|SetGuildRosterShowOffline()]] setting. A simple program like
| |
|
| |
| DEFAULT_CHAT_FRAME:AddMessage("Firing SetGuildRosterShowOffline(false)");
| |
| SetGuildRosterShowOffline(false)
| |
| DEFAULT_CHAT_FRAME:AddMessage("GetNumGuildMembers(): "..tostring(GetNumGuildMembers()));
| |
| DEFAULT_CHAT_FRAME:AddMessage("GetNumGuildMembers(true): "..tostring(GetNumGuildMembers(true)));
| |
| DEFAULT_CHAT_FRAME:AddMessage("Firing SetGuildRosterShowOffline(true)");
| |
| SetGuildRosterShowOffline(true)
| |
| DEFAULT_CHAT_FRAME:AddMessage("GetNumGuildMembers(): "..tostring(GetNumGuildMembers()));
| |
| DEFAULT_CHAT_FRAME:AddMessage("GetNumGuildMembers(true): "..tostring(GetNumGuildMembers(true)));
| |
|
| |
| will show the difference.
| |
|
| |
| Only total members is reliable. Online members changes depending on the setting of [[API_GetGuildRosterShowOffline|GetGuildRosterShowOffline()]]. If set to true, the number of online members is the same as total.
| |
|
| |
| Take care, if your function called by [[G#GUILD_ROSTER_UPDATE|GUILD_ROSTER_UPDATE]] event handling wants to set the show offline status via [[API_SetGuildRosterShowOffline|SetGuildRosterShowOffline()]]. This may cause, due to guild roster updates, a loop, where a user that has opened the guild panel can't switch the status anymore, even if you reset the original status in your function.
| |
|
| |
| This is because [[API_SetGuildRosterShowOffline|SetGuildRosterShowOffline()]] fires an [[G#GUILD_ROSTER_UPDATE|GUILD_ROSTER_UPDATE]] event if changed.
| |
|
| |
| A function that gets reliable values (after at least one [[G#GUILD_ROSTER_UPDATE|GUILD_ROSTER_UPDATE]] event happened) would not consider the flag at all and build its count on roster table. It can probably look like this
| |
|
| |
| -- iterate over guild members list
| |
| local total = GetNumGuildMembers(true)
| |
| local onlineTotal = 0
| |
| local offlineTotal = 0
| |
| for i = 1, total
| |
| do
| |
| -- get info
| |
| local name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName = GetGuildRosterInfo(i)
| |
| if online
| |
| then
| |
| onlineTotal = onlineTotal + 1
| |
| else
| |
| offlineTotal = offlineTotal + 1
| |
| end
| |
| end
| |
| return onlineTotal, offlineTotal, total
| |