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.

If (any of the peds I spawned) are within 50f of player then have (ped) do this

Featured Replies

So depending on which option I choose, I could have any one of 8 cop ped objects dispatch to my location.

Regardless of which one I call, I want them to all have the same trigger once they get within a certain distance of me.

 

So basically I want to do something like

if Game.LocalPlayer.Character.Position.DistanceTo(((any one of my spawned cop peds).Position) <= 20.0F)

 

{

(That cops vehicle).IsSirenSilent = true;

}

I know I could do 8 different If/Then statements with one for each cop, but I figured there was an easier way.

How could I make this work?

Edited by download500

List<Ped> MyCops = new List<Ped>();

MyCops.Add(cop1);
MyCops.Add(cop2); //etc

foreach (Ped cop in MyCops) {

if Game.LocalPlayer.Character.Position.DistanceTo(((any one of my spawned cop peds).Position) <= 20.0F) {

//yourcode

}}

My YouTube: Click here. 

My Discord Server - https://discord.gg/0taiZvBSiw5qGAXU

Useful post? Let me and others know by clicking the Like button.
Check out my many script modifications! 
Having issues? LSPDFR Troubleshooter by Albo1125.

22 minutes ago, Albo1125 said:

List<Ped> MyCops = new List<Ped>();

MyCops.Add(cop1);
MyCops.Add(cop2); //etc

foreach (Ped cop in MyCops) {

if Game.LocalPlayer.Character.Position.DistanceTo(((any one of my spawned cop peds).Position) <= 20.0F) {

//yourcode

}}

You could also use a LINQ query, if you wanted to do some action on ALL cops if any one of them are within 20 metres.

int nearbyCops = (from x in myCops where x.DistanceTo(Game.LocalPlayer.Character.Position) <= 20.0f select x).Count();

if (nearbyCops > 0)
{
  foreach (Ped cop in myCops)
  {
    //do something
  }
}

//You can also get a list of nearby cops and only do an action on those nearby cops...

List<Ped> nearbyCopList = (from x in myCops where x.DistanceTo(Game.LocalPlayer.Character.Position) <= 20.0f select x).ToList();

if (nearbyCopList.Count > 0)
{
  foreach (Ped cop in nearbyCopList)
  {
    //do something
  }
}


//Or get the closest cop...

Ped closestCop = (from x in myCops where x.DistanceTo(Game.LocalPlayer.Character.Position) <= 20.0f select x).FirstOrDefault();
// if closestCop is null, no cop within 20 meters was found

//Or a list of cops sorted by how close they are...

List<Ped> nearbyCopList = (from x in myCops where x.DistanceTo(Game.LocalPlayer.Character.Position) <= 20.0f orderby x.DistanceTo(Game.LocalPlayer.Character.Position) select x).ToList();

 

Edited by Stealth22

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

This is more of a general C# question as I ran into this issue as well in VB NET (I do office programming at work).

 

Can you create objects dynamically, that is, create a cop object every time a button is pressed and have it be a new cop object that gets added to the list you made above?

 

Or do I have to declare a finite number of cops in advance as Peds, and then once it has assigned the last cop ped I'm out?

 

In other words if I made 10 cop objects at the begging of my script, am I limited to spawning 10 cops from my button press?

Edited by download500

32 minutes ago, download500 said:

This is more of a general C# question as I ran into this issue as well in VB NET (I do office programming at work).

 

Can you create objects dynamically, that is, create a cop object every time a button is pressed and have it be a new cop object that gets added to the list you made above?

 

Or do I have to declare a finite number of cops in advance as Peds, and then once it has assigned the last cop ped I'm out?

 

In other words if I made 10 cop objects at the begging of my script, am I limited to spawning 10 cops from my button press?

Nope, you can make them on the fly. As long as your list is globally declared, you're good.

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

Hey stealth, the for each worked great than you. I used it for crowd control in one of my callouts where once you give an order to the group, each ped has a random individual chance to either obey and leave or taunt/fight you.

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.