local coordinatesTable =
{
{ x, y, z },
{ x, y, z }
}
function sortCoordiantesByDistance ( x, y )
local coordinates = { }
for _, pos in ipairs ( coordinatesTable ) do
table.insert (
coordinates,
{
pos [ 1 ],
pos [ 2 ],
pos [ 3 ],
getDistanceBetweenPoints2D ( x, y, pos [ 1 ], pos [ 2 ] )
}
)
end
table.sort (
coordinates,
function ( a, b )
return ( tonumber ( a [ 4 ] ) or 0 ) < ( tonumber ( b [ 4 ] ) or 0 )
end
)
return coordinates
end
Example:
addCommandHandler ( "sort",
function ( thePlayer )
local x, y = getElementPosition ( thePlayer )
local coords = sortCoordiantesByDistance ( x, y )
-- do something
end
)