Сортировка

Neil_

Активный
Автор темы
201
29
Версия MoonLoader
Другое
Как координаты получить ближайшие из списка к игроку по дистанции
Lua:
function cust()
    local distanceList = {}
    for id = 0,2048 do
        if sampIs3dTextDefined(id) then
            text, color, posX, posY, posZ, distance, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(id)
            if text:find('Чтобы сорвать куст%.') then
                x,y,z = getCharCoordinates(PLAYER_PED)
                distanceList[#distanceList + 1] = getDistanceBetweenCoords3d(x,y,z,posX,posY,posZ)
            end
        end
    end
    table.sort(distanceList) 
end
 

RedHolms

Известный
Проверенный
618
360
Lua:
minDistPos = nil
for something in something do
    -- Итерируешься по таблице с координатами
    -- К примеру, переменная coord - таблица с координатами(x,y и z соответсвенно)
    if minDistPos == nil then minDistPos = coord
    else
        if
            getDistanceBetweenCoords3d(coord.x, coord.y, coord.z, getCharCoordinates(PLAYER_PED))
            < getDistanceBetweenCoords3d(minDistPos.x, minDistPos.y, minDistPos.z, getCharCoordinates(PLAYER_PED))
        then
            minDistPos = coord
        end
    end
end
 
  • Bug
Реакции: neverlessy

neverlessy

Потрачен
170
121
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Lua:
minDistPos = nil
for something in something do
    -- Итерируешься по таблице с координатами
    -- К примеру, переменная coord - таблица с координатами(x,y и z соответсвенно)
    if minDistPos == nil then minDistPos = coord
    else
        if
            getDistanceBetweenCoords3d(coord.x, coord.y, coord.z, getCharCoordinates(PLAYER_PED))
            < getDistanceBetweenCoords3d(minDistPos.x, minDistPos.y, minDistPos.z, getCharCoordinates(PLAYER_PED))
        then
            minDistPos = coord
        end
    end
end
table.sort утопился