Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Rugz007

HELLLPPPPPP!

Recommended Posts

Rugz007

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

Share this post


Link to post
Share on other sites
pedro2555

Are you using Visual Studio??

 

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Rugz007

nope its doesnt when we say reload its is good

and we say helicopter its says okay sir but it frezzes and crash

 

now testing a void instead of case

Share this post


Link to post
Share on other sites
Rugz007

No It Doesnt work Too....... :/:(

 

 

 

can u guys test it on other patches just copy paste the code.....

 

i am on 1.0.4.0 and its not working plz test.... it would be great!

Share this post


Link to post
Share on other sites
LordOfTheBongs

nope its doesnt when we say reload its is good

and we say helicopter its says okay sir but it frezzes and crash

 

now testing a void instead of case

im going to edit your code for u to test something, i dont know if it will fix but maybe ;)

Share this post


Link to post
Share on other sites
Rugz007

:D Thaknz man and how is idea btw......

 

let me pm u

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Rugz007

Wil lit work bcoz my comp is off

Share this post


Link to post
Share on other sites
LordOfTheBongs

Wil lit work bcoz my comp is off

i dont know, im at work, i havent played gta iv in months, when u test, let me know ;)

Share this post


Link to post
Share on other sites
AgentWD40

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

Share this post


Link to post
Share on other sites
Rugz007

nope My Game Directly Crashes When We Try To Spawn Helicopter

Share this post


Link to post
Share on other sites
Rugz007

LORD OF BONGS U R AWESOME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :D :DD :);):p U GOT MY MOD WORKING MAN!!!!!!!!!!!!!!!!

Share this post


Link to post
Share on other sites
Rugz007

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;

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Rugz007

so becoz million helicopter spwaning my game crashes?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Rugz007

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

Share this post


Link to post
Share on other sites
Wiebrendh

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
julionib

so, you say Helicopter in the Mic and a Heli appears? thats cool, i never tried this speech recognize thing

Share this post


Link to post
Share on other sites
Rugz007

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

Share this post


Link to post
Share on other sites
julionib

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)

Share this post


Link to post
Share on other sites
AgentWD40

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)

Share this post


Link to post
Share on other sites
Rugz007

hey Man the Problem In Solved But Thaknz For ur Help ^^

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
julionib

 

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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Sign in to follow this  

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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