не понял хендл или всё таки ид? Вот вариант с идом
function nearestPlayerId()
local minDist = 500
local savedId = -1
local mx, my, mz = getCharCoordinates(1)
for k, handle in pairs(getAllChars()) do
local cx, cy, cz = getCharCoordinates(handle)
local dist =...