function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
sampRegisterChatCommand("hplayer", player_handle_get)
while true do wait(0) end
end
function getNearestID()
local chars = getAllChars()
local mx, my, mz = getCharCoordinates(PLAYER_PED)
local nearId, dist = nil, 10000
for i,v in ipairs(chars) do
if doesCharExist(v) and v ~= PLAYER_PED then
local vx, vy, vz = getCharCoordinates(v)
local cDist = getDistanceBetweenCoords3d(mx, my, mz, vx, vy, vz)
local r, id = sampGetPlayerIdByCharHandle(v)
if r and cDist < dist then
dist = cDist
nearId = id
end
end
end
return nearId
end
function player_handle_get()
local id = getNearestID()
if id then
result, handle = sampGetCharHandleBySampPlayerId(id)
sampAddChatMessage('nearest id '..id, -1)
else
sampAddChatMessage('nearest id 0 (игрок в зоне стрима не найден)', -1)
end
end