Jump to content

Searching nearest vehicles from one dimension


Bananovy

Recommended Posts

Hello.

Is there any way to make a function which will find nearest vehicle only from the player's dimension? I found this function on forum:

function getNearestVehicle( player ) 
    local x, y, z = getElementPosition( player ) 
    local prevDistance 
    local nearestVehicle 
    for i, v in ipairs( getElementsByType( "vehicle" ) ) do 
        local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) ) 
        if distance <= ( prevDistance or distance + 1 ) then 
            prevDistance = distance 
            nearestVehicle = v 
        end 
    end 
    return nearestVehicle or false 
end 

but it finds vehicles from every dimension. How can I make it searching nearest vehicles only from player's dimension?

Link to comment

idk if its works

function getNearestVehicle(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    local plaDim = getElementDimension(thePlayer) 
    local prevDistance 
    local nearestVehicle 
    for i , v in ipairs(getElementsByType("vehicle")) do 
        local distance = getDistanceBetweenPoints3D(x, y, z, getElementPosition(v)) 
        if plaDim == getElementDimension(v) then 
           if distance <= (prevDistance or distance + 1) then  
               prevDistance = distance 
               nearestVehicle = v 
            end 
        end 
    end 
    return nearestVehicle or false 
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...