Guest User

[FS] Cruise Control/Flying Car Mode (no jump mode)

a guest
Nov 20th, 2011
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2> //Credits to Y_Less (http://forum.sa-mp.com/showthread.php?t=120356)
  3. #include <zcmd> //Credits to Zeex (http://forum.sa-mp.com/showthread.php?t=91354)
  4. #define COLOR_RED 0xAA3333AA
  5. #define COLOR_YELLOW 0xFFFF00AA
  6. #undef MAX_PLAYERS
  7. #define MAX_PLAYERS 100 //number of server slots
  8. #define UPDATE_RATE 50 //define update rate of vehicle speed (milliseconds); lower values might cause lag; higher values causes not constant vehicle speed
  9. #define CCKey KEY_ACTION //define key for CC mode
  10. #define AutoRepair 1 //autorepair vehicle while using CC mode: on - 1; off - 0
  11. //Speedboost functions were found at http://forum.sa-mp.com/showthread.php?t=199628 tutorial by The_Gangstas
  12.  
  13. new bool: cc[MAX_PLAYERS char];
  14. new Float: ccspeed[MAX_PLAYERS];
  15.  
  16. public OnFilterScriptInit()
  17. {
  18. for(new i=0; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i)) OnPlayerConnect(i);
  19. return print("Cruise Control/Flying Car Mode by Riccor loaded!");
  20. }
  21.  
  22. public OnPlayerConnect(playerid)
  23. {
  24. cc{playerid} = false;
  25. ccspeed[playerid] = 0.1;
  26. return 1;
  27. }
  28.  
  29. CMD:cc(playerid,params[])
  30. {
  31. new Float: value;
  32. if(!sscanf(params,"f", value))
  33. {
  34. if(value < 0.05 || value > 3.0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] Invalid Speed Value! [0.05-3.0]");
  35. ccspeed[playerid] = value;
  36. new string[128];
  37. format(string,sizeof(string),":: You setted CC Speed Value to %.2f!", ccspeed[playerid]);
  38. return SendClientMessage(playerid, COLOR_YELLOW, string);
  39. }
  40. if(cc{playerid})
  41. {
  42. cc{playerid} = false;
  43. return SendClientMessage(playerid, COLOR_RED, ":: You disabled CC mode!");
  44. }
  45. else
  46. {
  47. cc{playerid} = true;
  48. return SendClientMessage(playerid, COLOR_YELLOW, ":: You enabled CC mode! Press and hold CTRL key while driving to use it. Use /cc [value] to change CC speed.");
  49. }
  50. }
  51.  
  52. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  53. {
  54. if(cc{playerid} && newkeys & CCKey) ccf(playerid);
  55. return 1;
  56. }
  57.  
  58. forward ccf(playerid);
  59. public ccf(playerid)
  60. {
  61. new keys, ud, lr;
  62. GetPlayerKeys(playerid, keys, ud, lr);
  63. if((keys & CCKey))
  64. {
  65. new Float: adirection[3];
  66. new vehid = GetPlayerVehicleID(playerid);
  67. new Float:Quaternion[4];
  68. new Float:transformationmatrix[4][4];
  69.  
  70. GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
  71.  
  72. new Float:xx = Quaternion[0] * Quaternion[0];
  73. new Float:xy = Quaternion[0] * Quaternion[1];
  74. new Float:xz = Quaternion[0] * Quaternion[2];
  75. new Float:xw = Quaternion[0] * Quaternion[3];
  76. new Float:yy = Quaternion[1] * Quaternion[1];
  77. new Float:yz = Quaternion[1] * Quaternion[2];
  78. new Float:yw = Quaternion[1] * Quaternion[3];
  79. new Float:zz = Quaternion[2] * Quaternion[2];
  80. new Float:zw = Quaternion[2] * Quaternion[3];
  81.  
  82. transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
  83. transformationmatrix[0][1] = 2 * ( xy - zw );
  84. transformationmatrix[0][2] = 2 * ( xz + yw );
  85. transformationmatrix[0][3] = 0.0;
  86.  
  87. transformationmatrix[1][0] = 2 * ( xy + zw );
  88. transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
  89. transformationmatrix[1][2] = 2 * ( yz - xw );
  90. transformationmatrix[1][3] = 0.0;
  91.  
  92. transformationmatrix[2][0] = 2 * ( xz - yw );
  93. transformationmatrix[2][1] = 2 * ( yz + xw );
  94. transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
  95. transformationmatrix[2][3] = 0;
  96.  
  97. transformationmatrix[3][0] = 0;
  98. transformationmatrix[3][1] = 0;
  99. transformationmatrix[3][2] = 0;
  100. transformationmatrix[3][3] = 1;
  101.  
  102. adirection[2] = -1 * transformationmatrix[0][1] + transformationmatrix[0][3];
  103. adirection[1] = -1 * transformationmatrix[1][1] + transformationmatrix[1][3];
  104. adirection[0] = -(-1 * transformationmatrix[2][1] + transformationmatrix[2][3]);
  105.  
  106. #if AutoRepair == 1
  107. RepairVehicle(vehid);
  108. #endif
  109.  
  110. SetVehicleVelocity(vehid, adirection[0]*ccspeed[playerid], adirection[1]*ccspeed[playerid], adirection[2]*ccspeed[playerid]);
  111. SetTimerEx("ccf", UPDATE_RATE, false, "i", playerid);
  112. }
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment