• 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!

Solved Table sort

VirrageS

←•†ĿuĀ && ©¤¤•→
Joined
May 30, 2010
Messages
984
Reaction score
63
Location
Poland
Hello

How I can sort players by health in this scrpit:
Lua:
local list = getSpectators(getCreaturePosition(cid), 5, 7, false)
local players = {}
 
if(#list > 0) then
	for i = 1, #list do
		if(isPlayer(list[i])) then
			table.insert(players, list[i])
		end
	end
end
Example:

In table have inserted this values (by scrpit above):
players = {238437203, 238437204, 238437205, 238437206}

and they have miscellaneous health:
{450, 500, 315, 205}

And after sort table will looking like that:
players = {238437206, 238437205, 238437203, 238437204}




Is way to do it??

Thanks and rep for help :thumbup:
 
Last edited:
table.sort(players, function(a, b) return getCreatureHealth(a) > getCreatureHealth(b) end)
 
Back
Top