From 1e007617c34ce4b6cdff4b4842d776417c233545 Mon Sep 17 00:00:00 2001 From: Xruptor Date: Wed, 11 Aug 2010 09:29:28 -0400 Subject: [PATCH] -Added checks for Hunters to prevent bag/equip scan spamming due to ammo being used. -Will reduce lag and cpu use from constant scanning due to bag/equip updates due to ammot slot. --- BagSync.lua | 43 +++++++++++++++++++++++++++++++++++++++---- BagSync.toc | 2 +- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/BagSync.lua b/BagSync.lua index 129a5e6..f0caf7a 100644 --- a/BagSync.lua +++ b/BagSync.lua @@ -20,14 +20,16 @@ local L = BAGSYNC_L local lastItem local lastDisplayed = {} -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() +local currentPlayer +local currentRealm +local playerClass local NUM_EQUIPMENT_SLOTS = 19 local BS_DB local BS_GD local BS_TD local MAX_GUILDBANK_SLOTS_PER_TAB = 98 local doTokenUpdate = 0 +local ammoCount = 0 local SILVER = '|cffc7c7cf%s|r' local MOSS = '|cFF80FF00%s|r' @@ -57,6 +59,11 @@ function BagSync:PLAYER_LOGIN() local ver = GetAddOnMetadata("BagSync","Version") or 0 + --load our player info after login + currentPlayer = UnitName('player') + currentRealm = GetRealmName() + playerClass = select(2, UnitClass("player")) + --initiate the db self:StartupDB() @@ -81,6 +88,11 @@ function BagSync:PLAYER_LOGIN() BS_DB.guild = nil end + --check for hunter + if playerClass == "HUNTER" then + ammoCount = GetInventoryItemCount('player', 0) or 0 + end + --this will force an update of the -2 key ring self:SaveBag('key', KEYRING_CONTAINER, true) @@ -520,6 +532,10 @@ function BagSync:SaveItem(bagname, bagid, slot) end function BagSync:OnBagUpdate(bagid) + + --do hunter check + if not BagSync:DoHunterChecks() then return end + --this will update the bank/bag slots local bagname @@ -555,7 +571,6 @@ function BagSync:OnBagUpdate(bagid) for slot = 1, GetBagSize(bagid) do self:SaveItem(bagname, bagid, slot) end - end function BagSync:SaveEquipment() @@ -564,6 +579,9 @@ function BagSync:SaveEquipment() lastItem = nil lastDisplayed = {} + --do hunter check + if not BagSync:DoHunterChecks(true) then return end + for slot = 0, NUM_EQUIPMENT_SLOTS do local link = GetInventoryItemLink('player', slot) local index = GetTag('equip', 0, slot) @@ -587,7 +605,6 @@ function BagSync:SaveEquipment() BS_DB[index] = nil end end - end function BagSync:ScanEntireBank() @@ -690,6 +707,24 @@ function BagSync:ScanMailbox() BagSync.isCheckingMail = nil end +function BagSync:DoHunterChecks(equipSwitch) + --if not hunter return true, or if not in combat return true + if playerClass ~= "HUNTER" then return true end + if not UnitAffectingCombat("player") then return true end + + --this function is used to prevent scan spamming of the bags due to hunter ammo being used + local currAmmo = (GetInventoryItemCount('player', 0) or 0) + + if not equipSwitch and ammoCount ~= currAmmo then + return false + elseif ammoCount ~= currAmmo then + ammoCount = (GetInventoryItemCount('player', 0) or 0) + return false + end + + return true +end + ------------------------ -- Money Tooltip -- ------------------------ diff --git a/BagSync.toc b/BagSync.toc index 8325896..1deb52f 100644 --- a/BagSync.toc +++ b/BagSync.toc @@ -2,7 +2,7 @@ ## Title: BagSync ## Notes: BagSync tracks your characters items and displays it within tooltips. ## Author: Xruptor -## Version: 3.9 +## Version: 4.0 ## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB localization\localization.lua -- 1.7.9.5