Quantcast

Jump to content

» «
Photo

Manual Transmission Mod for GTA IV

32 replies to this topic
rapter014
  • rapter014

    Player Hater

  • Members
  • Joined: 16 Oct 2010

#1

Posted 24 August 2011 - 02:08 AM Edited by rapter014, 06 September 2011 - 07:03 PM.

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

AngryAmoeba
  • AngryAmoeba

    Symbiote

  • Members
  • Joined: 12 Jan 2009

#2

Posted 24 August 2011 - 04:27 AM Edited by AngryAmoeba, 24 August 2011 - 04:50 AM.

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.
CODE
const int MAX_GEAR = 5;
int gearState = 1;
bool bEnableClutch = true;

CODE
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.
CODE
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.gif icon14.gif

rapter014
  • rapter014

    Player Hater

  • Members
  • Joined: 16 Oct 2010

#3

Posted 24 August 2011 - 01:46 PM

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

MulleDK19
  • MulleDK19

    1337 Programmer

  • Members
  • Joined: 30 May 2009

#4

Posted 25 August 2011 - 01:47 AM

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.

ikt
  • ikt

     

  • Members
  • Joined: 02 Oct 2006

#5

Posted 25 August 2011 - 11:25 AM

QUOTE (MulleDK19 @ Thursday, Aug 25 2011, 03:47)
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?

AngryAmoeba
  • AngryAmoeba

    Symbiote

  • Members
  • Joined: 12 Jan 2009

#6

Posted 26 August 2011 - 06:01 AM

QUOTE (rapter014 @ Tuesday, Aug 23 2011, 20:08)
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?

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

rapter014
  • rapter014

    Player Hater

  • Members
  • Joined: 16 Oct 2010

#7

Posted 26 August 2011 - 10:34 AM

QUOTE (AngryAmoeba @ Friday, Aug 26 2011, 06:01)
Does this line in your code not work?

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

ikt
  • ikt

     

  • Members
  • Joined: 02 Oct 2006

#8

Posted 26 August 2011 - 11:56 PM

QUOTE (rapter014 @ Friday, Aug 26 2011, 12:34)
QUOTE (AngryAmoeba @ Friday, Aug 26 2011, 06:01)
Does this line in your code not work?

CODE
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?

GIXXER
  • GIXXER

    MOTORCYCLE LOVER

  • Members
  • Joined: 27 Jan 2010

#9

Posted 16 November 2011 - 01:35 PM

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


even if l accelerate with a 458?

Drunk Russian 9
  • Drunk Russian 9

    Soldier

  • Members
  • Joined: 13 Nov 2007

#10

Posted 18 November 2011 - 10:34 AM

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?

AngryAmoeba
  • AngryAmoeba

    Symbiote

  • Members
  • Joined: 12 Jan 2009

#11

Posted 18 November 2011 - 08:32 PM

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

Drunk Russian 9
  • Drunk Russian 9

    Soldier

  • Members
  • Joined: 13 Nov 2007

#12

Posted 18 November 2011 - 09:04 PM

This is why we need an SDK =(

XxUnknownkillax
  • XxUnknownkillax

    Player Hater

  • Members
  • Joined: 01 Aug 2009

#13

Posted 13 December 2011 - 04:54 AM

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

hammy434
  • hammy434

    Player Hater

  • Members
  • Joined: 01 Jun 2012

#14

Posted 01 June 2012 - 05:05 PM

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

Prometheus
  • Prometheus

  • Moderator
  • Joined: 18 Apr 2011
  • None

#15

Posted 02 June 2012 - 12:47 AM

QUOTE (hammy434 @ Friday, Jun 1 2012, 17:05)
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

jumpman971
  • jumpman971

    Player Hater

  • Members
  • Joined: 28 Feb 2009

#16

Posted 04 November 2012 - 11:11 AM

Anyone can finish this mod???

hamdaoui1998
  • hamdaoui1998

    Player Hater

  • Members
  • Joined: 25 Aug 2012

#17

Posted 04 November 2012 - 03:28 PM

how to download this scripts ?plz

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#18

Posted 05 November 2012 - 09:44 PM Edited by pedro2555, 05 November 2012 - 09:47 PM.

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.

Deluxe8900
  • Deluxe8900

    Player Hater

  • Members
  • Joined: 14 Jun 2012

#19

Posted 06 November 2012 - 11:04 AM

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

Vintage88
  • Vintage88

    Lost MC | VP

  • Members
  • Joined: 29 Nov 2011

#20

Posted 06 November 2012 - 08:29 PM

QUOTE (pedro2555 @ Monday, Nov 5 2012, 16:44)
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.

NudasPriest
  • NudasPriest

    Midnight Toker

  • Members
  • Joined: 29 Jul 2012

#21

Posted 06 November 2012 - 08:50 PM

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

Areppon
  • Areppon

    Square Civilian

  • Members
  • Joined: 08 Apr 2007

#22

Posted 09 February 2013 - 10:35 PM

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.

Engborg
  • Engborg

    Player Hater

  • Members
  • Joined: 25 Mar 2011

#23

Posted 18 March 2013 - 03:22 PM

QUOTE (Areppon @ Saturday, Feb 9 2013, 22:35)
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.

powler
  • powler

    Player Hater

  • Members
  • Joined: 30 Jan 2012

#24

Posted 18 March 2013 - 08:49 PM

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 :-)

Engborg
  • Engborg

    Player Hater

  • Members
  • Joined: 25 Mar 2011

#25

Posted 20 March 2013 - 02:45 PM

QUOTE (powler @ Monday, Mar 18 2013, 20:49)
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.

powler
  • powler

    Player Hater

  • Members
  • Joined: 30 Jan 2012

#26

Posted 20 March 2013 - 07:43 PM

QUOTE (Engborg @ Wednesday, Mar 20 2013, 14:45)
QUOTE (powler @ Monday, Mar 18 2013, 20:49)
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 :-)

Engborg
  • Engborg

    Player Hater

  • Members
  • Joined: 25 Mar 2011

#27

Posted 23 March 2013 - 12:44 PM

QUOTE (powler @ Wednesday, Mar 20 2013, 19:43)
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.

powler
  • powler

    Player Hater

  • Members
  • Joined: 30 Jan 2012

#28

Posted 23 March 2013 - 09:32 PM

QUOTE (Engborg @ Saturday, Mar 23 2013, 12:44)
QUOTE (powler @ Wednesday, Mar 20 2013, 19:43)
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 :-)

Engborg
  • Engborg

    Player Hater

  • Members
  • Joined: 25 Mar 2011

#29

Posted 23 March 2013 - 11:47 PM

QUOTE (powler @ Saturday, Mar 23 2013, 21:32)
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

powler
  • powler

    Player Hater

  • Members
  • Joined: 30 Jan 2012

#30

Posted 24 March 2013 - 12:03 AM

QUOTE (Engborg @ Saturday, Mar 23 2013, 23:47)
QUOTE (powler @ Saturday, Mar 23 2013, 21:32)
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 :-)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users