Advertisement
rockbandcheeseman

getpostable

Jul 29th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. -- Returns a table with the following syntax:
  2. -- t = getpostable()
  3. -- t[player] = position
  4. function getpostable()
  5.  
  6.     local pos = {}
  7.     local temp = {}
  8.     for player,_ in pairs(scores) do
  9.         local m_player = getplayer(player)
  10.         if m_player then
  11.             local t = {}
  12.             t.player = player
  13.             t.score = scores[player]
  14.             t.kills = readword(m_player, 0x9C)
  15.             t.deaths = readword(m_player, 0xAE)
  16.             t.assists = readword(m_player, 0xA4)
  17.             table.insert(temp, t)
  18.         end
  19.     end
  20.  
  21.     table.sort(temp,
  22.     function(a,b)
  23.         if a.score == b.score then
  24.             if a.kills == b.kills then
  25.                 if a.deaths == b.deaths then
  26.                     if a.assists == b.assists then
  27.                         return a.player > b.player
  28.                     else
  29.                         return a.assists > b.assists
  30.                     end
  31.                 else
  32.                     return a.deaths < b.deaths
  33.                 end
  34.             else
  35.                 return a.kills > b.kills
  36.             end
  37.         else
  38.             return a.score > b.score
  39.         end
  40.     end)
  41.  
  42.     local place = 0
  43.     local actual_place = 0
  44.  
  45.     for k,v in ipairs(temp) do
  46.         if temp[k - 1] then
  47.             if temp[k - 1].score ~= temp[k].score or temp[k - 1].kills ~= temp[k].kills or temp[k - 1].deaths ~= temp[k].deaths or temp[k - 1].assists ~= temp[k].assists then
  48.                 place = actual_place + 1
  49.             end
  50.         else
  51.             place = 1
  52.         end
  53.  
  54.         actual_place = actual_place + 1
  55.  
  56.         pos[temp[k].player] = place
  57.     end
  58.  
  59.     return pos
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement