Advertisement
Guest User

Guild management timer

a guest
Aug 5th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. local frame = CreateFrame("Frame")
  2. local timer = frame:CreateAnimationGroup()
  3. timer.animation = timer:CreateAnimation()
  4. timer.animation:SetDuration(1)
  5. timer.animation:SetOrder(1)
  6. timer.frame = frame
  7.  
  8. timer.testMode = true
  9.  
  10. local didAction, lastName, lastAction
  11. timer:SetScript("OnFinished", function(self)
  12.     didAction = false
  13.     for i = 1, GetNumGuildMembers() do
  14.         local name, _, rankIndex, level, _, _, _, _, _, _, classFileName = GetGuildRosterInfo(i)
  15.         -- Make it consistent with values for SetGuildMemberRank() for sanity's sake.
  16.         rankIndex = rankIndex + 1
  17.  
  18.         if rankIndex == 1 or rankIndex == 2 or rankIndex == 3 then -- Guild master, Officers, Intouchables
  19.             return
  20.         end
  21.  
  22.         if CanGuildPromote() then
  23.             local targetRank
  24.             if level >= 1 and level <= 79 and rankIndex ~= 7 then
  25.                 targetRank = 7
  26.             elseif level >= 80 and level <= 84 and rankIndex ~= 6 then
  27.                 targetRank = 6
  28.             elseif level >= 85 and level <= 89 and rankIndex ~= 5 then
  29.                 targetRank = 5
  30.             elseif level == 90 and rankIndex ~= 4 then
  31.                 targetRank = 4
  32.             end
  33.            
  34.             if self.testMode then
  35.                 print("PROMOTE", name, targetRank)
  36.             else
  37.                 if lastAction == "PROMOTE" and lastName == name then
  38.                     -- Avoid infinite loops if the action is failing:
  39.                     return print("Action failed:", lastAction, lastName, targetRank)
  40.                 end
  41.                 didAction, lastAction, lastName = true, "PROMOTE", name
  42.                 SetGuildMemberRank(i, targetRank)
  43.                 break
  44.             end
  45.         end
  46.  
  47.         if not ignoreList[name] and CanGuildRemove() then
  48.             local year, month, day = GetGuildRosterLastOnline(i)
  49.             -- (year > 0 or month > 0 or day > 21)
  50.             if year and (
  51.                 (rankIndex == 7
  52.                     and (day >= 1 and level == 1)
  53.                     or (day >= 2 and level == 5 and classFileName == "DEATHKNIGHT")
  54.                     or (day >= 3 and ((level > 1 and level <= 5) or (level > 55 and level <= 55 and classFileName == "DEATHKNIGHT")))
  55.                     or (day >= 14 and level > 5 and level <= 79)
  56.                 )
  57.                 or (rankIndex == 6 and day >= 21)
  58.                 or ((rankIndex == 4 or rankIndex == 5) and day >= 28)
  59.             ) then
  60.                 if self.testMode then
  61.                     print("REMOVE", name)
  62.                 else
  63.                     if lastAction == "REMOVE" and lastName == name then
  64.                         -- Avoid infinite loops if the action is failing:
  65.                         return print("Action failed:", lastAction, lastName)
  66.                     end
  67.                     didAction, lastAction, lastName = true, "REMOVE", name
  68.                     GuildUninvite(name)
  69.                     break
  70.                 end
  71.             end
  72.         end
  73.     end
  74.  
  75.     -- Start it again if we did something.
  76.     if didAction then
  77.         self:Play()
  78.     end
  79. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement