Описание: Получает серверный id ближайшей машины
Пример использования:
Lua:
function getClosestCarId()
local minDist = 9999
local closestId = -1
local x, y, z = getCharCoordinates(PLAYER_PED)
for i, k in ipairs(getAllVehicles()) do
local streamed, carId = sampGetVehicleIdByCarHandle(k)
if streamed then
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 = carId
end
end
end
return closestId
end
Lua:
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("carid", function()
sampAddChatMessage("Самая ближайшая машина к вам имеет ID: "..getClosestCarId(), -1)
end)
while true do
wait(0)
end
end
function getClosestCarId()
local minDist = 9999
local closestId = -1
local x, y, z = getCharCoordinates(PLAYER_PED)
for i, k in ipairs(getAllVehicles()) do
local streamed, carId = sampGetVehicleIdByCarHandle(k)
if streamed then
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 = carId
end
end
end
return closestId
end
Последнее редактирование: