SHARE
TWEET

M-Gear v1.1

a guest Feb 4th, 2014 565 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3.  
  4. // UPDATE v1.1 Plane not have gears ( reported by Hiddos )
  5.  
  6. #define FILTERSCRIPT
  7.  
  8. #include <a_samp> // thanks to samp team
  9.  
  10. #define PRESSED(%0) \
  11.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  12.        
  13. #define SpeedCheck(%0,%1,%2,%3,%4) floatround(floatsqroot(%4?(%0*%0+%1*%1+%2*%2):(%0*%0+%1*%1) ) *%3*1.6) // i dunno who made this
  14.  
  15. new GearLimit[MAX_PLAYERS];
  16. new Gear[MAX_VEHICLES];
  17. new Text:Geartxd[MAX_PLAYERS];
  18.  
  19. #define MAX_GEAR 4
  20. #define VEHICLE_GEAR_SPEED 30 //use this to set the gear max speed ( speed = Gear[vehicleid] * VEHICLE_GEAR_SPEED )
  21.  
  22. #if defined FILTERSCRIPT
  23.  
  24. public OnFilterScriptInit()
  25. {
  26.         print("\n--------------------------------------");
  27.         print(" MANUAL TRANSMISSION BY MAHAR!  LOADED  ");
  28.         print("--------------------------------------\n");
  29.         return 1;
  30. }
  31.  
  32. public OnFilterScriptExit()
  33. {
  34.         print("\n--------------------------------------");
  35.         print(" MANUAL TRANSMISSION BY MAHAR! UNLOADED ");
  36.         print("--------------------------------------\n");
  37.         return 1;
  38. }
  39.  
  40. #else
  41.  
  42. main()
  43. {
  44.    return 1;
  45. }
  46.  
  47. #endif
  48.  
  49. public OnGameModeInit()
  50. {
  51.         return 1;
  52. }
  53.  
  54. public OnGameModeExit()
  55. {
  56.         return 1;
  57. }
  58.  
  59. public OnPlayerRequestClass(playerid, classid)
  60. {
  61.         return 1;
  62. }
  63.  
  64. public OnPlayerConnect(playerid)
  65. {
  66.     Geartxd[playerid] = TextDrawCreate(478,413,"_"); // the gear textdraw
  67.         TextDrawLetterSize(Geartxd[playerid],0.37,1.099999);
  68.         TextDrawSetOutline(Geartxd[playerid],1);
  69.     GearLimit[playerid] = 0;
  70.         return 1;
  71. }
  72.  
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75.     TextDrawDestroy(Geartxd[playerid]);
  76.     GearLimit[playerid] = 0;
  77.         return 1;
  78. }
  79.  
  80. public OnPlayerSpawn(playerid)
  81. {
  82.     GearLimit[playerid] = 0;
  83.         return 1;
  84. }
  85.  
  86. public OnPlayerDeath(playerid, killerid, reason)
  87. {
  88.     GearLimit[playerid] = 0;
  89.         return 1;
  90. }
  91.  
  92. public OnVehicleSpawn(vehicleid)
  93. {
  94.     Gear[vehicleid] = 0;
  95.         return 1;
  96. }
  97.  
  98. public OnVehicleDeath(vehicleid, killerid)
  99. {
  100.     Gear[vehicleid] = 0;
  101.         return 1;
  102. }
  103.  
  104. public OnPlayerText(playerid, text[])
  105. {
  106.         return 1;
  107. }
  108.  
  109. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  110. {
  111.         GearLimit[playerid] = Gear[vehicleid] * 20;
  112.         if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510)
  113.         {
  114.             GearLimit[playerid] = 999;
  115.         }
  116.         return 1;
  117. }
  118.  
  119. public OnPlayerExitVehicle(playerid, vehicleid)
  120. {
  121.     GearLimit[playerid] = 0;
  122.         return 1;
  123. }
  124.  
  125. public OnPlayerStateChange(playerid, newstate, oldstate)
  126. {
  127.         return 1;
  128. }
  129.  
  130. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  131. {
  132.     if (PRESSED(KEY_YES)) // Gear UP
  133.         {
  134.                 new string[128];
  135.                 if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510) return GameTextForPlayer(playerid, "~n~~r~ This Vhicle Doesnt Have Engine", 1000, 2);
  136.             if(Gear[GetPlayerVehicleID(playerid)] <= MAX_GEAR)
  137.             {
  138.                
  139.                 Gear[GetPlayerVehicleID(playerid)] ++;
  140.                 format(string, sizeof(string), "~n~~w~Vehicle Gear ~r~( ~g~%d ~r~)", Gear[GetPlayerVehicleID(playerid)]);
  141.                 GameTextForPlayer(playerid, string, 3000, 3);
  142.                 }
  143.                 else
  144.                 {
  145.                 GameTextForPlayer(playerid, "~n~~r~ Max Vehicle Gear", 3000, 3);
  146.                 }
  147.         }
  148.         if (PRESSED(KEY_NO)) // Gear Down
  149.         {
  150.                 new string[128];
  151.                 if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510) return GameTextForPlayer(playerid, "~n~~r~ This Vhicle Doesnt Have Engine", 1000, 2);
  152.             if(Gear[GetPlayerVehicleID(playerid)] > -1)
  153.             {
  154.                 Gear[GetPlayerVehicleID(playerid)] --;
  155.                 format(string, sizeof(string), "~w~Vehicle Gear ~r~( ~g~%d ~r~)", Gear[GetPlayerVehicleID(playerid)]);
  156.                 if(Gear[GetPlayerVehicleID(playerid)] == -1)
  157.                 {
  158.                     format(string, sizeof(string), "~w~Vehicle Gear ~r~( ~g~R ~r~)");
  159.                         }
  160.                 GameTextForPlayer(playerid, string, 3000, 3);
  161.                 }
  162.         }
  163.         return 1;
  164. }
  165. stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
  166. {
  167.         new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
  168.         GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
  169.         DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
  170.         if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
  171.         {
  172.                 multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
  173.                 return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
  174.         }
  175.         return 0;
  176. }
  177.  
  178. stock IsVehicleDrivingBackwards(vehicleid) // By Joker
  179. {
  180.         new
  181.                 Float:Float[3]
  182.         ;
  183.         if(GetVehicleVelocity(vehicleid, Float[1], Float[2], Float[0]))
  184.         {
  185.                 GetVehicleZAngle(vehicleid, Float[0]);
  186.                 if(Float[0] < 90)
  187.                 {
  188.                         if(Float[1] > 0 && Float[2] < 0) return true;
  189.                 }
  190.                 else if(Float[0] < 180)
  191.                 {
  192.                         if(Float[1] > 0 && Float[2] > 0) return true;
  193.                 }
  194.                 else if(Float[0] < 270)
  195.                 {
  196.                         if(Float[1] < 0 && Float[2] > 0) return true;
  197.                 }
  198.                 else if(Float[1] < 0 && Float[2] < 0) return true;
  199.         }
  200.         return false;
  201. }
  202.  
  203. stock GetVehicleSpeed(vehicleid, get3d)
  204. {
  205.         new Float:x, Float:y, Float:z;
  206.         GetVehicleVelocity(vehicleid, x, y, z);
  207.         return SpeedCheck(x, y, z, 100.0, get3d);
  208. }
  209.  
  210. IsAPlane(carid)
  211. {
  212.         switch(GetVehicleModel(carid)) {
  213.                 case 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469: return 1;
  214.         }
  215.         return 0;
  216. }
  217.  
  218. public OnPlayerUpdate(playerid)
  219. {
  220.         new string[128];
  221.     GearLimit[playerid] = Gear[GetPlayerVehicleID(playerid)] * VEHICLE_GEAR_SPEED;
  222.     if(Gear[GetPlayerVehicleID(playerid)] == -1)
  223.         {
  224.             GearLimit[playerid] = 0;
  225.         }
  226.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  227.         {
  228.                 new a, b, c;
  229.                 GetPlayerKeys(playerid, a, b ,c);
  230.                 if(IsVehicleDrivingBackwards(GetPlayerVehicleID(playerid)))
  231.                 {
  232.                         if(Gear[GetPlayerVehicleID(playerid)] == -1)
  233.                         {
  234.                             return 1;
  235.                         }
  236.                         else
  237.                         {
  238.                         ModifyVehicleSpeed(GetPlayerVehicleID(playerid), - GetVehicleSpeed(GetPlayerVehicleID(playerid), 0));
  239.                         }
  240.                 }
  241.                 if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > GearLimit[playerid])
  242.                 {
  243.                     if(IsVehicleDrivingBackwards(GetPlayerVehicleID(playerid)))
  244.                         {
  245.                                 if(Gear[GetPlayerVehicleID(playerid)] != -1) return ModifyVehicleSpeed(GetPlayerVehicleID(playerid), - GetVehicleSpeed(GetPlayerVehicleID(playerid), 0));
  246.                         }
  247.                         if(!IsVehicleDrivingBackwards(GetPlayerVehicleID(playerid)))
  248.                         {
  249.                                 if(Gear[GetPlayerVehicleID(playerid)] == -1) return ModifyVehicleSpeed(GetPlayerVehicleID(playerid), - GetVehicleSpeed(GetPlayerVehicleID(playerid), 0));
  250.                         }
  251.                 new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - GearLimit[playerid];
  252.                 ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
  253.                 }
  254.                 if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) != 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) != 510 || !IsAPlane(GetPlayerVehicleID(playerid)))
  255.                 {
  256.                         if(IsPlayerConnected(playerid) && IsPlayerInAnyVehicle(playerid))
  257.                         {
  258.                                 TextDrawShowForPlayer(playerid,Geartxd[playerid]);
  259.                                 format(string,sizeof(string),"Gear: %d",Gear[GetPlayerVehicleID(playerid)]);
  260.                                 if(Gear[GetPlayerVehicleID(playerid)] == -1)
  261.                                 {
  262.                                     format(string,sizeof(string),"Gear: R");
  263.                                 }
  264.                                 TextDrawSetString(Geartxd[playerid],string);
  265.                         }
  266.                 }
  267.                 else if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 481 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510 || !IsAPlane(GetPlayerVehicleID(playerid)))
  268.                 {
  269.                     GearLimit[playerid] = 999;
  270.                 }
  271.                 return 1;
  272.         }
  273.         if(!IsPlayerInAnyVehicle(playerid))
  274.         {
  275.                 TextDrawHideForPlayer(playerid,Geartxd[playerid]);
  276.         }
  277.         return 1;
  278. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top