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.

Detecting the Player has initiated a Traffic Stop?

Featured Replies

Hey Experts of the LSPDFR API,

 

What do you all think is the best method for detecting whether the player has initiated a traffic stop?

I want to run some code every time the user pulls someone over.

I'm familiar with adding callouts, but wasn't too sure what the best method for this was.

 

Help is greatly appreciated. Cheers!

  • Author

Some Context:

 

To clarify, I'm able to do what I've described above, I've just been using a while(true) loop in the Main.cs file (iniated by "if (OnDuty)") to constantly check if the player is in a traffic stop, however I wasn't sure if I was doing it in an inefficient way, and perhaps there was a better way?

 

Code attached below for context:

 

		private static void OnOnDutyStateChangedHandler(bool OnDuty)
        {
            if (OnDuty)
            {
                PulloverCheck();     
            }
        }

        private static void PulloverCheck()
        {
            GameFiber.StartNew(delegate
            {

            while (true)
            {
                GameFiber.Yield();
                while (true)
                {
                    GameFiber.Yield();
                    if (Functions.IsPlayerPerformingPullover() && pulloverCheck == false)
                    {
                        Game.DisplayNotification("Pullover Detected");
                        pullover = Functions.GetCurrentPullover();
                        PulloverPed = Functions.GetPulloverSuspect(pullover);                                             
                        GameFiber.Wait(10000);
                        PulloverPed.PlayAmbientSpeech(null, "GENERIC_THANKS", 0, SpeechModifier.Force);
                        break;
                        }
                    }
                    Game.DisplayNotification("1");
                    pulloverCheck = true;
                    Game.DisplayNotification(Boolean.TrueString);

                    GameFiber.Yield();
              
                    while (true)
                    {
                        GameFiber.Yield();
                        if (!Functions.IsPlayerPerformingPullover() && pulloverCheck == true)
                        {
                            pulloverCheck = false;
                            break;
                        }
                    }

                }
                GameFiber.Hibernate();

            });
        }

 

Also curious if I'm using GameFiber.Yield correctly - not entirely sure if I need it as many times as I have it.

Cheers again!

  • Author
10 minutes ago, ToastinYou said:

Never put a loop within a loop..

Especially not a loop within a loop within a loop lol.

 

Yes, I had noticed that since I last posted and have removed - cheers for the reminder!

I would use an event, and invoke it whenever you register a pullover. Then, use a method that includes your code you want to run. Lastly, add your method to your event.

 

Look up events.

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.