Bananovy Posted September 23, 2015 Share Posted September 23, 2015 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
Dimos7 Posted September 23, 2015 Share Posted September 23, 2015 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
Bananovy Posted September 23, 2015 Author Share Posted September 23, 2015 Looks like it works! Thank you very much! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now