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

rapter014

Manual Transmission Mod for GTA IV

Recommended Posts

rapter014

Today I decided to see if I could make a Manual Transmission Mod for GTA IV but at the moment I'm stuck. I know there's already a Manual Transmission mod here but unfortunately it does not work with the 1.0.7.0 patch for GTA IV. More specifically it doesn't limit the speed and RPMs of the car.

 

What I want the mod to do:

  • Limit speed of the Players car
  • Shut car off if the user tries to accelerate from 0MPH in a gear higher than 1
  • Shut car off if the user shifts down from a higher gear into a lower one at too high of a speed.
  • Have an optional clutch which the user can turn on and off in an Ini File
Controls:
  • 8 - Shift Up
  • 5 - Shift Down
  • 0 - Clutch
I didn't know how to code in C# so I looked at this tutorial. It taught me a lot about what I was trying to do but I still have no idea how to perfect the script.

 

EDIT #3: Changed the code again:

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using GTA;namespace ManualTransmission{   public class ManualTransmission : Script   {       //Declare Gear       int gearState = 1;       const int MAX_GEAR = 6;       //clutch       bool bEnableClutch = true;       //Keys       Keys keySU;       Keys keySD;       Keys keyC;              public ManualTransmission()       {           //Get INI Settings           bEnableClutch = Settings.GetValueBool("CLUTCH_ENABLED", "SETTINGS", true);           keySU = Settings.GetValueKey("SHIFT_UP", "KEYS", Keys.NumPad8);           keySD = Settings.GetValueKey("SHIFT_DN", "KEYS", Keys.NumPad5);           keyC = Settings.GetValueKey("CLUTCH", "KEYS", Keys.NumPad0);                      //Set Interval 10 milSecs           Interval = 10;           //Limit Speed           this.Tick += new EventHandler(setSpeed);                      //Change Gear           this.KeyDown += new GTA.KeyEventHandler(gearSwitchHandler);                       //Show Info           this.PerFrameDrawing += new GraphicsEventHandler(gfxDraw);       }       //Switch Through Gears       public void gearSwitchHandler(object sender, GTA.KeyEventArgs e)       {           if (bEnableClutch && !isKeyPressed(keyC)) return;                      //Increase gear           if (keySU == e.Key && gearState < MAX_GEAR)           {               gearState ++;           }           //Decrease Gear           if(keySD == e.Key && gearState > 1)           {               gearState --;           }       }       //Display Gear       public void gfxDraw(object sender, GraphicsEventArgs e)       {           if (Player.Character.isInVehicle())           {               e.Graphics.DrawText("Current Gear: " + gearState, 1f, 0.3f);           }       }       //Calculate heading       //public void calcHeading(object sender, GraphicsEventArgs e)       //{       //}       //Use gear to limit speed       public void setSpeed(object sender, EventArgs e)       {           Vehicle v = Player.Character.CurrentVehicle;           if (Player.Character.isInVehicle())           {               switch (gearState)               {                   case 1:                       if (Exists(v) && v.EngineHealth == 0) v.EngineHealth = 1000;                       if (Exists(v) && v.Speed >= 15.0f) v.Speed = 15.0f;                       break;                   case 2:                       if (Exists(v) && v.Speed <= 2.0f && v.Speed >= 1.0f) v.EngineHealth = 0;                       else if (Exists(v) && v.Speed >= 25.0f && v.isOnAllWheels == true) v.Speed = 25.0f;                       break;                   case 3:                       if (Exists(v) && v.Speed <= 2.0f && v.Speed >= 1.0f) v.EngineHealth = 0;                       else if (Exists(v) && v.Speed >= 35.0f && v.isOnAllWheels == true) v.Speed = 35.0f;                       break;                   case 4:                       if (Exists(v) && v.Speed <= 2.0f && v.Speed >= 1.0f) v.EngineHealth = 0;                       else if (Exists(v) && v.Speed >= 45.0f && v.isOnAllWheels == true) v.Speed = 45.0f;                       break;                   case 5:                       if (Exists(v) && v.Speed <= 2.0f && v.Speed >= 1.0f) v.EngineHealth = 0;                       else if (Exists(v) && v.Speed >= 55.0f && v.isOnAllWheels == true) v.Speed = 55.0f;                       break;                   case 6:                       if (Exists(v) && v.Speed <= 2.0f && v.Speed >= 1.0f) v.EngineHealth = 0;                       else if (Exists(v) && v.Speed >= 75.0f && v.isOnAllWheels == true) v.Speed = 75.0f;                       break;                   default:                       throw new Exception("Gear is out of Range");               }           }           else if (gearState != 1) gearState = 1;       }   }}

 

 

I tested the code again on 1.0.7.0 and found that the reason the car wasn't be held at the correct speed was because the values I had in the script I had were too high.

For anyone interested: 1.0f=2MPH

 

Change List:

  • Text which shows what gear the car is in now only appears when a player is in a car
  • car health is now set to 0 if the player tries to acclerate from the wrong gear
I plan on:
  • adding a variable to set the player's engine health back to what it was before they tried to accelerate
Gonna keep updating this thread until the mod is complete. Thanks a ton to everyone that helped me so far. Edited by rapter014

Share this post


Link to post
Share on other sites
Symbiote

Some things I noticed:

 

- In gearSwitchHandler(), you set gearState to 1 every time any key is pressed. Instead, initialize it to 1 when it's declared at the top.

- I would add a constant, MAX_GEAR = 5, and prevent gearState from being greater.

- I added code you could use for the clutch.

 

const int MAX_GEAR = 5;int gearState = 1;bool bEnableClutch = true;

 

 

public void gearSwitchHandler(object sender, GTA.KeyEventArgs e){   //Do nothing if clutch isn't pressed   if (bEnableClutch && !isKeyPressed(Keys.NumPad0)       return;   //Increase or decrease gear   if (Keys.NumPad8 == e.Key && gearState < MAX_GEAR)       gearState++;   else if (Keys.NumPad5 == e.Key && gearState > 1)       gearState--;}

 

 

- You should check if v exists before getting its speed. And use Exists(v), because it checks if v.Exists() as well as if v == null. This will avoid null reference errors.

- I think v.Speed is a float.

- I would rearrange the code in the switch a bit.

- gearState will have to be reset to 1 when the player exits a car.

 

if (Player.Character.isInVehicle()){  switch (gearState)  {      case 1:          if (Exists(v) && v.Speed > 30.0f) v.Speed = 30.0f;          break;      case 2:          if (Exists(v) && v.Speed <= 1.0f) v.EngineRunning = false;          else if (Exists(v) && v.Speed > 50.0f)  v.Speed = 50.0f;          break;      case 3:          if (Exists(v) && v.Speed <= 1.0f) v.EngineRunning = false;          else if (Exists(v) && v.Speed > 70.0f) v.Speed = 70.0f;          break;      case 4:          if (Exists(v) && v.Speed <= 1.0f) v.EngineRunning = false;          else if (Exists(v) && v.Speed > 90.0f) v.Speed = 90.0f;          break;      case 5:          if (Exists(v) && v.Speed <= 1.0f) v.EngineRunning = false;          else if (Exists(v) && v.Speed > 110.0f) v.Speed = 110.0f;          break;      default:          throw new Exception("Gear is out of range.");  }}else if (gearState != 1) gearState = 1;

 

 

I haven't tested any of that, but it might work a bit better now.

 

Good work on your first script. biggrin.gificon14.gif

Edited by AngryAmoeba

Share this post


Link to post
Share on other sites
rapter014

Thanks a ton! The code you gave makes much more sense to me.

 

I'll Change the code in the original post to match what you said smile.gif

Share this post


Link to post
Share on other sites
MulleDK19

Setting the Speed property is not a good idea for things like this, as Speed sets the instantaneous velocity in the current direction. Meaning you won't be able to slide the car, as the car will gain perfect handling.

Share this post


Link to post
Share on other sites
ikt
Setting the Speed property is not a good idea for things like this, as Speed sets the instantaneous velocity in the current direction. Meaning you won't be able to slide the car, as the car will gain perfect handling.

Add force in the direction you're already heading, getting the heading from the difference between two ticks and calculate the vector from that and add a force in that direction?

Share this post


Link to post
Share on other sites
Symbiote
2) How can I get the car to shut off only until the user shifts into first and not permanently?

Does this line in your code not work?

 

 

if (Exists(v) && v.EngineRunning == false) v.EngineRunning = true;

 

Share this post


Link to post
Share on other sites
rapter014

 

Does this line in your code not work?

 

 

if (Exists(v) && v.EngineRunning == false) v.EngineRunning = true;

 

When I tested the code to see if the car would shut off at the right time, I found that if I did not switch to gear 1 quickly enough, the car would not start again unless I got out of the car and got back in again.

Share this post


Link to post
Share on other sites
ikt
Does this line in your code not work?

 

 

if (Exists(v) && v.EngineRunning == false) v.EngineRunning = true;

 

When I tested the code to see if the car would shut off at the right time, I found that if I did not switch to gear 1 quickly enough, the car would not start again unless I got out of the car and got back in again.

You could use a native to start the car engine again once you put the gear into 1?

Share this post


Link to post
Share on other sites
1000pia

 

Shut car off if the user tries to accelerate from 0MPH in a gear higher than 1

 

even if l accelerate with a 458?

Share this post


Link to post
Share on other sites
Drunk Russian 9

Can't a more natural manual transmission be coded? Can't you just stop the car from shifting on it's own, and wait for a user input?

Share this post


Link to post
Share on other sites
Symbiote

If only it were that simple. As far as I know, that's not possible.

Share this post


Link to post
Share on other sites
Drunk Russian 9

This is why we need an SDK =(

Share this post


Link to post
Share on other sites
XxUnknownkillax

Can some body please make this into a .dll or asi downloadable file for the newbies?

Share this post


Link to post
Share on other sites
hammy434

please continue with this mod, i really need it, when its done it will be really amazing cause i really want it. can't wait!!

Share this post


Link to post
Share on other sites
Prometheus
please continue with this mod, i really need it, when its done it will be really amazing cause i really want it. can't wait!!

The OP hasn't been here for more than 2 months, so I don't think this mod will be released anytime soon. confused.gif

Share this post


Link to post
Share on other sites
jumpman971

Anyone can finish this mod???

Share this post


Link to post
Share on other sites
hamdaoui1998

how to download this scripts ?plz

Share this post


Link to post
Share on other sites
pedro2555

You said 1.0f=2MPH. Don't know if we are talking about the same think, but the speed value of GTA IV is in meters per second, so 1.0f = 2.23694 MPH.

 

Just a question, how do you handle the already existent gearing system. Because the cars already have gears, they'r auto but they have gears. How to managed that, check the RPM, and if at 1 don't allow speed to go up ? But how to be sure, you don't hear the in-game gear go up (or down) out of time ?

 

I'm looking include this on UltimateFuelScript V2. But it has to be just right.

Edited by pedro2555

Share this post


Link to post
Share on other sites
Deluxe8900

It can be done for Xbox manual trans cause we have a SDK, XDK etc tounge.gif

Share this post


Link to post
Share on other sites
Vintage88
You said 1.0f=2MPH. Don't know if we are talking about the same think, but the speed value of GTA IV is in meters per second, so 1.0f = 2.23694 MPH.

 

Just a question, how do you handle the already existent gearing system. Because the cars already have gears, they'r auto but they have gears. How to managed that, check the RPM, and if at 1 don't allow speed to go up ? But how to be sure, you don't hear the in-game gear go up (or down) out of time ?

 

I'm looking include this on UltimateFuelScript V2. But it has to be just right.

Do we really know they have gears?

Could be an auditory trick.

Share this post


Link to post
Share on other sites
NudasPriest

They definitely have gears, i've felt the difference between 1st gear and 2nd/3rd in certain cars, they take steep slopes better in 1st

Share this post


Link to post
Share on other sites
Areppon

How functional is this script? Does it work as is or does it still need work? Has anyone played with it since November? Is anyone playing with it now?

 

Play with it = mess with the code.

Share this post


Link to post
Share on other sites
Engborg
How functional is this script? Does it work as is or does it still need work? Has anyone played with it since November? Is anyone playing with it now?

 

Play with it = mess with the code.

I'm actually playing with some of this code, written some own for this aswell but it's not functional as it is now. A manual gearbox isn't easy doing since there's no command for controlling the gears that's already in the game. The only thing related to the in-game gears is that you can access the "CurrentRPM" but not set it. But I'm wearing my thinking hat and I'll hopefully figure something out, until then, I'll gladly accept tips on what the best way is for controlling the speed of the vehicle.

Share this post


Link to post
Share on other sites
powler

I really hope you can do it because i would love to use this would you be able to make it compatible for 360 controller? That would be amazing :-)

Share this post


Link to post
Share on other sites
Engborg
I really hope you can do it because i would love to use this would you be able to make it compatible for 360 controller? That would be amazing :-)

IF I'm able to do this mod it will work with an Xbox 360 controller, since I always play with one myself. But as I said before, it's not easy and there's a chance it's not possible to make a GOOD manual gearbox.

Share this post


Link to post
Share on other sites
powler
I really hope you can do it because i would love to use this would you be able to make it compatible for 360 controller? That would be amazing :-)

IF I'm able to do this mod it will work with an Xbox 360 controller, since I always play with one myself. But as I said before, it's not easy and there's a chance it's not possible to make a GOOD manual gearbox.

That's cool would it work if when you get to a set amount of revs it locks until you release acceleration then press and hold acceleration to unlock to the next set amount? Then with with the handbrake if you press it it locks until pressed again? Could that be done? Hope that all made sense lol :-) looking forward to trying when its done thought this will be so sweet :-)

Share this post


Link to post
Share on other sites
Engborg
That's cool would it work if when you get to a set amount of revs it locks until you release acceleration then press and hold acceleration to unlock to the next set amount? Then with with the handbrake if you press it it locks until pressed again? Could that be done? Hope that all made sense lol :-) looking forward to trying when its done thought this will be so sweet :-)

The problem is that I can't control the RPM, I can only read the current number.

Share this post


Link to post
Share on other sites
powler
That's cool would it work if when you get to a set amount of revs it locks until you release acceleration then press and hold acceleration to unlock to the next set amount? Then with with the handbrake if you press it it locks until pressed again? Could that be done? Hope that all made sense lol :-) looking forward to trying when its done thought this will be so sweet :-)

The problem is that I can't control the RPM, I can only read the current number.

Fair enough mate, i can see the difficulty you are facing... I hope you work it out though :-)

Share this post


Link to post
Share on other sites
Engborg
Fair enough mate, i can see the difficulty you are facing... I hope you work it out though :-)

Yeah, it would be neat. smile.gif

Share this post


Link to post
Share on other sites
powler
Fair enough mate, i can see the difficulty you are facing... I hope you work it out though :-)

Yeah, it would be neat. smile.gif

Neat? Will be amazing :-) if you get it to work i would love to test it for you :-)

Share this post


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

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

×

Important Information

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