Jump to content
Sign in to follow this  

Jack random car if on foot

Recommended Posts

Currently I am using the following code to attempt to force my ped to get into the closest vehicle when they are on foot:

            foreach(Vehicle v in World.GetAllVehicles());

                if (myPed.IsOnFoot)
                    myPed.Tasks.EnterVehicle(v, -1);

So far the ped reenters the starting vehicle, immediately get out of the starting vehicle and then runs away, never again attempting to steal other vehicles.

What I want the ped to try and do is steal any nearby vehicle if they are on foot. Can anybody help me out here?

Share this post

Link to post
Share on other sites

The code you have given is not complete enough to assess your problem.

I suggest adding a .WaitCompletion() after the task, like so:

myPed.Tasks.EnterVehicle(v, 10000, -1).WaitForCompletion(); 

This will wait till the task finishes and times it out after 10secs.

Share this post

Link to post
Share on other sites

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
Sign in to follow this