|
 |
|
|
|
|
|
GTA Modification Forums
Manual Transmission Mod for GTA IV Mod for GTA IV 1.0.7.0
 |
|
 |
| |
rapter014  |
Posted: Wednesday, Aug 24 2011, 02:08
|
Player Hater

Group: Members
Joined: Oct 16, 2010

|
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=2MPHChange 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
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
AngryAmoeba  |
Posted: Wednesday, Aug 24 2011, 04:27
|
Symbiont

Group: Members
Joined: Jan 12, 2009


|
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. This post has been edited by AngryAmoeba on Wednesday, Aug 24 2011, 04:50
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
pedro2555  |
|
Rat

Group: Members
Joined: Sep 2, 2012

|
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
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Vintage88  |
|
Lost MC | VP

Group: Members
Joined: Nov 29, 2011


|
| 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.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Pages:
(2) [1] 2
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
| |
 |
|
 |
|
|
|
|