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.

DisplayNotification Loop - Distanceto2D (PlayAudio)

Featured Replies

The Callout Pack I'm working on has aspects that create realism and I've added a DisplayNotification which has caused a loop issue. I was reading past forums but did not find code that would fix this particular issue. I was reading that executing a ex. if (Game.LocalPlayer.Character.Distanceto2D(Suspect) < 30) is not the best method for a Function.PlayScannerAudio or DisplayNotification and creates a loop. I've tried GameFiber.Yield(), GameFiber.Sleep(100000), GameFiber.( delegate. All have not solved this issue. I figure it is just because the Distanceto is causing the looping issue. Is there a proper method to either sleep the process without sleeping the Main or do I have to figure out another way to get it to display once? Thanks!

 

(Code Below)

 

Spoiler

public override void Process()
        {
            base.Process();
            GameFiber.Yield();

            if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) < 5f)
            {
                triggerDialogAction();
            }

            if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) < 30f)
            {
                triggerDispatch();
            }
            if (Game.LocalPlayer.Character.DistanceTo2D(Suspect) <= 2)
            {
                calloutStatus = CalloutState.arrivedOnScene;
                if (SuspectBlip.IsValid()) { SuspectBlip.Delete(); }
            }
            if (Suspect.IsCuffed)
                if (Functions.IsPedBeingCuffedByPlayer(Suspect))
                    if (Functions.IsPedGettingArrested(Suspect))
                    {
                        Game.DisplayNotification("~b~DISPATCH~w~, I HAVE 1 10-15, CODE 4 AT THIS TIME");
                        Functions.PlayScannerAudio("10_4 SUSPECT_IS_10_15 NO_ADDITIONAL_OFFICERS_NEEDED");
                        Suspect.Tasks.ClearImmediately();
                    }
            if (Suspect.IsDead)
                if (Game.LocalPlayer.Character)
                {
                    End();
                }
          }
        private void triggerDialogAction()
        {
            if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) < 5f)
            {
                if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y)) return;
                if (dialogWithSuspectIndex < dialogWithSuspect.Count)
                {
                    Game.DisplaySubtitle(dialogWithSuspect[dialogWithSuspectIndex]);
                    dialogWithSuspectIndex++;
                }
                else
                {
                    Game.DisplayHelp("Press ~g~Y~w~, to speak with ~y~Suspect");
                    GameFiber.Wait(3000);
                    Game.HideHelp();
                }
            }
        }

        private void triggerDispatch()
        {
            if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) < 30f)
            {
                Game.DisplayNotification("~b~DISPATCH~w~, I'LL BE OUT WITH 1, 10-23 ON SCENE ");
                Functions.PlayScannerAudio("10_4 OFFICERS_ARRIVED_ON_SCENE");
            }
        }

 

Edited by CableDog19

  • Author

Nevermind, Solved this issue after trying different options. This may not be the best method but it works for now. If anyone could recommend a better method. Please let me know.

 

private void triggerDispatch()
        {
            if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) < 30f)
               if (Suspect.DistanceTo(Game.LocalPlayer.Character.Position) > 29f)
                    {
                    Game.DisplayNotification("~b~DISPATCH~w~, 10-23 ON SCENE, I'LL BE OUT WITH 1");
                    Functions.PlayScannerAudio("10_4 OFFICERS_ARRIVED_ON_SCENE");
                    GameFiber.Yield();
                }
            }

I always make a bool first and set it as false. Then I check if it is false and I set it to true in the if statement so it doesn't repeat, it works pretty okay for me.

bool notificationDisplayed = false; // do this at the beginning (in your class, not in any method)
public override void Process()
{
  if(condition && !notificationDisplayed) {
    //do your thing
    notificatioDisplayed = true;
  }
}

 

2 minutes ago, LMS said:

FYI bools declared on a class level are false by default, so no need to explicitly set it. 

Yes, I know, but I always like to set them first, it's just my preference.

 

Edited by Xonyne88

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.