Jump to content

Issue Creating More Than 1 Ped Discussions


CableDog19

Recommended Posts

Hello Everyone,

 

I've been working on a callout pack for a few weeks now. I'm new to the c# language like most people who start are lol. I've read through all the multiple forums on Ped/Player text interaction. I've seen the Array style, EcalloutState, and basic <string>. No matter what way I try to code this, I can only get 1 dialog to display. The other dialog code will not show up. I know I'm missing a line of code to separate them from being called at the same time in the public override void Process(). I've been working on different processes for the last three days with no success as to resolving this issue. This is what I have.

 

*I HAVE NOT SET PRIVATE INT DIALOGWITH...INDEX; YET. JUST GOING STEP BY STEP AND TESTING AS I GO IF THIS EFFECTS IT, PLEASE LET ME KNOW*

Spoiler

public class Trespassing : Callout
    {
        private Ped Suspect;
        private Ped Witness;
        private Vector3 SusSpawn;
        private Vector3 WitSpawn;
        private Blip Sus;
        private Blip Wit;
        private readonly List<string> dialogWithWitness = new List<string>()
{
  ((DIALOG))
};
        private int dialogWithWitnessIndex;

        private readonly List<string> dialogWithSuspect = new List<string>()
{
      ((DIALOG))
};
        private int dialogWithSuspectIndex;

 

Spoiler

        public override void Process()
        {
            if (Game.LocalPlayer.Character.DistanceTo2D(Witness) <= 3)
            {
                Game.DisplayHelp("Press ~g~y~w~, to speak with ~y~Witness");

                if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y)) return;

                if (dialogWithWitnessIndex < dialogWithWitness.Count)
                {
                    Game.DisplaySubtitle(dialogWithWitness[dialogWithWitnessIndex]);
                    dialogWithWitnessIndex++;
                }
                if (Game.LocalPlayer.Character.DistanceTo2D(Suspect) <= 3)
                {
                    Game.DisplayHelp("Press ~g~y~w~, to speak with ~r~Suspect");
                    {
                        if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y))

                            if (dialogWithSuspectIndex < dialogWithSuspect.Count)
                            {
                                Game.DisplaySubtitle(dialogWithSuspect[dialogWithSuspectIndex]);
                                dialogWithSuspectIndex++;
                            }
                    }
                }
            }
        }

 

 

Link to comment
Share on other sites

You may separate the dialog with witness and suspect/



        public override void Process()
        {
            if (Game.LocalPlayer.Character.DistanceTo2D(Witness) <= 3)
            {
                Game.DisplayHelp("Press ~g~y~w~, to speak with ~y~Witness");
                if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y)) return;
                if (dialogWithWitnessIndex < dialogWithWitness.Count)
                {
                    Game.DisplaySubtitle(dialogWithWitness[dialogWithWitnessIndex]);
                    dialogWithWitnessIndex++;
                }
            }
            else if (Game.LocalPlayer.Character.DistanceTo2D(Suspect) <= 3)
            {
                Game.DisplayHelp("Press ~g~y~w~, to speak with ~r~Suspect");
                if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y))
                    if (dialogWithSuspectIndex < dialogWithSuspect.Count)
                    {
                        Game.DisplaySubtitle(dialogWithSuspect[dialogWithSuspectIndex]);
                        dialogWithSuspectIndex++;
                    }
                }
            }
        }

 

Link to comment
Share on other sites

I tried this too but it doesn't work. I can walk up to the (Witness) Full Dialog interaction. Then walk up to the Suspect and hit Y with nothing. 

The Witness and Suspect are on opposite sides of a building. They're about 10f apart if that. I dont think its because of the .DistanceTo2D() <=3. I have tried reducing to <=1 with still no change as well. 

Link to comment
Share on other sites

You need to add 

base.Process();

Inside the process method as well.

 

Additionally make use of logging, or displaying variables in game using subtitles etc. That way you can see if your code is actually reaching where you expect it to.

Live Streaming daily from 8pm GMT (UK) at https://twitch.tv/OfficialLukeD - I play a variety of things 😄

Join my official discord server for support, general chat and my stream schedule! https://discord.gg/Mddj7PQ

Link to comment
Share on other sites

Thank You, 

 

I had stripped it down to the minimum to try and get the dialog to work so many times that I had deleted the base.Process().

I tried what you mentioned and what was mentioned above but now I just get the last line of Dialog for the Suspect.

 

Am I able to create a

 

private void Dialog()

base.Process() 

 

before the public override void Process()

 

to separate the code or is it not efficient?

will it still work the way I would like it too?

 

I have posted the new code below so that you can spot why the suspect dialog only shows the last line.

 

*New Code* *public class* still the same from previous post

 

Spoiler

 public override void Process()
        {
            base.Process();
            if (Suspect.IsValid())
            {
                if (Functions.IsPedGettingArrested(Suspect) || Functions.IsPedArrested(Suspect) || Functions.IsPlayerArresting() || Functions.IsPedStoppedByPlayer(Suspect))
                {
                    Suspect.Tasks.Clear();
                    End();
                }
            }
            {
                if (Game.IsKeyDown(System.Windows.Forms.Keys.End))
                {     // When User presses "END" key, the callout will forcefully end. Remember to delete your Blips!
                    End();
                    Game.DisplayNotification("~g~Call is Code 4~w~");
                    LSPD_First_Response.Mod.API.Functions.PlayScannerAudio("WE_ARE_CODE_4");
                }
            }
            {
                base.Process();
                if (Witness.IsValid())
                {
                    if (Game.LocalPlayer.Character.DistanceTo2D(Witness) <= 3)
                    {
                        Game.DisplayHelp("Press ~g~y~w~, to speak with ~y~Witness");
                        if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y)) return;
                        if (dialogWithWitnessIndex < dialogWithWitness.Count)
                        {
                            Game.DisplaySubtitle(dialogWithWitness[dialogWithWitnessIndex]);
                            dialogWithWitnessIndex++;
                        }
                    }
                {
                    base.Process();
                    if (Suspect.IsValid())
                    {
                        if (Game.LocalPlayer.Character.DistanceTo2D(Suspect) <= 3)
                        {
                            Game.DisplayHelp("Press ~g~y~w~, to speak with ~r~Suspect");
                            if (!Game.IsKeyDown(System.Windows.Forms.Keys.Y))
                                if (dialogWithSuspectIndex < dialogWithSuspect.Count)
                                {
                                    Game.DisplaySubtitle(dialogWithSuspect[dialogWithSuspectIndex]);
                                    dialogWithSuspectIndex++;
                             }
                        }
                    }
                }
            }
        }

 

 

Link to comment
Share on other sites

Your formatting is off, as you have brackets surrounding if statements that are not needed. If you are not using an IDE I suggest using one, such as Visual Studio Community Edition or JetBrains Rider.

 

You only need to call base.Process() once at the start of the Process() method.

 

You're only getting the last line of dialogue because what you're trying to do is display each line in an array. This is fine but you're not giving each line time to display, so you tell it to display a subtitle and then increment the counter and then at the speed the code executes its being told to display the next line. This behaviour will override the previous subtitle until it gets to the last line which doesn't have another line after it to override it, therefore it is allowed the time to display it.

Try adding GameFiber.Sleep(2000); after the dialogWithSuspectIndex++; (same with witness).

 

This will mean the thread will stop processing for 2 seconds before allowing it to loop round again., you'll see each line in the text be displayed then.

Live Streaming daily from 8pm GMT (UK) at https://twitch.tv/OfficialLukeD - I play a variety of things 😄

Join my official discord server for support, general chat and my stream schedule! https://discord.gg/Mddj7PQ

Link to comment
Share on other sites

Thank You,

 

I believe I have it figured out. I was able to talk with the suspect. Only problem I was having is the DisplayNotification"Press Y to Talk with Suspect" not displaying when near.  I'll fix that soon. I appreciate the help. This has been a good learning experience. All the callouts are location based, each with different variations of how the callout can go. Super excited about this project. Hopefully should be done by the end of April. Planning on having 15 callouts, 5 of which are completed. Worst case scenario, release as a WIP.   🙂

Edited by CableDog19
Link to comment
Share on other sites

I look forward to seeing what you've come up with and I'm glad you've learnt a lot from your project. Don't hesitate to pop into this forum section in the future if you need us 🙂

Live Streaming daily from 8pm GMT (UK) at https://twitch.tv/OfficialLukeD - I play a variety of things 😄

Join my official discord server for support, general chat and my stream schedule! https://discord.gg/Mddj7PQ

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