Jump to content

DisplayNotification Loop - Distanceto2D (PlayAudio)


CableDog19

Recommended Posts

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
Link to comment
Share on other sites

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();
                }
            }

Link to comment
Share on other sites

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;
  }
}

 

Link to comment
Share on other sites

  • Management Team

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

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Link to comment
Share on other sites

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