Skip to content

Instantly share code, notes, and snippets.

@dbjorkholm
Created September 7, 2016 17:29
Show Gist options
  • Save dbjorkholm/6601b7c9147af58d9f1e53493a24ae3d to your computer and use it in GitHub Desktop.
Save dbjorkholm/6601b7c9147af58d9f1e53493a24ae3d to your computer and use it in GitHub Desktop.
[TFS 1.x] Fetch ingame Top Players
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