Jump to content

Help-10 peds try to enter nearest car. If seats full in 4 seater with 4 ped, proceed to find a new car and enter.


Recommended Posts

I have 10 spawned peds. I want to make them enter nearest car. If the car holds 4 and 4 thugs have entered in its respective seat. Make the remaining peds search for new vehicle. 

 

And if a car is full drive away, BUT if 2 peds remain and they enter 4 seater, how can I make them drive away? 

Edited by kukupie
Fixed

I don't think you can because before they start to open the door, their task is to simply walk to a position where they can open the door.

 

If you have set the task sequence, then you might be able to use the task sequence progress to know where they are in the sequence. For checking the seat you can use GET_SEAT_PED_IS_TRYING_TO_ENTER but I am not sure when that returns a valid seat nunber.

 

Edit: As far as I rememeber, you can force the seat the ped will use when you set the task to enter the vehicle.

Edited by LeeC22
  • Like 2
1 minute ago, LeeC22 said:

I don't think you can because before they start to open the door, their task is to simply walk to a position where they can open the door.

 

If you have set the task sequence, then you might be able to use the task sequence progress to know where they are in the sequence. For checking the seat you can use GET_SEAT_PED_IS_TRYING_TO_ENTER but I am not sure when that returns a valid seat nunber.

I just edited my post. Think you can give me some ideas on how I can do it. The approach I talked seems too complex and so I decided to make it simpler

27 minutes ago, kukupie said:

I just edited my post. Think you can give me some ideas on how I can do it. The approach I talked seems too complex and so I decided to make it simpler

You haven't said whether the cars that are there are ones you have spawned. If not, what if the nearby cars only have two seats?

 

Assuming you have spawned compatible vehicles...

 

If you spawn all 10 peds, then you know their positions. You can either check each ped relative to a car and make the 4 closest peds enter that car. Or you can pick the first 4 peds and tell them to enter a car, then the next 4 etc... You have to group them some way, it depends on how you want to split them up.

 

You can then check to see if each ped in the respective group IsSittingInVehicle() and if so, then the car can drive away. You can even specify which vehicle they should be sitting in with an overload of that function. You could check for any seats being empty but as you say, anything less than 4 peds makes things more complicated, although you can check how many seats a car has, so the functionality is there to help.

 

But trust me, this will get complicated when a ped gets into the wrong vehicle, leaving another ped without a vehicle to enter. The game doesn't always do things exactly as you have planned it, so you have to prepare for that. You're going to need to manage them carefully, to make sure they don't get left behind. Any time you are managing ped tasks, it gets complicated unless their tasks are simple. I mean, what if the first car gets full, drives away and runs over one or more of the other peds? What if all the peds get into a vehicle and then a stray bullet kills the driver? There are the kinds of "What if?" that it helps to think about and these are the things that make simple tasks very complicated.

 

This is not the kind of thing where you could write a short snippet of code to show you how it would all work, so all I can offer is hints and tips really.

Edited by LeeC22

You can use this to check if a ped is trying to enter any vehicle:

bool tryingToEnterVeh = Function.Call<bool>(Hash.GET_IS_TASK_ACTIVE, ped, 160); //160 = EnterVehicle task

 

2 minutes ago, Jitnaught said:

You can use this to check if a ped is trying to enter any vehicle:


bool tryingToEnterVeh = Function.Call<bool>(Hash.GET_IS_TASK_ACTIVE, ped, 160); //160 = EnterVehicle task

 

Is that different to this?

bool check = myPed.IsGettingIntoAVehicle;

 

That uses the IS_PED_GETTING_INTO_A_VEHICLE native. I don't know when that returns true/false, I haven't tried it. I tested the GET_IS_TASK_ACTIVE and it returned true when they were walking to the vehicle, opening the door, and closing the door.

9 minutes ago, LeeC22 said:

You haven't said whether the cars that are there are ones you have spawned. If not, what if the nearby cars only have two seats?

 

Assuming you have spawned compatible vehicles...

 

If you spawn all 10 peds, then you know their positions. You can either check each ped relative to a car and make the 4 closest peds enter that car. Or you can pick the first 4 peds and tell them to enter a car, then the next 4 etc... You have to group them some way, it depends on how you want to split them up.

 

You can then check to see if each ped in the respective group IsSittingInVehicle() and if so, then the car can drive away. You can even specify which vehicle they should be sitting in with an overload of that function. You could check for any seats being empty but as you say, anything less than 4 peds makes things more complicated, although you can check how many seats a car has, so the functionality is there to help.

 

But trust me, this will get complicated when a ped gets into the wrong vehicle, leaving another ped without a vehicle to enter. The game doesn't always do things exactly as you have planned it, so you have to prepare for that. You're going to need to manage them carefully, to make sure they don't get left behind. Any time you are managing ped tasks, it gets complicated unless their tasks are simple. I mean, what if the first car gets full, drives away and runs over one or more of the other peds? What if all the peds get into a vehicle and then a stray bullet kills the driver? There are the kinds of "What if?" that it helps to think about and these are the things that make simple tasks very complicated.

 

This is not the kind of thing where you could write a short snippet of code to show you how it would all work, so all I can offer is hints and tips really.

For real man. It is really complex. I have been trying to get it right for over 4 days now.

2 minutes ago, Jitnaught said:

That uses the IS_PED_GETTING_INTO_A_VEHICLE native. I don't know when that returns true/false, I haven't tried it. I tested the GET_IS_TASK_ACTIVE and it returned true when they were walking to the vehicle, opening the door, and closing the door.

Oh yes, since walking to vehicle, getting in are tasks. It should be true when they are walking to the car! This should help alot

19 minutes ago, Jitnaught said:

That uses the IS_PED_GETTING_INTO_A_VEHICLE native. I don't know when that returns true/false, I haven't tried it. I tested the GET_IS_TASK_ACTIVE and it returned true when they were walking to the vehicle, opening the door, and closing the door.

It's just my OnFoot cam mod uses the one I posted but if what you have posted let's me know that info earlier, that could be very useful. I'll have to check when the camera switches in my mod to be sure.

 

Edit: IsGettingIntoVehicle() switches the camera just before the animation starts playing for the player to open the door, about a second or so before. So that's probably when the animation position and rotation have been returned from the GET_ANIM_INITIAL_OFFSET_POSITION and GET_ANIM_INITIAL_OFFSET_ROTATION natives.

 

I'll replace that check in the mod with that task call and see what happens. I'll post back with any results.

 

Edit: That TASK reports True the minute you start to walk towards the vehicle, so that's way sooner than the call I have been using, thank you for that.

Edited by LeeC22
  • Like 2

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.