Как получить название ближайшего тс

Licht

Известный
Автор темы
238
32
Версия MoonLoader
.026-beta
Как получить id или название ближайшего авто?
Таблица с идами в название есть
..
Проще говоря нужно получить ближайший авто и допустим вывести в чат "Самое близкое авто *название*" и тд и тп...
 
Решение
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 400, 600 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = getCarModel(pedID)
            end
        end
    end
    return closestId
end
и переберет он только машины от 400 до 600 серверного айди, класс
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z =...

Albertio

Attention! Thanks for your attention.
877
702
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 1800 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = i
            end
        end
    end
    return closestId
end
 

Licht

Известный
Автор темы
238
32
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 0, 1800 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = i
            end
        end
    end
    return closestId
end
Это получает серверный id кара, а нужен желательно его локальный ид
 

Albertio

Attention! Thanks for your attention.
877
702
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 400, 600 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = getCarModel(pedID)
            end
        end
    end
    return closestId
end
 

Licht

Известный
Автор темы
238
32
подхожу к тому же полиц кару sf вызываю функу.. позвращает -1
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 400, 600 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = getCarModel(pedID)
            end
        end
    end
    return closestId
end
 

paulohardy

вы еще постите говно? тогда я иду к вам
Всефорумный модератор
1,891
1,254
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i = 400, 600 do
        local streamed, pedID = sampGetCarHandleBySampVehicleId(i)
        if streamed then
            local xi, yi, zi = getCarCoordinates(pedID)
            local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
            if dist < minDist then
                minDist = dist
                closestId = getCarModel(pedID)
            end
        end
    end
    return closestId
end
и переберет он только машины от 400 до 600 серверного айди, класс
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i, k in ipairs(getAllVehicles()) do
       local xi, yi, zi = getCarCoordinates(k)
       local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
       if dist < minDist then
          minDist = dist
          closestId = getCarModel(k)
       end
    end
    return closestId
end
 
  • Нравится
Реакции: Licht и Albertio

Albertio

Attention! Thanks for your attention.
877
702
и переберет он только машины от 400 до 600 серверного айди, класс
Lua:
function getClosestCarId()
    local minDist = 9999
    local closestId = -1
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for i, k in ipairs(getAllVehicles()) do
       local xi, yi, zi = getCarCoordinates(k)
       local dist = math.sqrt( (xi - x) ^ 2 + (yi - y) ^ 2 + (zi - z) ^ 2 )
       if dist < minDist then
          minDist = dist
          closestId = getCarModel(k)
       end
    end
    return closestId
end
С тлф пишу и да человеку нужны не id транспорта, а id машины в целом, то есть к примеру инфернус 411
 

paulohardy

вы еще постите говно? тогда я иду к вам
Всефорумный модератор
1,891
1,254

Albertio

Attention! Thanks for your attention.
877
702
да, но у тебя перебор серверных айди
Я же говорю не правильно сделал, но перебор айди надо делать от 400 до 600, это если нужны узнать id или модель машины, а если серверный айди то от 0 и вроде до 1800