-- Использование: pickUpNearestPickup()
local vector3d = require('vector3d')
require('addon')
function pickUpNearestPickup()
local pickup_id, distance = nil, math.huge
local position = vector3d(getPosition())
for id, data in pairs(getAllPickups()) do
if getDistanceBetweenCoords3d(position, distance.position) < distance then
pickup_id, distance = id, getDistanceBetweenCoords3d(position, distance.position)
end
end
if pickup_id then
sendPickedUpPickup(pickup_id)
end
return pickup_id and true or false
end
function getDistanceBetweenCoords3d(point1, point2)
return math.sqrt((point2.x - point1.x) ^ 2 + (point2.y - point1.y) ^ 2 + (point2.z - point1.z) ^ 2)
end