Create car with ped driver and let player enter the car in the backseat?
-
Here's what I've done so far:
if (e.KeyCode == Keys.NumPad7) { theVehicle = World.CreateVehicle(new Model(VehicleHash.Police), Game.Player.Character.Position.Around(7)); driverPed = Function.Call<Ped>(Hash.CREATE_RANDOM_PED_AS_DRIVER, theVehicle); driverPed.CanBeDraggedOutOfVehicle = false; } if (e.KeyCode == Keys.L) { Vector3 _waypoint = new Vector3(); if (Game.IsWaypointActive) { _waypoint = World.GetWaypointPosition(); } driverPed.Task.DriveTo(theVehicle, _waypoint, 10, 25); }
So far this works. The ped will drive to the waypoint whenever I press L. But the problem is I can't ride on the car with him. If I delete the "canbedragged" part - when I press F, the player just drags the driver away from the car. I want it that when the player presses F near the car, he will go to the backseat (or front right etc.) and just chill there. So I can press L and the ped driver will just drive me to the waypoint. Any ideas? Thanks!
-
@nightmareexe This is easy to do. I'll post working code.
-
This might not be exactly what you want, but hopefully this will get you started.
Option 1 - Passenger, no specific location, any ped
In the first option, you walk up to any car being driven by a ped and hit a key binding. You now enter car as passenger or backseat and ped will AI drive you while you chill. No destination.Vector3 PlayerPosition = Game.Player.Character.GetOffsetPosition(new Vector3(0.0f, 10f, 0.0f)); Ped ClosestPed = World.GetClosestPed(PlayerPosition, 15.0f); if (ClosestPed.Exists() && ClosestPed != Game.Player.Character) { Vehicle LastVehicle = Function.Call<Vehicle>(Hash.GET_VEHICLE_PED_IS_IN, ClosestPed, true); Game.Player.Character.Task.EnterVehicle(LastVehicle, VehicleSeat.Passenger, -1, 0.0F, 0); ; }
Option 2 - Passenger, with specific location, specific ped
In this second option, you need to spawn a ped, called CurrentPed in example. You can modify code to use ambient ped.
Secondly, as the player, you enter and exit any car to make it LastVehicle.private void PedDrivesYou(object sender, EventArgs e) { // 1.Spawn any car and enter it so it becomes LastVehicle, exit car. Go Vehicle LastVehicle = Function.Call<Vehicle>(Hash.GET_VEHICLE_PED_IS_IN, Game.Player.Character, true); //not the same as currentvehicle when player isn't in car. Game.Player.Character.Task.EnterVehicle(LastVehicle, VehicleSeat.Passenger, -1, 0.0F, 0); Wait(3000); CurrentPed.Task.EnterVehicle(LastVehicle, VehicleSeat.Driver, -1, 0.0F, 0); CurrentPed.Task.DriveTo(LastVehicle, new Vector3(-1278, -3099, 14), 3.0F, 45, DrivingStyle.Rushed); }
-
@JohnFromGWN Hey man thank you so much! Just one inquiry. How do I make the ped and vehicle spawn near the current street as to my player? When I spawn them, they seem to spawn somewhere near but sometimes on overpasses, and they need to go around the map for quite a bit just to get to me. You have to wait for some time (depending on their spawned location). Is there any way to spawn them like 2 blocks away from my street or something? Here's my code:
Vector3 _posSpawn = World.GetNextPositionOnStreet(Game.Player.Character.Position.Around(100));
Thank you so much man!
-
@nightmareexe
OMG. There must be hundreds of different ways to spawn peds and cars. You can even spawn a ped in the car.
You can do it with absolute coordinates or relative coordinates.For peds, I generally use this (you can replace Game.Player and Game.Player.Character with variables, just wanted to make it clear):
Ped AdaA = World.CreatePed("AdacasualA", Game.Player.Character.Position + Game.Player.Character.ForwardVector * 3.0f, Game.Player.Character.Heading + 90);
For cars, I use something like this:
Vehicle Vehicle2 = World.CreateVehicle("308gts", Game.Player.Character.GetOffsetPosition(new Vector3(-1, -3, 0))); Vehicle2.Heading = 90;
or off the Ped above:
Vehicle Vehicle1 = World.CreateVehicle("cobra", AdaA.GetOffsetPosition(new Vector3(1, 2, 0))); Vehicle1.Heading = 90;
an absolute spawn could look like this:
Vehicle vehicle1 = World.CreateVehicle("cobra", new Vector3(9314.51f, -6737.61f, 749.73f), 2f);
But again, there are so many possibilities including using variables for the model name and also for the location.
-
@JohnFromGWN said in Create car with ped driver and let player enter the car in the backseat?:
Game.Player.Character.GetOffsetPosition(new Vector3(-1, -3, 0)
Thanks man! I'm currently using:
driverPed = World.CreatePed(new Model(PedHash.FbiSuit01), World.GetNextPositionOnStreet(Game.Player.Character.Position.Around(100)));
Is there any way I could spawn him on the same street as mine but not necessarily "that" near to me? Like probably a couple of blocks. And also, mind I ask what is the
heading
used for? LikeGame.Player.Character.Heading
etc? Thank you so much man! Sorry if I sound so naïve, I just started modding last week
-
heading is the direction player will be facing when spawned.
To adjust the distance you simply play with the parameters
Game.Player.Character.ForwardVector * 2.0f
//close
Game.Player.Character.ForwardVector * 4.0f
//further
Game.Player.Character.ForwardVector * 6.0f
//even furtherGame.Player.Character.GetOffsetPosition(new Vector3(-1, 0, 0)));
//very closeGame.Player.Character.GetOffsetPosition(new Vector3(-3, 0, 0)));
//furtherGame.Player.Character.GetOffsetPosition(new Vector3(-6, 0, 0)));
// even furthercheck this out:
https://alloc8or.re/gta5/nativedb/
-
@JohnFromGWN Thank you so much! This really helped me a lot!