Jump to content

Detecting the Player has initiated a Traffic Stop?


RedJackal

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...