function getClosestPlayerId()
local closestId = -1
mydist = 30
local x, y, z = getCharCoordinates(PLAYER_PED)
for i = 0, 999 do
local streamed, pedID = sampGetCharHandleBySampPlayerId(i)
if streamed and getCharHealth(pedID) > 0 and not sampIsPlayerPaused(pedID) then
local xi, yi, zi = getCharCoordinates(pedID)
local dist = getDistanceBetweenCoords3d(x, y, z, xi, yi, zi)
if dist <= mydist then
mydist = dist
closestId = i
end
end
end
return closestId
end