Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
Hello there, I've got one question regarding Game.getSpectators. Namely, is it possible to print lowest level spectator? If yes, then how? I'd like to know that .
something like this should do the trick, you just need to change the "(...)" params
Code:
Game.getLowestLevelSpectator(...)
local specPlayers = {}
for k, creature in pairs(Game.getSpectators(...)) do
if creature:isPlayer() then
specPlayers[k] = creature
end
end
if specPlayers ~= {} then
for k, player in pairs(specPlayers) do
local lowest = nil
if lowest == nil then
lowest = {k, player:getLevel()}
end
if lowest[2] <= player then
lowest = {k, player:getLevel()}
end
end
return specPlayers[k]
end
return nil
end
function getLowestLevelSpectator(...)
local specPlayers = {}
for _, creature in pairs(Game.getSpectators(...)) do
if creature:isPlayer() then
table.insert(specPlayers, creature)
end
end
if (#specPlayers > 2) then
table.sort(specPlayers, function(a, b) return (a:getLevel() < b:getLevel()) end)
end
return specPlayers[1]
end
function getLowestLevelSpectator(...)
local spectators = Game.getSpectators(...)
for i = #spectators, 2, -1 do
if not spectators[i]:isPlayer() or spectators[i]:getLevel() < spectators[i - 1]:getLevel() then
spectators[i] = nil
end
end
return spectators[#spectators > 1 and 2 or 1]
end