Advertisement
Guest User

Skada.lua merge by name

a guest
Mar 6th, 2013
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. -- NEW FUNCTION
  2. function Skada:find_player_by_name(set, playername)
  3.     if set then
  4.         for i, p in ipairs(set.players) do
  5.             if p.name == playername then
  6.                 return p
  7.             end
  8.         end
  9.     end
  10. end
  11.  
  12. -- REPLACES OLD FUNCTION
  13. -- Returns or creates a player in the current.
  14. function Skada:get_player(set, playerid, playername)
  15.     --if playerid then
  16.     --  self:Print("Getting player with playerid "..playerid)
  17.     --end
  18.        
  19.     --if playername then
  20.     --  self:Print("Getting player with name "..playername)
  21.     --end
  22.    
  23.     -- Add player to set if it does not exist.
  24.     local player = Skada:find_player(set, playerid)
  25.  
  26.     if not player then
  27.         -- If we do not supply a playername (often the case in submodes), we can not create an entry.
  28.         if not playername then
  29.             return
  30.         end
  31.        
  32.         player = Skada:find_player_by_name(set, playername)
  33.        
  34.         if not player then
  35.             player = {id = playerid, class = select(2, UnitClass(playername)), name = playername, first = time(), ["time"] = 0}
  36.  
  37.             -- Tell each mode to apply its needed attributes.
  38.             for i, mode in ipairs(modes) do
  39.                 if mode.AddPlayerAttributes ~= nil then
  40.                     mode:AddPlayerAttributes(player)
  41.                 end
  42.             end
  43.  
  44.             -- Strip realm name
  45.             -- This is done after module processing due to cross-realm names messing with modules (death log for example, which needs to do UnitHealthMax on the playername).
  46.             local player_name, realm = string.split("-", playername, 2)
  47.             player.name = player_name or playername
  48.  
  49.             table.insert(set.players, player)
  50.         end
  51.     end
  52.  
  53.     -- The total set clears out first and last timestamps.
  54.     if not player.first then
  55.         player.first = time()
  56.     end
  57.  
  58.     -- Mark now as the last time player did something worthwhile.
  59.     player.last = time()
  60.     changed = true
  61.     return player
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement