IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
Forum Rules GTA Modification Forums

Post mod/code requests in the Mod Requests topic

Post mod releases in the Mod Showroom

Read the Modding Rules BEFORE posting!

GTAGarage.com
free mod hosting from GTANet, simply login with your GTAForums account details

GTAModding.com
GTANet's modding wiki

GTA Modding Chatroom
provided by irc.gtanet.com (Don't have an IRC client? Click here)


Pages: (2) [1] 2   ( Go to first unread post ) Reply to this topicStart new topicStart Poll

 Manual Transmission Mod for GTA IV

 Mod for GTA IV 1.0.7.0
 
rapter014  
Posted: Wednesday, Aug 24 2011, 02:08
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Oct 16, 2010

XXXXX



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.

This post has been edited by rapter014 on Tuesday, Sep 6 2011, 19:03
PM
  Top
 

 
AngryAmoeba  
Posted: Wednesday, Aug 24 2011, 04:27
Quote Post


Symbiont
Group Icon
Group: Members
Joined: Jan 12, 2009

us.gif

XXXXX



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

This post has been edited by AngryAmoeba on Wednesday, Aug 24 2011, 04:50
PM
  Top
 

 
rapter014  
Posted: Wednesday, Aug 24 2011, 13:46
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Oct 16, 2010

XXXXX



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
PM
  Top
 

 
MulleDK19  
Posted: Thursday, Aug 25 2011, 01:47
Quote Post


1337 Programmer
Group Icon
Group: Members
Joined: May 30, 2009

dk.gif

XXXXX



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.
Users WebsitePM
  Top
 

 
ikt  
Posted: Thursday, Aug 25 2011, 11:25
Quote Post


 
Group Icon
Group: Members
Joined: Oct 2, 2006

XXXXX



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?
PM
  Top
 

 
AngryAmoeba  
Posted: Friday, Aug 26 2011, 06:01
Quote Post


Symbiont
Group Icon
Group: Members
Joined: Jan 12, 2009

us.gif

XXXXX



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;
PM
  Top
 

 
rapter014  
Posted: Friday, Aug 26 2011, 10:34
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Oct 16, 2010

XXXXX



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

 
ikt  
Posted: Friday, Aug 26 2011, 23:56
Quote Post


 
Group Icon
Group: Members
Joined: Oct 2, 2006

XXXXX



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?
PM
  Top
 

 
GIXXER  
Posted: Wednesday, Nov 16 2011, 13:35
Quote Post


MOTORCYCLE LOVER
Group Icon
Group: Members
Joined: Jan 27, 2010

ba.gif

XXXXX



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?
PM
  Top
 

 
Drunk Russian 9  
Posted: Friday, Nov 18 2011, 10:34
Quote Post


[★] SZM
Group Icon
Group: Members
Joined: Nov 13, 2007

ru.gif

XXXXX



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?
PMMSNAOLXbox Live
  Top
 

 
AngryAmoeba  
Posted: Friday, Nov 18 2011, 20:32
Quote Post


Symbiont
Group Icon
Group: Members
Joined: Jan 12, 2009

us.gif

XXXXX



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

 
Drunk Russian 9  
Posted: Friday, Nov 18 2011, 21:04
Quote Post


[★] SZM
Group Icon
Group: Members
Joined: Nov 13, 2007

ru.gif

XXXXX



This is why we need an SDK =(
PMMSNAOLXbox Live
  Top
 

 
XxUnknownkillax  
Posted: Tuesday, Dec 13 2011, 04:54
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Aug 1, 2009

XXXXX



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

 
hammy434  
Posted: Friday, Jun 1 2012, 17:05
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Jun 1, 2012

XXXXX



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

 
PrometheusX  
Posted: Saturday, Jun 2 2012, 00:47
Quote Post


Did I balls?
Group Icon
Group: Andolini Mafia Family
Joined: Apr 18, 2011

Member Award




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
Users WebsitePM
  Top
 

 
jumpman971  
Posted: Sunday, Nov 4 2012, 11:11
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Feb 28, 2009

XXXXX



Anyone can finish this mod???
PM
  Top
 

 
hamdaoui1998  
Posted: Sunday, Nov 4 2012, 15:28
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Aug 25, 2012

XXXXX



how to download this scripts ?plz
PM
  Top
 

 
pedro2555  
Posted: Monday, Nov 5 2012, 21:44
Quote Post


Rat
Group Icon
Group: Members
Joined: Sep 2, 2012

XXXXX



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.

This post has been edited by pedro2555 on Monday, Nov 5 2012, 21:47
PM
  Top
 

 
Deluxe8900  
Posted: Tuesday, Nov 6 2012, 11:04
Quote Post


Player Hater
Group Icon
Group: Members
Joined: Jun 14, 2012

XXXXX



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

 
Vintage88  
Posted: Tuesday, Nov 6 2012, 20:29
Quote Post


Lost MC | VP
Group Icon
Group: Members
Joined: Nov 29, 2011

nk.gif

XXXXX



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.
PMMSNXbox Live
  Top
 

 

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)

0 Members:

Pages: (2) [1] 2 

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG