Here we go,
PLAYER_LOGOUT event saving the last index to a savedvariable, two OnUpdate scripts iterating either a new index or the savedvariable, and either of them shuts down the savedvariable one.
Lua Code:
local index = 1
local backup = CreateFrame'Frame'
backup:SetScript('OnUpdate', function(self)
if(not SomeCleverVariableName) then return end
if(_G['NamePlate' .. SomeCleverVariableName]) then
self:Hide()
index = SomeCleverVariableName
SomeCleverVariableName = nil
end
end)
local iterate = CreateFrame'Frame'
iterate:SetScript('OnUpdate', function()
while(_G['NamePlate' .. index]) do
local frame = _G['NamePlate' .. index]
frame:HookScript('OnShow', Update)
backup:Hide()
Update(frame)
index = index + 1
end
end)
iterate:RegisterEvent'PLAYER_LOGOUT'
iterate:SetScript('OnEvent', function()
SomeCleverVariableName = index + 1
end)