Jump to content

Detecting vehicles?


goigle

Recommended Posts

Hi, so I basically need a way to find a vehicle near a ped. I know there are a few plugins that do things similar to this but I can't for the life of me find anything about it in the rage documentation (except for maybe doing a whole circle of raycasts - does not seem performance friendly though).

If the correct solution is to do raycasts, how I go about sending one? In the documentation I only see a hit result - nothing about sending the actual raycast out.

Link to comment
Share on other sites

List<Entity> entities = World.GetEntities(myPed.Position, 10f, GetEntitiesFlags.ConsiderAllVehicles).ToList();
List<Vehicle> vehList = (from x in entities where x.Exists() && x.IsVehicle() select (Vehicle)x).ToList();
vehList = (from x in vehList where x.IsPlayersVehicle() == false select x).ToList();

That will get you a list of vehicles within 10 meters of the ped. If you want the nearest vehicle, you could do:

Vehicle v = (from x in vehList where x.IsPlayersVehicle() == false orderby x.Position.DistanceTo(myPed.Position) select x).FirstOrDefault();

That would sort the list by distance to the ped, and then get the first Vehicle in the list, or if the list is empty (no vehicles found), it would return null.

Is that what you're looking for?

EDIT: Damn it, I forgot that Entity.IsVehicle() and Vehicle.IsPlayersVehicle() are extension methods that I wrote.

They are relatively simple to implement though. IsVehicle() is just calls a native called IS_ENTITY_A_VEHICLE or something like that. IsPlayersVehicle just checks if the vehicle is the player's CurrentVehicle or LastVehicle. (With null checks and .Exists() checks in between, of course lol)

Edited by Stealth22

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

Yes, I can take it from there! Exactly what I am looking for, thanks for the help again!

No worries, glad I could help! :thumbsup:

Let me know if you have any more questions. Looking at the code again, you may want to change the flag to, ConsiderGroundVehicles, I think it's called. Not that there's going to be an aircraft or boat near your ped, but if you're OCD about it like me....lol

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

No worries, glad I could help! :thumbsup:

Let me know if you have any more questions. Looking at the code again, you may want to change the flag to, ConsiderGroundVehicles, I think it's called. Not that there's going to be an aircraft or boat near your ped, but if you're OCD about it like me....lol

Just to add to the code you posted before in RPH there is Model.IsVehicle so you don't need the extension method. Also there is Model.IsCar, Model.IsBike, etc. You will use it like this Entity.Model.IsVehicle

Hope this helps:smile:

Link to comment
Share on other sites

Just to add to the code you posted before in RPH there is Model.IsVehicle so you don't need the extension method. Also there is Model.IsCar, Model.IsBike, etc. You will use it like this Entity.Model.IsVehicle

Hope this helps:smile:

Right, I forgot RPH implemented those. I wrote those extension methods before those properties were brought in, so I've just kept them in there, lol.

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

What about Stealth's code limits the selection to just vehicles in front of or behind the ped?

And great link, thanks!

Yeah, I forgot RPH had that GetNearbyVehicles function. Its limited to 16 vehicles I think, but for your purposes, it will work just fine. Unless you want more than that. My code does the same thing basically, except theres no limit to the number of vehicles.

If you want to find vehicles in front/behind the ped, you'll need to do some comparisons with the vehicle's position.

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...