Created
September 7, 2016 17:29
-
-
Save dbjorkholm/6601b7c9147af58d9f1e53493a24ae3d to your computer and use it in GitHub Desktop.
[TFS 1.x] Fetch ingame Top Players
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function getTopPlayers(maxPlayers) | |
local topPlayers = { } | |
for _, tmpPlayer in ipairs(Game.getPlayers()) do | |
if not tmpPlayer:getGroup():getAccess() then | |
topPlayers[#topPlayers + 1] = { | |
name = tmpPlayer:getName(), | |
level = tmpPlayer:getLevel() | |
} | |
end | |
end | |
table.sort(topPlayers, function(lhs, rhs) return lhs.level > rhs.level end) | |
if #topPlayers > maxPlayers then | |
for i = 1, #topPlayers do | |
topPlayers[#topPlayers] = nil | |
if #topPlayers == maxPlayers then | |
break | |
end | |
end | |
end | |
return topPlayers | |
end | |
-- Usage | |
local topPlayers = getTopPlayers(5) | |
if #topPlayers ~= 0 then | |
-- something | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment