registerVariable closestcar Название ближайшей машины function local c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
registerVariable('closestcar', 'Название ближайшей машины', function()
local car = storeClosestEntities(PLAYER_PED)
local res, model = pcall(getCarModel, car)
return res and tCarsName[model - 399] or ''
end)
registerVariable('closestdriverid', 'Ид ближайшего ко мне водителя', function()
local lastMinPos, closestDriverId
local myPosX, myPosY, myPosZ = getCharCoordinates(PLAYER_PED)
local allVehicles = getAllVehicles()
local mycar = isCharInAnyCar(PLAYER_PED) and storeClosestEntities(PLAYER_PED) or 0
for _, vehicle in ipairs(allVehicles) do
local ped = getDriverOfCar(vehicle)
if mycar ~= vehicle and doesCharExist(ped) and ped ~= PLAYER_PED then
local distance = getDistanceBetweenCoords3d(myPosX, myPosY, myPosZ, getCarCoordinates(vehicle))
if lastMinPos == nil or distance < lastMinPos then
lastMinPos, closestDriverId = distance, select(2, sampGetPlayerIdByCharHandle(ped))
end
end
end
return closestDriverId or ''
end)