[Coding] Check if character vehicle is for exemple a bullet
-
Hello,
im sorry if this post in in the wrong section so pls move it when its wrong.
My question is: how i can check that the character car is a specific vehicle for exemple a bullet?Exemple c#:
if(Game.Player.Character.CurrentVehicle == Vehicle hash for exemple bullet)
{
//code
}
-
@CodeMunk Have you checked the native database, for example:
GET_VEHICLE_PED_IS_IN(Ped ped, BOOL includeLastVehicle)
Not sure what it returns, but probably the hash.
https://gist.github.com/QuynhVir/f2f28fcc921d4f207280534f9326d7cf#file-gistfile1-txt
-
@JohnFromGWN Yes i didi but i don`t know how to use it ^^
-
@CodeMunk What I don't understand is how you will use this. More importantly you will need to look at some tutorials on how to script for GTA V even if you are experienced with C#. You will need to learn how to spawn vehicles and peds and then you can write whatever logic you want to add to that. Again, I really don't understand why you would want to know if a ped is in a given vehicle when there are hundreds of possibilities - i.e. the probability is near nill. Also, your example refers to the player - and as the player you know exactly what vehicle you are in - unless you teleport randomly into a vehicle for example. You're French I assume?
-
@JohnFromGWN You dont need to understand. I know how to spawn vehicles and peds but i want to know that for exemple a car seller. That i can check ok the ped is sitting in a adder so when i want to sell it i get the amount of money.
-
@CodeMunk If you know how to script peds and vehicles spawns, then again I will refer you to the natives database. Search through it. With respect to examples, you will need to do google searches because documentation is hard to find. You are pretty much on your own here with a the exception of a few experts (i'm not one of them) who pop in from time to time.
From your reply, i do think
GET_VEHICLE_PED_IS_IN
is the right function. If you know how to spawn the vehicle by a script, why can't you use the native function?Try this one:
PED::IS_PED_IN_VEHICLE BOOL IS_PED_IN_VEHICLE(Ped ped, Vehicle vehicle, BOOL atGetIn) // 0xA3EE4A07279BB9DB 0x7DA6BC83 b323
Gets a value indicating whether the specified ped is in the specified vehicle.
If 'atGetIn' is false, the function will not return true until the ped is sitting in the vehicle and is about to close the door. If it's true, the function returns true the moment the ped starts to get onto the seat (after opening the door). Eg. if false, and the ped is getting into a submersible, the function will not return true until the ped has descended down into the submersible and gotten into the seat, while if it's true, it'll return true the moment the hatch has been opened and the ped is about to descend into the submersible.
or this one might be better
BOOL IS_PED_SITTING_IN_VEHICLE(Ped ped, Vehicle vehicle)
https://alloc8or.re/gta5/nativedb/
with respect on how to use, again, you will need to google tutorials. I'm really new to this. I would do it like this though:
Function.Call(Hash.GET_VEHICLE_PED_IS_IN, MyPedName, true);
ofc this assumes you spawned ped and vehicle through a script.
-
@JohnFromGWN Here is another excellent resource with code examples. Go through entities and you will find code for peds, vehicles, etc.
https://github.com/crosire/scripthookvdotnet/tree/main/source/scripting_v2/GTA