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.

[Resolved] Getting key press multiple times

Featured Replies

 public void ConversationHuman()
        {
            GameFiber.StartNew(delegate
            {
                Game.DisplaySubtitle("~w~Talk to the ~y~Caller", 6500);
                Game.DisplayHelp(("Press '~b~Y~w~' to advance in conversation"), 6500);

                check = ESwitchCheck.init;

                while (true)
                {
                    if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.init)
                    {
                        Game.DisplaySubtitle("Oh my poor booboo!", 6500);
                        check = ESwitchCheck.first;
                        GameFiber.Wait(500);

                        if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.first)
                        {
                            Game.DisplaySubtitle("They must be so scared!", 6500);
                            check = ESwitchCheck.finish;
                            GameFiber.Wait(500);

                            if (Game.IsKeyDown(System.Windows.Forms.Keys.Y) && check == ESwitchCheck.finish)
                            {
                                Game.DisplaySubtitle("Please officer, you must find them!", 6500);
                                GameFiber.Wait(500);
                            }
                        }
                    }
                    
                    GameFiber.Yield();
                }
            });
        }

 

I have looked through the API development forum for an answer, and either I've missed it, or it doesn't exist.

This is a pretty simple problem, which I'm sure has a simple answer, but I cannot come up with it for the life of me for some odd reason.

I want to have a ped say dialogue to the player every time the 'Y' key is pressed.

While testing, I come up to the ped, press 'Y', and only the first phrase is said to me: "Oh my poor booboo!" (yes it sounds weird, but will make sense when callout is released)

I press 'Y' again, and the second phrase does not execute.

Help appreciated,
Thanks
 

Edited by tanu1215

I think it is because you have put all of the if statements inside each other.

Because when it runs through the while loop the second time, your check equals ESwitchCheck.first and not ESwitchCheck.init. So it doesn't meet the 'criteria' and never reads the second if statement.

 

I'd suggest using an else-if statement if possible.

while (true)
{
	if (Game.IsKeyDown(System.Windows.Forms.Keys.Y))
	{			
		if (check == ESwitchCheck.init)
		{
			Game.DisplaySubtitle("Oh my poor booboo!", 6500);
			check = ESwitchCheck.first;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.first)
		{
			Game.DisplaySubtitle("They must be so scared!", 6500);
			check = ESwitchCheck.finish;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.finish)
		{
			Game.DisplaySubtitle("Please officer, you must find them!", 6500);
			GameFiber.Wait(500);
		}
		else
		{
		}
	}
}

 

I'm not sure if the last else is needed so I put it there just in case. And I added the very first if statement but you can get rid of that and check for key press in the other if's and else if's if you prefer.

  • Author
17 hours ago, Cosmo said:

I think it is because you have put all of the if statements inside each other.

Because when it runs through the while loop the second time, your check equals ESwitchCheck.first and not ESwitchCheck.init. So it doesn't meet the 'criteria' and never reads the second if statement.

 

I'd suggest using an else-if statement if possible.


while (true)
{
	if (Game.IsKeyDown(System.Windows.Forms.Keys.Y))
	{			
		if (check == ESwitchCheck.init)
		{
			Game.DisplaySubtitle("Oh my poor booboo!", 6500);
			check = ESwitchCheck.first;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.first)
		{
			Game.DisplaySubtitle("They must be so scared!", 6500);
			check = ESwitchCheck.finish;
			GameFiber.Wait(500);
		}
		else if (check == ESwitchCheck.finish)
		{
			Game.DisplaySubtitle("Please officer, you must find them!", 6500);
			GameFiber.Wait(500);
		}
		else
		{
		}
	}
}

 

I'm not sure if the last else is needed so I put it there just in case. And I added the very first if statement but you can get rid of that and check for key press in the other if's and else if's if you prefer.

I ended up figuring this out a while after I made the post. I find it weird how I only find things out after I make posts about it haha.

Thanks a lot!

Edited by tanu1215

  • 2 weeks later...

A little late to the party, but I use a Generic List of strings, and I just cycle through them. Much better than hardcoding it. :thumbsup:

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!

  • Author
On 1/16/2016 at 1:10 PM, Stealth22 said:

A little late to the party, but I use a Generic List of strings, and I just cycle through them. Much better than hardcoding it. :thumbsup:

Yep, I have started to do that :)

  • 9 months later...

How was this figured out?

On 1/7/2016 at 9:27 PM, tanu1215 said:

I ended up figuring this out a while after I made the post. I find it weird how I only find things out after I make posts about it haha.

Thanks a lot!

I'm getting errors with init first finish and Im unaware of how to write the e switch check variable

Edited by Markadaliah

  • Author
4 hours ago, Markadaliah said:

How was this figured out?

I'm getting errors with init first finish and Im unaware of how to write the e switch check variable

It's been a while. Post your code and I can try to help.

{

            base.Process();
            GameFiber.StartNew(delegate
            {
                if (Game.LocalPlayer.Character.DistanceTo(CalloutPositionTrooperCar1) < 5f)
                {
                    Game.DisplaySubtitle("Please locate your ~r~Supervisor~w~ for briefing", 3000);
                    //GameFiber.Wait(400);

                    {
                        while (true)
                        {
                            if (Game.IsKeyDown(System.Windows.Forms.Keys.G))
                            {
                                break;
                            }
                            Game.DisplaySubtitle("Glad you all could make it", 6500);
                            //  GameFiber.Wait(500);
                            GameFiber.Yield();
                        }
                    }
                }

 

                {
                    while (true)
                    {
                        if (Game.IsKeyDown(System.Windows.Forms.Keys.G))
                        {
                            break;
                        }
                        Game.DisplaySubtitle("We are going to be running some traffic enforcement as part of a new San Andreas Highway System initiative to reduce traffic fatalities", 6500);
                    }
                }


            });
        
            }

[Spoiler/]

I want to drive up to the scene, and have it display the locate sergeant message, and then after that, I want to be able to hit Y when I am right next to the sergeant, and have him say multiple subtitles of things/ Just a new basic feature for me that I have not learned yet. Thank you for offering the help

Edited by Markadaliah

9 hours ago, tanu1215 said:

It's been a while. Post your code and I can try to help.

I guess a lot of my issue is with the game fibers because as long as I have that is key down stuff in there it with the game fiber and the gamefiber.wait, it just freezes the game

  • Author
11 hours ago, Markadaliah said:

I guess a lot of my issue is with the game fibers because as long as I have that is key down stuff in there it with the game fiber and the gamefiber.wait, it just freezes the game

Sorry for the late response. So I don't really understand your code.. I am not sure why you are using two while loops? There should only be one. And Yes, you're probably crashing due to you not yielding the fibers.

By the way, those Eswitch things are called Enums, and im simply using them as flags.

So here is some pseudo - code for what you'd probably want:

 

boolean isSpeechComplete = false;

while(!isSpeechComplete)
{
    while(!Game.isKeyDown(Key.Y)

    {
    GameFiber.Yield();
    }

	SayFirstthing;
	GameFiber.Wait(1000);
	SaySecondThing;
	GameFiber.Wait(1000);
	SayLastThing:
    GameFiber.Wait(1000);
	isSpeechComplete = true;
}

 

This obviously wont work.. but it should hopefully give you a good idea of what you may want to do.

If you need some more help, let me know.

2 hours ago, tanu1215 said:

Sorry for the late response. So I don't really understand your code.. I am not sure why you are using two while loops? There should only be one. And Yes, you're probably crashing due to you not yielding the fibers.

By the way, those Eswitch things are called Enums, and im simply using them as flags.

So here is some pseudo - code for what you'd probably want:

 


boolean isSpeechComplete = false;

while(!isSpeechComplete)
{
    while(!Game.isKeyDown(Key.Y)

    {
    GameFiber.Yield();
    }

	SayFirstthing;
	GameFiber.Wait(1000);
	SaySecondThing;
	GameFiber.Wait(1000);
	SayLastThing:
    GameFiber.Wait(1000);
	isSpeechComplete = true;
}

 

This obviously wont work.. but it should hopefully give you a good idea of what you may want to do.

If you need some more help, let me know.

Yeah sorry for my shit code, I have a lot of garbage trial crap going on. But thank you, seriously, thank you so much. I am trying this now.

 

Damn, so close man, thank you. I just have one or two issues here. I want it to say more and more so I guess I could add more lines. But the thing is, when I accept the callout, the texts starts without waiting for my to hit G, and it just continues to loop. How to I stop the loop so I can end the speech the SGT will be giving, and then he will escort them to a spot to to run radar.

   public override void Process()
        {

 

            base.Process();
            Boolean isSpeechComplete = false;

            while (!isSpeechComplete)
            {
                while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

                Game.DisplaySubtitle("Today we are going to run speed trap traffic enforcement");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("I will call out the speed, car, and car color of the individual you are to pull over");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("Fllow me to the spot where we will setup, turn your radios to channels 15");
                GameFiber.Wait(3000);
                isSpeechComplete = true;
            }
        }
       

        public override void End()
        {

[Spoiler/]

Edited by Markadaliah

  • Author
17 hours ago, Markadaliah said:

Yeah sorry for my shit code, I have a lot of garbage trial crap going on. But thank you, seriously, thank you so much. I am trying this now.

 

Damn, so close man, thank you. I just have one or two issues here. I want it to say more and more so I guess I could add more lines. But the thing is, when I accept the callout, the texts starts without waiting for my to hit G, and it just continues to loop. How to I stop the loop so I can end the speech the SGT will be giving, and then he will escort them to a spot to to run radar.

 

  Hide contents

 

   public override void Process()
        {

 

            base.Process();
            Boolean isSpeechComplete = false;

            while (!isSpeechComplete)
            {
                while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

                Game.DisplaySubtitle("Today we are going to run speed trap traffic enforcement");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("I will call out the speed, car, and car color of the individual you are to pull over");
                GameFiber.Wait(3000);
                Game.DisplaySubtitle("Fllow me to the spot where we will setup, turn your radios to channels 15");
                GameFiber.Wait(3000);
                isSpeechComplete = true;
            }
        }
       

        public override void End()
        {

[Spoiler/]

 

Try putting a '!' to denote false. 

 

while (Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }

Should be

 

while (!Game.IsKeyDown(System.Windows.Forms.Keys.G)) ;

                {
                    GameFiber.Yield();
                }


So basically we're checking to see if the G key is not pressed. This will yield the fiber and basically wait until the G key is pressed, then it will continue to the speech.

And the loop should stop after the boolean is set to true. So after that while loop, put any code you need for your SGT. to walk to a point.

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

Similar Content

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.