Jump to content

Some resources to get on the nearest vehicle?


Andres99907

Recommended Posts

On 27/10/2016 at 4:04 AM, Andres99907 said:

some resources to get on the nearest vehicle?

, Sorry , My English is bad. :(

Try this

local mathFloor = math.floor

function getNearestVehicle( player ) 
    if player and isElement(player) then
        local x, y, z = getElementPosition( player ) 
        local vehicles =  getElementsByType( "vehicle" )
        local prevDistance 
        local nearestVehicle 
        for i=1, #vehicles do
            local distance = mathFloor(getDistanceBetweenPoints3D( x, y, z, getElementPosition(vehicles[i])))
            if distance <= ( prevDistance or distance + 1 ) then 
                prevDistance = distance 
                nearestVehicle = vehicles[i] 
            end 
        end 
        return nearestVehicle or false 
    end 
end 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...