LT.Steiner Posted September 29, 2022 Posted September 29, 2022 (edited) Hello Dear RageMP Community. I want to find Closest Vehicle distance from Player with this code: public static Vehicle GetClosestVehicle(Player player, float distance = 1000.0f) { Vehicle vehResult = new Vehicle(); foreach (var veh in NAPI.Pools.GetAllVehicles()) { Vector3 vehPos = NAPI.Entity.GetEntityPosition(veh); float distanceVehicleToPlayer = player.Position.DistanceTo(vehPos); if (distanceVehicleToPlayer < distance) { distance = distanceVehicleToPlayer; vehResult = veh; } } return vehResult; } There is an error making me mad and cannot find out and understand what's going on, should I convert NetHandle to Entity(Vehicle) ?? ERROR: CS7036 There is no argument given that corresponds to the required formal parameter 'handle' of 'Vehicle.Vehicle(NetHandle)' all of my input type from other functions are 'Vehicle' (not the NetHandle) and NAPI.Entity.GetEntityPosition(veh); want's me NetHandle type, How can I convert veh to NetHandle? I should add this too, When I'm going to change my input types to NetHandle, some errors come and say's this: CS1503 Argument 1: cannot convert from 'GTANetworkAPI.NetHandle' to 'GTANetworkAPI.Entity' I need to know How to Convert from NetHandle to Entity or Entity to NetHandle Edited September 29, 2022 by LT.Steiner
Kopra Posted October 3, 2022 Posted October 3, 2022 You can use System.Linq to simplify this check: public static Vehicle GetClosestVehicle(Player player, float distance = 15f) { return NAPI.Pools.GetAllVehicles().Where(X => X.Position.DistanceToSquared(player.Position) <= distance).OrderBy(v => v.Position.DistanceToSquared(player.Position)).FirstOrDefault(); }
LT.Steiner Posted October 4, 2022 Author Posted October 4, 2022 Hello again, Thank you @Kopra for second time, for one more time you were my solver, much much love to you ❤️ 1
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