The logic you posted about is to prevent your loop from doing work on anything not visible. MAX_TARGET_BUFFS, which is the boundary for your loop, is a constant -- 32.
self.maxBuffs is the current amount of buffs on the target, but understand that all 32 buff frames exist, and are used dynamically. So, that bit of logic prevents the loop from iterating past what buffs are currently displayed.
The code you posted leaks some very generic variables into the global name space, I posted a cleaned up version.
Lua Code:
hooksecurefunc("TargetFrame_UpdateAuras", function(self)
for i = 1, MAX_TARGET_BUFFS do
local _, _, icon, _, dispelType = UnitBuff(self.unit, i)
if (icon and (not self.maxBuffs or i <= self.maxBuffs) ) then
if (dispelType ~= "Magic") then
_G["TargetFrameBuff"..i]:Hide()
end
end
end
end)