Zerotorescue@17: do Zerotorescue@160: local disabledGuilds = {}; Zerotorescue@160: Zerotorescue@160: local function GetGuildNames() Zerotorescue@160: local guilds = {}; Zerotorescue@160: Zerotorescue@160: local realm = GetRealmName(); Zerotorescue@160: Zerotorescue@160: -- Process all accounts Zerotorescue@160: for accountName in pairs(DataStore:GetAccounts()) do Zerotorescue@160: for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do Zerotorescue@160: Zerotorescue@160: if disabledGuilds[guildName] then Zerotorescue@160: guilds[guildName] = false; Zerotorescue@160: else Zerotorescue@160: guilds[guildName] = true; Zerotorescue@160: end Zerotorescue@160: Zerotorescue@160: end Zerotorescue@160: end Zerotorescue@160: Zerotorescue@160: return guilds; Zerotorescue@160: end Zerotorescue@160: Zerotorescue@160: local function SetGuildState(guildName, state) Zerotorescue@160: if guildName and type(guildName) == "table" then Zerotorescue@160: disabledGuilds = guildName; Zerotorescue@160: else Zerotorescue@160: if not state then Zerotorescue@160: disabledGuilds[guildName] = true; Zerotorescue@160: else Zerotorescue@160: disabledGuilds[guildName] = nil; Zerotorescue@160: end Zerotorescue@160: end Zerotorescue@160: end Zerotorescue@17: Zerotorescue@17: local function GetTotalCount(itemId) Zerotorescue@17: local realm = GetRealmName(); Zerotorescue@17: Zerotorescue@17: local totalCount = 0; Zerotorescue@17: Zerotorescue@17: -- Process all charracters on this account (GetCharacters defaults to THIS_ACCOUNT) Zerotorescue@17: for characterName, character in pairs(DataStore:GetCharacters(realm, nil)) do Zerotorescue@17: -- Get only useful info (currency / gear shouldn't contain the stuff we are interested in) Zerotorescue@118: local bag, bank = DataStore:GetContainerItemCount(character, itemId); Zerotorescue@118: bag = (bag or 0); bank = (bank or 0); Zerotorescue@54: local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0; Zerotorescue@54: local mail = DataStore:GetMailItemCount(character, itemId) or 0; Zerotorescue@17: Zerotorescue@17: totalCount = totalCount + bag + bank + auctionHouse + mail; Zerotorescue@17: end Zerotorescue@17: Zerotorescue@160: local guilds = {}; Zerotorescue@160: Zerotorescue@160: -- Process all accounts Zerotorescue@160: for accountName in pairs(DataStore:GetAccounts()) do Zerotorescue@160: -- Process all guilds Zerotorescue@160: for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do Zerotorescue@160: if not guilds[guildName] and not disabledGuilds[guildName] then Zerotorescue@160: -- We don't want itemcounts from a single guild to be counted twice, so first to present data wins Zerotorescue@160: Zerotorescue@160: guilds[guildName] = true; Zerotorescue@160: Zerotorescue@160: local guild = DataStore:GetGuildBankItemCount(guild, itemId) or 0; Zerotorescue@160: Zerotorescue@160: totalCount = totalCount + guild; Zerotorescue@160: end Zerotorescue@160: end Zerotorescue@160: end Zerotorescue@160: Zerotorescue@17: return totalCount or -1; Zerotorescue@17: end Zerotorescue@17: Zerotorescue@17: local function GetCharacterCount(itemId) Zerotorescue@17: local character = DataStore:GetCharacter(); Zerotorescue@17: Zerotorescue@118: local bag, bank = DataStore:GetContainerItemCount(character, itemId); Zerotorescue@118: bag = (bag or 0); bank = (bank or 0); Zerotorescue@54: local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0; Zerotorescue@54: local mail = DataStore:GetMailItemCount(character, itemId) or 0; Zerotorescue@17: Zerotorescue@17: return bag, bank, auctionHouse, mail; Zerotorescue@17: end Zerotorescue@17: Zerotorescue@17: local function IsEnabled() Zerotorescue@17: return (DataStore and DataStore.GetContainerItemCount and DataStore.GetAuctionHouseItemCount and DataStore.GetMailItemCount); Zerotorescue@17: end Zerotorescue@17: Zerotorescue@160: IMRegisterItemCountAddon("DataStore (current account only)", GetTotalCount, GetCharacterCount, IsEnabled, nil, GetGuildNames, SetGuildState); Zerotorescue@17: Zerotorescue@17: end