- Версия MoonLoader
- Другое
Когда нажимаю на "Ид, Ник" нормально сортирует, когда нажимаю на остальные две кнопки, скрипт крашит "invalid order function for sorting", в чём проблема?
Lua:
local scoreboard = {
sortType = {1, false}
}
for index, cText in ipairs({u8'Ид', u8'Ник', u8'Уровень', u8'Пинг'}) do
if imgui.Selectable(cText, true) then
scoreboard.sortType[1] = index
if (scoreboard.sortType[1] == index) then scoreboard.sortType[2] = not scoreboard.sortType[2] end
end
imgui.NextColumn()
end
imgui.Separator()
imgui.BeginGroup()
for _, player in pairs(PlayersScoreboard(scoreboard.sortType[1], scoreboard.sortType[2])) do
imgui.Text(tostring(player[1])) imgui.NextColumn()
imgui.Text(tostring(player[2])) imgui.NextColumn()
imgui.Text(tostring(player[3])) imgui.NextColumn()
imgui.Text(tostring(player[4])) imgui.NextColumn()
imgui.Separator()
end
imgui.EndGroup()
function PlayersScoreboard(sortType, sortD)
local players = {}
for i = 0, sampGetMaxPlayerId(false) do
if (sampIsPlayerConnected(i)) then
local nick, score, ping = sampGetPlayerNickname(i), sampGetPlayerScore(i), sampGetPlayerPing(i)
table.insert(players, {i, nick, score, ping})
end
end
for i = 1, 4 do
if (sortType == i) then table.sort(players, function (a, b) return a[i] < b[i] == not sortD end) end
end
return players
end