zulao

cruise control by zulao

Jun 20th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1.  
  2. /*
  3. ZZZZZZZZZ ZZ ZZ
  4. Z ZZ ZZ ZZ
  5. Z ZZ ZZZZZ
  6. ZZZZZZZZZZZZ Z
  7. Z ZZ Z
  8. Z ZZ Z
  9. ZZZZZZZZZ Z
  10.  
  11. ZZZZZZZZZZZZZ Z Z Z ZZZZZZZZZZZZZ ZZZZZZZZZZZZZ
  12. ZZ Z Z Z Z Z Z Z
  13. ZZ Z Z Z Z Z Z Z
  14. ZZ Z Z Z Z Z Z Z
  15. ZZ Z Z Z ZZZZZZZZZZZZZ Z Z
  16. ZZ Z Z Z Z Z Z Z
  17. ZZ Z Z Z Z Z Z Z
  18. ZZZZZZZZZZZZZ ZZZZZZZZZZZZZ ZZZZZZZZZZZZZ Z Z ZZZZZZZZZZZZZ
  19. -------------------------------------------------| @@@@@@@@@@ BY ZULAO @@@@@@@@@@ |---------------------------------------------------------------------------
  20.  
  21. */
  22. #include <a_samp>
  23. #include <sscanf2>
  24. #include <zcmd>
  25. #undef MAX_PLAYERS
  26. #define MAX_PLAYERS 100
  27. #define UPDATE_RATE 50
  28. #define CCKey KEY_ACTION
  29.  
  30. new bool: cc[MAX_PLAYERS char];
  31. new Float: ccspeed[MAX_PLAYERS];
  32.  
  33. public OnPlayerConnect(playerid)
  34. {
  35. cc{playerid} = false;
  36. ccspeed[playerid] = 0.1;
  37. return 1;
  38. }
  39.  
  40. CMD:cc(playerid,params[])
  41. {
  42. new Float: value;
  43. if(!sscanf(params,"f", value))
  44. {
  45. if(value < 0.05 || value > 0.15) return SendClientMessage(playerid,-1, "Valor da velocidade inválida! Limite de 0.05 até 0.15!");
  46. ccspeed[playerid] = value;
  47. new string[128];
  48. format(string,sizeof(string),"Você setou o valor da velocidade para %.2f!", ccspeed[playerid]);
  49. return SendClientMessage(playerid,-1, string);
  50. }
  51. if(cc{playerid})
  52. {
  53. cc{playerid} = false;
  54. return SendClientMessage(playerid,-1, "Você desabilitou o mode de Cruise Control!");
  55. }
  56. else
  57. {
  58. cc{playerid} = true;
  59. return SendClientMessage(playerid,-1, "Você ativou o mode de Cruise Control! Precione a tecla CTRL para andar com o veículo no modo Cruise Control. Use /cc [valor] para alterar a velocidade.");
  60. }
  61.  
  62. }
  63.  
  64. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  65. {
  66. if(cc{playerid})
  67. {
  68. if(newkeys & CCKey) ccf(playerid);
  69. {
  70. new Float: x, Float:y, Float:z;
  71. GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);
  72. }
  73. }
  74. return 1;
  75. }
  76.  
  77. forward ccf(playerid);
  78. public ccf(playerid)
  79. {
  80. new keys, ud, lr;
  81. GetPlayerKeys(playerid, keys, ud, lr);
  82. if((keys & CCKey))
  83. {
  84. new Float: adirection[3];
  85. new vehid = GetPlayerVehicleID(playerid);
  86. new Float:Quaternion[4];
  87. new Float:transformationmatrix[4][4];
  88.  
  89. GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
  90.  
  91. new Float:xx = Quaternion[0] * Quaternion[0];
  92. new Float:xy = Quaternion[0] * Quaternion[1];
  93. new Float:xz = Quaternion[0] * Quaternion[2];
  94. new Float:xw = Quaternion[0] * Quaternion[3];
  95. new Float:yy = Quaternion[1] * Quaternion[1];
  96. new Float:yz = Quaternion[1] * Quaternion[2];
  97. new Float:yw = Quaternion[1] * Quaternion[3];
  98. new Float:zz = Quaternion[2] * Quaternion[2];
  99. new Float:zw = Quaternion[2] * Quaternion[3];
  100.  
  101. transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
  102. transformationmatrix[0][1] = 2 * ( xy - zw );
  103. transformationmatrix[0][2] = 2 * ( xz + yw );
  104. transformationmatrix[0][3] = 0.0;
  105.  
  106. transformationmatrix[1][0] = 2 * ( xy + zw );
  107. transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
  108. transformationmatrix[1][2] = 2 * ( yz - xw );
  109. transformationmatrix[1][3] = 0.0;
  110.  
  111. transformationmatrix[2][0] = 2 * ( xz - yw );
  112. transformationmatrix[2][1] = 2 * ( yz + xw );
  113. transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
  114. transformationmatrix[2][3] = 0;
  115.  
  116. transformationmatrix[3][0] = 0;
  117. transformationmatrix[3][1] = 0;
  118. transformationmatrix[3][2] = 0;
  119. transformationmatrix[3][3] = 1;
  120.  
  121. adirection[2] = -1 * transformationmatrix[0][1] + transformationmatrix[0][3];
  122. adirection[1] = -1 * transformationmatrix[1][1] + transformationmatrix[1][3];
  123. adirection[0] = -(-1 * transformationmatrix[2][1] + transformationmatrix[2][3]);
  124.  
  125. SetVehicleVelocity(vehid, adirection[0]*ccspeed[playerid], adirection[1]*ccspeed[playerid], adirection[2]*ccspeed[playerid]);
  126. SetTimerEx("ccf", UPDATE_RATE, false, "i", playerid);
  127. }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment