Moj mistrz
Monster Creator
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
.
Thanks in advance.

Thanks in advance.
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