Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to spawn a cop a ways out and make them drive to me, vs spawning at my location?

Featured Replies

I'm creating a mod that will allow you to pre-dispatch backup to a location before you arrive in case a responding unit can get there first.

I also am creating the ability to dispatch units to points as nothing more than traffic control and have them stand by until you dismiss them.

 

I understand how to spawn them at the location, but how do I spawn them a distance out and make them drive to it?

 

This is my current code:

 

  if (Game.LocalPlayer.Character.Position.DistanceTo(myPed.Position) > 50.0F && Game.LocalPlayer.Character.Position.DistanceTo(caller.Position) > 50.0F)
                {

                    int cophelps = new Random().Next(1, 5);

                    if (cophelps == 1)
                    {



                        int copFindsFirst = new Random().Next(1, 2);
                      

                        if (copFindsFirst == 2)

                        {
                            Game.DisplaySubtitle("Other Unit: I've located the subject, I'm in pursuit.", 5000);
                            Functions.AddPedToPursuit(this.pursuit, this.myPed);
                            Functions.RequestBackup(myPed.Position.Around(5f), LSPD_First_Response.EBackupResponseType.Code3, LSPD_First_Response.EBackupUnitType.LocalUnit);
                            cop1 = new Ped("S_M_Y_Sheriff_01", myPed.Position, 1f);
                            copcar1 = new Vehicle("SHERIFF", myPed.Position, 5f);
                            copcar1.IsSirenOn = true;


                        }
                        else
                        {
                            Game.DisplaySubtitle("Other Unit: I'm out with the caller.", 5000);
                            cop1 = new Ped("S_M_Y_Sheriff_01", caller.Position, 1f);
                            copcar1 = new Vehicle("SHERIFF", caller.Position, 5f);
                            copcar1.IsSirenOn = true;



                        }

                    }
                }
            }

 

Edited by download500

  • Author

The problem with that though is I need them to be on the scene behaving calmly, not with guns drawn, and I want them to stay there until I tell them to go away.

With the backup function, the only way to get them with a siren is to call them code 3, which has them go guns drawn, and they don't stay long.

 

Is there a function that will let me reference the nearest cop, or all cops within a range as a PED so that I can give them tasks/make them stand indefinitely?

What you want to do is get a random spawn point with World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(250)). You can change the 250 to however many metres you want.

Then spawn your cop car, then spawn the cop (I usually do right next to the vehicle), and warp him into the vehicle. At that point, you can call copPed.Tasks.DriveToPosition to make him drive to a Vector3 near you. You can use whatever driving flags you want, but I'd use either Normal or Emergency, and turn on the lights/siren for him if desired.

You could also get a list of peds near you and filter that for cops, but its probably easier (and more efficient) just to create the cop.

I did this with my Unknown Trouble callout, spawning a homicide detective. Let me know if you need more help.

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!

After a lot of trial and error, I found the best way to get them to stop near you is to set them to DriveToPosition of the player's ped, and use the overload that lets you specify an accepted distance. This seems to work a lot better than telling them to drive to a random position near the ped (can quite easily be a place thats not reachable). For example:

emsMedic.Tasks.DriveToPosition(target, 35, VehicleDrivingFlags.Emergency, 30f).WaitForCompletion();
 The 30f here is the acceptable range - as soon as my medic gets within this range he stops driving and the thread continues.

My YouTube Channel: Darkmyre Gaming (Australian LSPDFR patrols, plugins in development, and other games)

My Discord Server | AusGamer Network

 

Please do not PM me for technical support or bug reports, use the appropriate forum or plugin's comments instead.

1 hour ago, Darkmyre said:

After a lot of trial and error, I found the best way to get them to stop near you is to set them to DriveToPosition of the player's ped, and use the overload that lets you specify an accepted distance. This seems to work a lot better than telling them to drive to a random position near the ped (can quite easily be a place thats not reachable). For example:

 


emsMedic.Tasks.DriveToPosition(target, 35, VehicleDrivingFlags.Emergency, 30f).WaitForCompletion();

 The 30f here is the acceptable range - as soon as my medic gets within this range he stops driving and the thread continues.

Omg why have I not thought of this! I had a problem with one of my callouts and the driver of a vehicle would just run over a ped I had told it to go to.

It got so rage inducing that I just ended up leaving my computer.

5 minutes ago, tanu1215 said:

Omg why have I not thought of this! I had a problem with one of my callouts and the driver of a vehicle would just run over a ped I had told it to go to.

It got so rage inducing that I just ended up leaving my computer.

lol I feel your pain... for me it was stupid EMS ram-raiding their way through the scene of my accident callout, before treating the peds in the accident and the others they'd just run down. Amusing but so frustrating at the same time lol

My YouTube Channel: Darkmyre Gaming (Australian LSPDFR patrols, plugins in development, and other games)

My Discord Server | AusGamer Network

 

Please do not PM me for technical support or bug reports, use the appropriate forum or plugin's comments instead.

14 hours ago, Darkmyre said:

After a lot of trial and error, I found the best way to get them to stop near you is to set them to DriveToPosition of the player's ped, and use the overload that lets you specify an accepted distance. This seems to work a lot better than telling them to drive to a random position near the ped (can quite easily be a place thats not reachable). For example:

 


emsMedic.Tasks.DriveToPosition(target, 35, VehicleDrivingFlags.Emergency, 30f).WaitForCompletion();

 The 30f here is the acceptable range - as soon as my medic gets within this range he stops driving and the thread continues.

@Darkmyre wins.

I didn't even realize that DriveToPosition had that extra overload. I was picking a random spot around the player, and calling World.GetNextPositionOnStreet to ensure it wasn't an unreachable spot.

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!

  • Author

I'm using the following code, but for some reason it spawns the cop instantly on top of me, versus having him spawn 1000f feet out and drive to me. What am I doing wrong?

 

                            Game.DisplaySubtitle("David 1 en route", 5000);
                            cop1 = new Ped("S_M_Y_Sheriff_01", Game.LocalPlayer.Character.Position, 1000f);
                            v1 = new Vehicle("SHERIFF", cop1.Position, 5f);
                            cop1.WarpIntoVehicle(v1, -1);
                            v1.IsSirenOn = true;
                            v1.IsSirenSilent = true;
                            b1 = cop1.AttachBlip();
                            b1.Order = 100;
                            //b1.Color = Color.Yellow;
                            cop1.Tasks.DriveToPosition(Game.LocalPlayer.Character.Position, 35, VehicleDrivingFlags.Emergency, 30f).WaitForCompletion();
                            cop1.Tasks.LeaveVehicle(LeaveVehicleFlags.LeaveDoorOpen);
                            Game.DisplaySubtitle("David 1 arrival", 5000);

 

UPDATE: Got it working! Had to use  cop1 = new Ped("S_M_Y_Sheriff_01", World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(250)), 1000f);

1 hour ago, download500 said:

UPDATE: Got it working! Had to use  cop1 = new Ped("S_M_Y_Sheriff_01", World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(250)), 1000f);

You've got 1000 as the heading right now. Heading is 0 to 359, if I'm not mistaken, so you can just set that to 0, and put 1000f where the 250 is. Keep in mind though, the unit is metres, not feet. The 'f' on the end converts it to a float.

So 1000 metres would be 1km, or 0.62 miles. So he would spawn at any point within a 1km radius...the distance is as the crow flies, so the actual DRIVING distance on the roads would be longer. 250 meters is probably good enough.

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!

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...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.