Jump to content

HELLLPPPPPP!


Recommended Posts

Hey Guys

 

I Am Having A BIG! Problem.....

 

 

I Made a program while learing c#

 

Here it is:

 

 

and i used some of its method in gta 4 modding...

 

so it speaks well if we give him a command and its good normally

 

but i tried to spawn helicopter and the game crashes...

 

any sugesstions?

 

Here Is The Code It Has No errors or warings

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Speech.Recognition;using System.Speech.Synthesis;using System.Threading;using System.Xml.Linq;using System.Xml;using System.IO;using GTA;namespace Speech_Recognizer{    public class Form1 : Script    {        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();        SpeechSynthesizer JARVIS = new SpeechSynthesizer();        public Form1()        {            Game.Console.Print("Working!");                        _recognizer.SetInputToDefaultAudioDevice();            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Program Files\Alex SR program\Alex.txt")))));            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);            _recognizer.RecognizeAsync(RecognizeMode.Multiple);        }        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)        {            string speech = e.Result.Text;            switch (speech)            {                //Commands                case "Reload":                    JARVIS.Speak("Checking Ammo. Reloading Gun");                    break;                case "Helicopter":                    JARVIS.Speak("Okay Sir");                     Vector3 vehPos = Player.Character.Position.Around(10.0f);                   World.CreateVehicle(new Model("ANNIHILATOR"), vehPos);                    break;            }        }    }}

any help..... if worked u r in my respect list ^^

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/
Share on other sites

LordOfTheBongs

Are you using Visual Studio??

 

A switch statement should not compile if it does not provide a default action.

switch should compile without a default case, maybe your VS is setup to show this as an error/warning and u prevent compiling with errors/warnings, that's my only guess but it will compile without default.

 

@Rugz007 Cool idea for a script. I'll test it later... your GTA code looks fine... just to make sure I understand you, your game crashes to the desktop when u say "Helicopter" into the microphone?

 

Does it crash when you say "Reload" too?

 

You didn't explain eveything so I'm guessing this speech recognition code event is not being called on the ScriptThread. I think you need to call this code via delegate... im not 100% sure but i know you cant call gta natives from other threads

Edited by LordOfTheBongs
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065438810
Share on other sites

LordOfTheBongs

 


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using GTA;

namespace Speech_Recognizer
{
public class Form1 : Script
{
private SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
private SpeechSynthesizer JARVIS = new SpeechSynthesizer();

private string currentFunction;

public Form1()
{
Tick += FunctionCaller;
Game.Console.Print("Working!");

recognizer.SetInputToDefaultAudioDevice();
recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Program Files\Alex SR program\Alex.txt")))));
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(RecognizerSpeechRecognized);
recognizer.RecognizeAsync(RecognizeMode.Multiple);
}

private void FunctionCaller(object sender, EventArgs e)
{
switch (currentFunction)
{
case "Reload":
//insert code to reload
currentFunction = null;
break;
case "Helicopter":
Vector3 vehPos = Player.Character.Position.Around(10.0f);
World.CreateVehicle(new Model("ANNIHILATOR"), vehPos);
currentFunction = null;
break;
}
}

private void RecognizerSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
currentFunction = e.Result.Text;
switch (currentFunction)
{
//Commands
case "Reload":
JARVIS.Speak("Checking Ammo. Reloading Gun");
break;
case "Helicopter":
JARVIS.Speak("Okay Sir");
break;
}
}
}
}

 

Edited by LordOfTheBongs
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065439053
Share on other sites

I did a small project with "System.Speech" but always had memory leaks. Does this happen to you Rugz007?

 

http://stackoverflow.com/questions/10707187/memory-leak-in-net-speech-synthesizer

 

I asked LMS(lcpdfr developer) for help and told me "the link you posted clearly states that there is indeed an issue in the code causing memory being leaked. So I'd follow the advice in the post and switch to Microsoft.Speech in order to prevent memory leaks."

Edited by hardsty1e
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065439174
Share on other sites

will it work if we put in the case thing this statement ?:

currentFunction = null;

will it work for example of my own code posted above

case "Helicopter":                    Vector3 vehPos = Player.Character.Position.Around(10.0f);                    World.CreateVehicle(new Model("ANNIHILATOR"), vehPos);                    currentFunction = null;                    break;
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065439408
Share on other sites

LordOfTheBongs

yes u need to make the current function null after so it doesnt keep calling the code over and over. You only want it to spawn the helicopter 1 time for example. If you did not reset the value of currentFunction to null then it would spawn the helicopter a million times or until your game crashes

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065439494
Share on other sites

LordOfTheBongs

so becoz million helicopter spwaning my game crashes?

oh no, i was just explaining why in my code i need to reset the value of the string currentFunction.

 

Your code was crashing the game because the speech recognition event was being called on another thread that GTA scripts dont run on. All GTA code needs to be called on the GTA script thread. Your speech code was on some thread the speech recognition uses ;)

 

i know i need to have the GTA thread call my code and i know the script tick event runs on the GTA thread. So i just needed to have the speech recognition trigger code in my tick event.

 

You learn this kind of stuff when writing forms apps... etc. Just know every single GTA script is running on a single thread and all being processed one after another. This is why u need to have waits in while loops for example.

Edited by LordOfTheBongs
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065439573
Share on other sites

This is your switch:

switch (currentFunction)            {                case "Reload":                    //insert code to reload                    currentFunction = null;                    break;                case "Helicopter":                    Vector3 vehPos = Player.Character.Position.Around(10.0f);                    World.CreateVehicle(new Model("ANNIHILATOR"), vehPos);                    currentFunction = null;                    break;            }

if you want to increase/decrease the wanted level you can do this:

switch (currentFunction)            {                case "Reload":                    //insert code to reload                    currentFunction = null;                    break;                case "Helicopter":                    Vector3 vehPos = Player.Character.Position.Around(10.0f);                    World.CreateVehicle(new Model("ANNIHILATOR"), vehPos);                    currentFunction = null;                    break;                case "Increase wanted level":                    Player.WantedLevel++;                    currentFunction = null;                    break;                case "Decrease wanted level":                    Player.WantedLevel--;                    currentFunction = null;                    break;            }
  • Like 1
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065440011
Share on other sites

LordOfTheBongs

okay

 

 

can you give me some cases (PM Me):

1) Wanted Levels (Increase And Decrease)

2) NRG- 900 Spwaner (have some doubts)

3) Some Others :D PM ME

it is better to keep the discussion here, then at least people who are learning can see your script

 

i know some people like to be private with their code but this is just a game and no one here is making money from this stuff... better to share publicly this knowledge ;)

 

But any questions I am happy to asnwer when im not busy, if u really like to then just PM me any question but your questions here can teach everyone who reads :)

 

Wiebrendh showed you how to adjust the player wanted level... for spawning any vehicle it is the same as the heli... just make sure u use the correct model name found here...

 

http://www.gtamodding.com/index.php?title=List_of_models_hashes#Vehicles

 

to spawn the NRG900, u need to use the model name "NRG900"... just create a new speech function for "Bike" or whatever name u decide

Edited by LordOfTheBongs
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065440066
Share on other sites

Thank you for all support guys

 

@julio- hey julio i know u script in vb.net but i saw your pastebins and u know c# ?

@weibren- Thanks Weibren de haan

@lord of bongs- okay

 

 

 

So Guys May i Make A Topic For The Mod.... because i just made this topic for crashing problem which is solved by lordofbongs

 

Edited by Rugz007
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065443290
Share on other sites

i write somethings in C# when i really need, the language is similar to others i used (even to vb). But i stay with vb.net mainly because of the case sensitive thing and the ease to understand coding (no much symbols)

"System.Speech" with gtaiv seems to have memory leaks, I suggest to check if your still gettting memory leaks before creating with "System.Speech" in big projects.

 

http://stackoverflow.com/questions/10707187/memory-leak-in-net-speech-synthesizer

 

 

The link you posted clearly states that there is indeed an issue in the code causing memory being leaked. So I'd follow the advice in the post and switch to Microsoft.Speech in order to prevent memory leaks.

 

LMS (lcpdfr developer)

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065445714
Share on other sites

LordOfTheBongs

i write somethings in C# when i really need, the language is similar to others i used (even to vb). But i stay with vb.net mainly because of the case sensitive thing and the ease to understand coding (no much symbols)

for me it is the opposite... the case sensitivity makes the names unique and i think that is important and having the symbols makes the code look cleaner and easier to follow... like if you were driving on the street and you see a sign that says "DO NOT TURN RIGHT" or you can see a sign with a picture of a right arrow and a red X over it... u can understand without having to read text. To me VB looks like reading a book and i find this to be more work to understand. Also the { } seem to be easier to follow than End xxx but everyone has their own preference and not one is better or worse

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065447408
Share on other sites

 

i write somethings in C# when i really need, the language is similar to others i used (even to vb). But i stay with vb.net mainly because of the case sensitive thing and the ease to understand coding (no much symbols)

for me it is the opposite... the case sensitivity makes the names unique and i think that is important and having the symbols makes the code look cleaner and easier to follow... like if you were driving on the street and you see a sign that says "DO NOT TURN RIGHT" or you can see a sign with a picture of a right arrow and a red X over it... u can understand without having to read text. To me VB looks like reading a book and i find this to be more work to understand. Also the { } seem to be easier to follow than End xxx but everyone has their own preference and not one is better or worse

 

 

yep.

 

biggest issue for me (and "nonsense" thing) is the case sensitive, why i would declare a variable called myVar and one called myvar? just will increase the possibility of wrong use in wrong place, but, maybe there is a good reason for this case sensitive, i dont know

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065452193
Share on other sites

LordOfTheBongs

 

 

i write somethings in C# when i really need, the language is similar to others i used (even to vb). But i stay with vb.net mainly because of the case sensitive thing and the ease to understand coding (no much symbols)

for me it is the opposite... the case sensitivity makes the names unique and i think that is important and having the symbols makes the code look cleaner and easier to follow... like if you were driving on the street and you see a sign that says "DO NOT TURN RIGHT" or you can see a sign with a picture of a right arrow and a red X over it... u can understand without having to read text. To me VB looks like reading a book and i find this to be more work to understand. Also the { } seem to be easier to follow than End xxx but everyone has their own preference and not one is better or worse

 

 

yep.

 

biggest issue for me (and "nonsense" thing) is the case sensitive, why i would declare a variable called myVar and one called myvar? just will increase the possibility of wrong use in wrong place, but, maybe there is a good reason for this case sensitive, i dont know

 

if ur using a proper capitalization style, u would always use camel case for local fields/private variables

 

u dont just name methods and objects whatever u like, u name them based on what the object is and it's access modifier or how it is being used. So when i look at a variable i can understand some important things about it just by seeing how it is capitalized

 

myVar, MyVar, _myVar, MY_VAR

 

all tell me something different and help me understand the script... people who ignore these type of style rules generally have ugly ass code

 

capitalization in c# has a purpose, it's not just to look nice

 

look...

private const int MY_VAR = 5;//i can tell by capitalization this is a constant and will not changeprivate int myVar;//camel case so i know it is used in this class onlyprivate int _myVar;//this i can tell is private but can be referenced from other classes via a public propertypublic int MyVar { get { return _myVar; } }//this one i can tell is referenced in other classes... class names and method names follow same casing (Pascal case)
Edited by LordOfTheBongs
Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065452307
Share on other sites

NTAuthority

I personally consider accessing private member fields starting with _ fairly ugly, which is why I use common 'native code' conventions of m_/ms_; which is perfectly fine according to the common naming conventions for CLI code.

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065452372
Share on other sites

LordOfTheBongs

I personally consider accessing private member fields starting with _ fairly ugly, which is why I use common 'native code' conventions of m_/ms_; which is perfectly fine according to the common naming conventions for CLI code.

i believe u use the underscore for private fields refrenced through public properties

Link to comment
https://gtaforums.com/topic/710621-helllpppppp/#findComment-1065452400
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.