Advertisement
Guest User

Manual Transmission Mod SOURCE

a guest
May 30th, 2015
3,809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.55 KB | None | 0 0
  1. /*
  2.     THIS FILE IS A PART OF GTA V SCRIPT HOOK SDK
  3.                 http://dev-c.com           
  4.             (C) Alexander Blade 2015
  5. */
  6. #pragma warning(disable:4996)
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <string>
  10. #include <psapi.h>
  11. #include <stdint.h>
  12. #include <iostream>
  13. #include <fstream>
  14. #include <sstream>
  15. using namespace std;
  16. #include "script.h"
  17. #include <string>
  18. #include <ctime>
  19.  
  20. struct Buttons {
  21.     int Clutch, FirstGear, SecondGear, ThirdGear, FourthGear, Reverse, EnableDisable;
  22. };
  23. Buttons Pressed;
  24.  
  25. void loadConfig(Buttons& config) {
  26.     ifstream fin("MTconfig.ini");
  27.     string line;
  28.     while (getline(fin, line)) {
  29.         istringstream sin(line.substr(line.find("=") + 1));
  30.         if (line.find("Clutch") != -1)
  31.             sin >> config.Clutch;
  32.         else if (line.find("FirstGear") != -1)
  33.             sin >> config.FirstGear;
  34.         else if (line.find("SecondGear") != -1)
  35.             sin >> config.SecondGear;
  36.         else if (line.find("ThirdGear") != -1)
  37.             sin >> config.ThirdGear;
  38.         else if (line.find("FourthGear") != -1)
  39.             sin >> config.FourthGear;
  40.         else if (line.find("Reverse") != -1)
  41.             sin >> config.Reverse;
  42.         else if (line.find("Enable/Disable") != 1)
  43.             sin >> config.EnableDisable;
  44.     }
  45. }
  46.  
  47. ifstream ConfigFile("MTconfig.ini");
  48. void LB()
  49. {
  50.     if (ConfigFile)
  51.     {
  52.         loadConfig(Pressed);
  53.     }
  54. }
  55.  
  56. void max_speed(int entity, float speed)
  57. {
  58.     ENTITY::SET_ENTITY_MAX_SPEED(entity, speed);
  59. }
  60.  
  61. bool MT = true;
  62. bool Gear1 = true, Gear2, Gear3, Gear4, Reverse;
  63. bool isClutchDown = false;
  64. bool ConfigLoaded = false;
  65. bool ShiftNow;
  66. bool Gear3Launch = false;
  67. void ManualTransmission()
  68. {
  69.     reset_globals();
  70.     while (true)
  71.     {
  72.  
  73.         if (!ConfigLoaded)
  74.         {
  75.             LB();
  76.             ConfigLoaded = true;
  77.         }
  78.  
  79.         unsigned int model = GetHash("taxi");
  80.  
  81.         if (is_control_pressed(Gamepad::Right) || get_key_pressed(Keys::RIGHT))
  82.         {
  83.             MT = !MT;
  84.             MT ? ShowText("Manual Transmission ~g~Enabled~w~!") : ShowText("Manual Transmission ~r~Disabled~w~!");
  85.             WAIT(50);
  86.         }
  87.  
  88.         if (MT)
  89.         {          
  90.             if (is_ped_in_any_vehicle(player_ped_id()))
  91.             {
  92.                 float speed = ENTITY::GET_ENTITY_SPEED(vehid());
  93.                 float acceleration = VEHICLE::GET_VEHICLE_ACCELERATION(vehid());
  94.                 float FirstMax = 21.0f;
  95.                 float SecondMax = 31.0f;
  96.                 float ThirdMax = 40.5f;
  97.                 if (get_key_pressed(Pressed.Clutch))
  98.                 {
  99.                     isClutchDown = true;
  100.                     CONTROLS::DISABLE_CONTROL_ACTION(2, 71, true);
  101.                 }
  102.                 else
  103.                 {
  104.                     isClutchDown = false;
  105.                 }
  106.  
  107.                 if (isClutchDown)
  108.                 {
  109.                     GearSc("Clutch", 0.080, 0.015);
  110.                 }
  111.                 else
  112.                 {
  113.                     Gear("Clutch", 0.080, 0.015);
  114.                 }
  115.  
  116.                 if (ShiftNow)
  117.                 {
  118.                     GearSc("Shift", 0.155, 0.015);
  119.                 }
  120.                 else
  121.                 {
  122.                     Gear("Shift", 0.155, 0.015);
  123.                 }
  124.  
  125.                 if (speed < 1)
  126.                 {
  127.                     CONTROLS::DISABLE_CONTROL_ACTION(2, 72, true);
  128.                 }
  129.  
  130.                 if (!Reverse && get_key_pressed(Keys::S))
  131.                 {
  132.                     if (speed > 0)
  133.                     {
  134.                         speed -= 1.2f;
  135.                     }
  136.                     else if (speed < 1)
  137.                     {
  138.                         CONTROLS::DISABLE_CONTROL_ACTION(2, 72, true);
  139.                     }
  140.                 }
  141.  
  142.                 if (Gear1)
  143.                 {
  144.                     GearSc("1", 0.015, 0.015);
  145.                     if (speed > FirstMax)
  146.                     {
  147.                         float curr = ENTITY::GET_ENTITY_SPEED(vehid());
  148.                         max_speed(vehid(), curr);
  149.                     }
  150.                     else
  151.                     {
  152.                         max_speed(vehid(), FirstMax);
  153.                     }
  154.                     if (speed > FirstMax - 1)
  155.                     {
  156.                         ShiftNow = true;
  157.                     }
  158.                     else
  159.                     {
  160.                         ShiftNow = false;
  161.                     }
  162.                 }
  163.                 else if (Gear2)
  164.                 {
  165.                     GearSc("2", 0.015, 0.015);
  166.                     if (speed > SecondMax)
  167.                     {
  168.                         float curr = ENTITY::GET_ENTITY_SPEED(vehid());
  169.                         max_speed(vehid(), curr);
  170.                     }
  171.                     else
  172.                     {
  173.                         max_speed(vehid(), SecondMax);
  174.                     }
  175.                     if (speed > SecondMax - 1)
  176.                     {
  177.                         ShiftNow = true;
  178.                     }
  179.                     else
  180.                     {
  181.                         ShiftNow = false;
  182.                     }
  183.                 }
  184.                 else if (Gear3)
  185.                 {
  186.                     GearSc("3", 0.015, 0.015);
  187.                     if (speed > ThirdMax)
  188.                     {
  189.                         float curr = ENTITY::GET_ENTITY_SPEED(vehid());
  190.                         max_speed(vehid(), curr);
  191.                     }
  192.                     else
  193.                     {
  194.                         max_speed(vehid(), ThirdMax);
  195.                     }
  196.                     if (speed > ThirdMax - 1)
  197.                     {
  198.                         ShiftNow = true;
  199.                     }
  200.                     else
  201.                     {
  202.                         ShiftNow = false;
  203.                     }
  204.                 }
  205.                 else if (Gear4)
  206.                 {
  207.                     GearSc("4", 0.015, 0.015);
  208.                     max_speed(vehid(), 9999);
  209.                     ShiftNow = false;
  210.                 }
  211.                 else if (Reverse)
  212.                 {
  213.                     GearSc("R", 0.015, 0.015);
  214.                     max_speed(vehid(), 8.0f);
  215.                     CONTROLS::DISABLE_CONTROL_ACTION(2, 71, true);
  216.                     CONTROLS::DISABLE_CONTROL_ACTION(2, 72, true);
  217.                     if (get_key_pressed(Keys::W))
  218.                     {
  219.                         VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehid(), -4.1f);
  220.                     }
  221.                 }
  222.  
  223.                 if (isClutchDown)
  224.                 {
  225.                     if (get_key_pressed(Pressed.FirstGear))
  226.                     {
  227.                         Gear1 = true;
  228.                         Gear2 = false;
  229.                         Gear3 = false;
  230.                         Gear4 = false;
  231.                         Reverse = false;
  232.                         WAIT(50);
  233.                     }
  234.                     else if (get_key_pressed(Pressed.SecondGear))
  235.                     {
  236.                         Gear1 = false;
  237.                         Gear2 = true;
  238.                         Gear3 = false;
  239.                         Gear4 = false;
  240.                         Reverse = false;
  241.                         WAIT(50);
  242.                     }
  243.                     else if (get_key_pressed(Pressed.ThirdGear))
  244.                     {
  245.                         Gear1 = false;
  246.                         Gear2 = false;
  247.                         Gear3 = true;
  248.                         Gear4 = false;
  249.                         Reverse = false;
  250.                         WAIT(50);
  251.                     }
  252.                     else if (get_key_pressed(Pressed.FourthGear))
  253.                     {
  254.                         Gear1 = false;
  255.                         Gear2 = false;
  256.                         Gear3 = false;
  257.                         Gear4 = true;
  258.                         Reverse = false;
  259.                         WAIT(50);
  260.                     }
  261.                     else if (get_key_pressed(Pressed.Reverse))
  262.                     {
  263.                         Gear1 = false;
  264.                         Gear2 = false;
  265.                         Gear3 = false;
  266.                         Gear4 = false;
  267.                         Reverse = true;
  268.                         WAIT(50);
  269.                     }
  270.                 }
  271.  
  272.  
  273.                 if (Gear2 && speed <= FirstMax - 2.1f)
  274.                 {
  275.                     if (is_control_pressed(Gamepad::R2) || get_key_pressed(Keys::W))
  276.                     {
  277.                         VEHICLE::SET_VEHICLE_ENGINE_ON(vehid(), 0, 0);
  278.                     }
  279.                 }
  280.                 else if (Gear3 && speed <= SecondMax - 2.1f)
  281.                 {
  282.                     if (is_control_pressed(Gamepad::R2) || get_key_pressed(Keys::W))
  283.                     {
  284.                         VEHICLE::SET_VEHICLE_ENGINE_ON(vehid(), 0, 0);
  285.                     }
  286.                 }
  287.                 else if (Gear4 && speed <= ThirdMax - 2.1f)
  288.                 {
  289.                     if (is_control_pressed(Gamepad::R2) || get_key_pressed(Keys::W))
  290.                     {
  291.                         VEHICLE::SET_VEHICLE_ENGINE_ON(vehid(), 0, 0);
  292.                     }
  293.                 }
  294.  
  295.                 if (!Gear1 && VEHICLE::IS_VEHICLE_STOPPED(vehid()))
  296.                 {
  297.                     if (is_control_pressed(Gamepad::R2) || get_key_pressed(Keys::W))
  298.                     {
  299.                         VEHICLE::SET_VEHICLE_ENGINE_ON(vehid(), 0, 0);
  300.                     }
  301.                 }
  302.  
  303.  
  304.             }
  305.         }
  306.         else if (!MT || ENTITY::GET_ENTITY_MODEL(vehid()) == model)
  307.         {
  308.             max_speed(vehid(), 9999);
  309.             Gear1 = true, Gear2 = false, Gear3 = false, Gear4 = false, Reverse = false;
  310.         }
  311.         /*--------------*/
  312.         update_features();
  313.         WAIT(0);
  314.     }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement