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.

How do you code conversations with suspects/victims?

Featured Replies

Hello,

I'm fairly new to C# however, I do consider myself fairly competent with the basic C#, RAGE and the LSPDFR API. I have run into a problem with trying to figure out how to code conversations in game. (By this I mean the ones that show up as subtitles and you click 'y' to cycle through them.) In the past I have just let them cycle through with out the user clicking 'y' to advance in the conversation.

 

Like this... 

Spoiler

 if (!IsSpeechFinished && Game.LocalPlayer.Character.DistanceTo(Suspect.Position) < 8f)
                    {
                        Game.DisplayNotification("~w~ Press ~y~Y~w~ to talk to the ~o~suspect");


                        while (!Game.IsKeyDown(System.Windows.Forms.Keys.Y))
                            GameFiber.Yield();

 

                        Suspect.Tasks.Clear();
                        Suspect.Tasks.StandStill(30000);


                        Game.DisplaySubtitle("~b~You~w~: Excuse me, would you mind talking for a minute?", 4000);
                        GameFiber.Wait(4500);
                        Game.DisplaySubtitle("~o~Suspect~w~: Well well well... How the turn tables.", 3500);
                        GameFiber.Wait(4000);
                        Game.DisplaySubtitle("~b~You~w~: Sorry, what do you mean?", 4000);
                        GameFiber.Wait(4500);
                        Game.DisplaySubtitle("~o~Suspect~w~: I don't want to name fingers and point names, but...", 3500);
                        GameFiber.Wait(4000);
                        Game.DisplaySubtitle("~o~Suspect~w~: some of your PIG friends didn't come help me when I needed a lift to the bar a few hours ago! ", 3500);
                        GameFiber.Wait(4000);
                        IsSpeechFinished = true;
                        GameFiber.Hibernate();

                    }

 

However, I want to give the user more control by only advancing to the next part of the conversation when they press a certain key. 

 

I have browsed through this forum and came across an old thread called "Getting key press multiple times" by @tanu1215I didn't understand the way @Stealth22 said he did it in that thread. This is because I am not too knowledgeable with lists. 

 

So my question is how do you code conversations? Also, if you feel like it, I would really appreciate it if you could provide some examples or pseudo code to help me understand. Also if you have any other advice I would greatly appreciate it.

 

Thank-you for your time.

Edited by Jinja

     enum ConversationTypes { HandsUp, Donut }
     ConversationTypes Current = ConversationTypes.None;
     List<String>.Enumerator CurrentDialog;

     Dictionary<ConversationTypes, List<String>> DialogMessages = new Dictionary<ConversationTypes, List<string>>()
        {
            { ConversationTypes.HandsUp, new List<string>()
            {
                "how your doinng",
                "Very well oficer"
            }
        },
            { ConversationTypes.Donut, new List<string>()
            {
                "mmm a donut!"
            }
            }

 

Current = ConversationTypes.Donut;
CurrentDialog = DialogMessages[Current].GetEnumerator();
 
 
if Game.LocalPlayer.Character.Position.DistanceTo(Call) <= 60f)
            {
                if (Game.IsKeyDown(Settings.TalkKey)) //This is in a ini file
                {
                    if (CurrentDialog.MoveNext())
                    {
                        Game.DisplaySubtitle(CurrentDialog.Current, 7500);
                    }
                }
            }

https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx

 

Does this help? of you have any more problems feel free to tell them.

 

 

Edited by epicmrjuan

Thank you

I do something kind of different for conversations, I don't use a dictionary, I use a loop. It looks something like this

string[] talkArray = 
{
"Aggressor: I shot him!",
"Victim: He shot me!"
}

for (i = 0; i < talkArray.Length; i++)
{
  while (!Game.IsKeyDown(Keys.Y)) GameFiber.Yield();
  
  Game.DisplaySubtitle(talkArray[i]);
  GameFiber.Sleep(1000); //You don't need the sleep I just like to have it in my code so the person reads the entire text
}

That really should give you the same effect but you could choose either way.

//Set the strings to display as conversations and such.
private readonly string[] _conversationLines = 
{
	"Blurb1.",
	"Blurb2.",
	"Blurb3."
};

//Set our shit.
private int _currentConversationLine, _conversationLineMax;
private Ped _myPed1;
private Ped Player = Game.LocalPlayer.Character;

//Set our _currentConversationLine to 0, as arrays start at 0, not 1.
_currentConversationLine = 0;

//Get our max value from our string array so we don't go out of index (max).
_conversationLineMax = _currentConversationLines.Length;

//(put this in a loop) Check if player is at least 5 [cm?] away from _myPed1 and on foot and make sure that we aren't at the end of the string array and see if our ini files talk key is down.
if (Player.Position.DistanceTo2D(_myPed1.Position) <= 5f && Player.IsOnFoot && _conversationLine != _conversationLineMax && (Game.IsKeyDownRightNow(Settings.TalkKeyModifier) || Settings.TalkKeyModifier == Keys.None) && Game.IsKeyDown(Settings.TalkKey))
{
	//Display the current string from the string array as a subtitle.
	Game.DisplaySubtitle(_conversationLines[_currentConversationLine]);

	//Add on to _currentConversationLine so the player does not get the same string over and over.
	_currentConversationLine++;
}

/* OUTPUT:
Blurb1.
Blurb2.
Blurb3.
*/

 

Edited by ToastinYou

What BlockBa5her gave you is the simplest way to do it. Your conversation will display as it's defined in the array. However, if you choose to keep the players convo lines in its own array, and the other person's convo in another array, then you can do that too. You'd just need to modify your loops.

  • 2 weeks later...
On 4/4/2017 at 3:26 PM, BlockBa5her said:

I do something kind of different for conversations, I don't use a dictionary, I use a loop. It looks something like this


string[] talkArray = 
{
"Aggressor: I shot him!",
"Victim: He shot me!"
}

for (i = 0; i < talkArray.Length; i++)
{
  while (!Game.IsKeyDown(Keys.Y)) GameFiber.Yield();
  
  Game.DisplaySubtitle(talkArray[i]);
  GameFiber.Sleep(1000); //You don't need the sleep I just like to have it in my code so the person reads the entire text
}

That really should give you the same effect but you could choose either way.

 

Whenever I try this, it crashes the game with the error that that index is larger than the array.

 

 

  • 4 weeks later...
On 4/4/2017 at 4:26 PM, BlockBa5her said:

 


string[] talkArray = 
{
"Aggressor: I shot him!",
"Victim: He shot me!"
}

for (i = 0; i < talkArray.Length; i++)
{
  while (!Game.IsKeyDown(Keys.Y)) GameFiber.Yield();
  
  Game.DisplaySubtitle(talkArray[i]);
  GameFiber.Sleep(1000); //You don't need the sleep I just like to have it in my code so the person reads the entire text
}

 

 

Why do I get errors for the lowercase i in this?  what does the i stand for?  

Youtube: President Shadow

Creator Of Shadow Callouts

Discord: Contact Me and Apply For The Beta: https://discord.gg/q7JPXaR

 

15 hours ago, President Shadow said:

Why do I get errors for the lowercase i in this?  what does the i stand for?  

 

The "i" can be anything, it's just what you name your iterator variable. Most people just use "i" because it's the simplest. However, you need to declare the variable: "int i = 0;", not "i = 0;".

for (int i = 0; i < myMaxValue; i++)
{
    // Do stuff here
}

You also need to add a semicolon at the end of your "talkArray" declaration, after the closing bracket. And your loop should be run in a separate GameFiber, or your code will lock up the main thread, and RPH will kill LSPDFR because it will think that the plugin is frozen/crashed.

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

  • 2 weeks later...
On 4/14/2017 at 1:08 AM, AndyAlmighty said:

 

Whenever I try this, it crashes the game with the error that that index is larger than the array.

 

 

It did not work for you because..

 

This:

for (i = 0; i < talkArray.Length; i++)

 

Needs to be changed to..


This:

for (i = 0; i < talkArray.Count; i++)

 

Reading through some of these posts, I can't recommend websites like udemy enough for those of you new to programming. 

 

Trying to create plugins whilst also learning C# will be a challenging experience. Using udemy or a similar tool to learn the fundamentals of programming and a bit of basic C# will help you progress at a much higher rate. It may seem like more effort but it's really the most efficient way. I wish I'd had those tools available when I was first learning to program, would have saved me a lot of time.

Edited by AlconH

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.