Quantcast

Fixed the currency counter

Robert [10-19-14 - 00:01]
Fixed the currency counter
IsActiveBattlefieldArena() was returning false false instead of nil nil,
so the a==nil statement was always causing the function to return true.
Filename
BagSync.lua
diff --git a/BagSync.lua b/BagSync.lua
index 1997a8d..c5fe535 100644
--- a/BagSync.lua
+++ b/BagSync.lua
@@ -606,24 +606,16 @@ end
 ------------------------
 --      Tokens        --
 ------------------------
-
 local function IsInBG()
 	if (GetNumBattlefieldScores() > 0) then
 		return true
 	end
-	local status, mapName, instanceID, minlevel, maxlevel
-	for i=1, GetMaxBattlefieldID() do
-		status, mapName, instanceID, minlevel, maxlevel, teamSize = GetBattlefieldStatus(i)
-		if status == "active" then
-			return true
-		end
-	end
 	return false
 end

 local function IsInArena()
 	local a,b = IsActiveBattlefieldArena()
-	if (a == nil) then
+	if not a then
 		return false
 	end
 	return true
@@ -640,8 +632,10 @@ local function ScanTokens()
 	end

 	local lastHeader
+	local limit = GetCurrencyListSize()
+
+	for i=1, limit do

-	for i=1, GetCurrencyListSize() do
 		local name, isHeader, isExpanded, _, _, count, icon = GetCurrencyListInfo(i)
 		--extraCurrencyType = 1 for arena points, 2 for honor points; 0 otherwise (an item-based currency).

@@ -649,6 +643,7 @@ local function ScanTokens()
 			if(isHeader and not isExpanded) then
 				ExpandCurrencyList(i,1)
 				lastHeader = name
+				limit = GetCurrencyListSize()
 			elseif isHeader then
 				lastHeader = name
 			end
@@ -1102,6 +1097,9 @@ function BagSync:PLAYER_LOGIN()
 	self:RegisterEvent("AUCTION_HOUSE_SHOW")
 	self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE")

+	--currency
+	self:RegisterEvent('CURRENCY_DISPLAY_UPDATE')
+
 	--void storage
 	self:RegisterEvent('VOID_STORAGE_OPEN')
 	self:RegisterEvent('VOID_STORAGE_CLOSE')
@@ -1203,6 +1201,12 @@ end
 --      Event Handlers      --
 ------------------------------

+function BagSync:CURRENCY_DISPLAY_UPDATE()
+	if IsInBG() or IsInArena() or InCombatLockdown() or UnitAffectingCombat("player") then return end
+	doTokenUpdate = 0
+	ScanTokens()
+end
+
 function BagSync:PLAYER_REGEN_ENABLED()
 	if IsInBG() or IsInArena() or InCombatLockdown() or UnitAffectingCombat("player") then return end
 	self:UnregisterEvent("PLAYER_REGEN_ENABLED")