ближайшая машина

Tenkara

Потрачен
Автор темы
380
173
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Версия MoonLoader
.026-beta
как сделать чтобы вывело одну самую близкую к педу машину? даже если их стоит несколько

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('findcar',function(arg)
        lua_thread.create(function()
            if #arg == 0 then
                return sampAddChatMessage('/findcar [idmodel]')
            elseif string.match(arg,'%d+') then
                arg = tonumber(arg)
                if arg >= 400 and arg <= 611 then
                    local carname = getNameOfVehicleModel(arg)
                    if carname ~= nil then
                        for i = 0, 2000 do
                            local res, car = sampGetCarHandleBySampVehicleId(i)
                            if res then
                                local modelId = getCarModel(car)
                                if carname == getNameOfVehicleModel(modelId) then
                                    local px, py, pz = getCharCoordinates(playerPed)
                                    local x, y, z = getCarCoordinates(car)
                                    local dist = getDistanceBetweenCoords3d(px, py, pz, x, y, z)
                                    if dist < 50 then
                                        sampGetVehicleIdByCarHandle(i)
                                        sampAddChatMessage(i, -1)
                                        sampAddChatMessage(string.format('X:%d Y:%d Z:%d model:%s[%d]',x, y, z,carname,arg),-1)
                                        sampProcessChatInput("/setmarker "..x.. ", " ..y.. ", "..z)
                                        sampProcessChatInput("/rtpc")
                                        wait(3000)
                                        sampSendEnterVehicle(i, 0)
                                        wait(1000)
                                        warpCharIntoCar(PLAYER_PED, car)
                                    end
                                end
                            end
                        end
                    end
                else
                    sampAddChatMessage('от 400 до 611', -1)
                end
            end
        end)
    end)
end
 

hinazuki

Потрачен
344
94
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Lua:
print(getClosestCarId())

function getClosestCarId()
    local minDist = 100 -- дистанция
    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

Взял отсюда: