local function getClosestPickup(ped)
local px, py, pz = getCharCoordinates(ped)
local closest_pickup = nil
local closest_pickup_distance = 999999999999
for _, pickup in pairs(getAllPickups()) do
local pcx, pcy, pcz = getPickupCoordinates(pickup)
local distance = getDistanceBetweenCoords3d(px, py, pz, pcx, pcy, pcz)
if closest_pickup_distance > distance then
closest_pickup_distance = distance
closest_pickup = pickup
end
end
return closest_pickup
end