Advertisement
frog163

speed_control.inc

Nov 23rd, 2012
46
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**['Скоростной' инклуд ;)  ]**
  2. *   Автор: Frog163         ***
  3. *   Релиз: 12/04/2012      ***
  4. ******************************/
  5. #if defined _fspeed
  6.     #endinput
  7. #endif
  8. #define _fspeed
  9. /*
  10. fGetPlayerSpeed(int player[, bool return_km=true])
  11.         вернет скорость игрока в км/ч, если return_km=false то в mph
  12.        
  13. fGetVehicleSpeed(int vehicle[, bool return_km=true])
  14.         вернет скорость машины в км/ч, если return_km=false то в mph
  15.        
  16. sSetVehicleSpeed(int vehicle, int speed)
  17.         установит машине(vehicle) скорость: speed км/ч
  18.         (не учитывает ротацию)
  19.        
  20. fSetVehicleSpeed(int vehicle, int speed[, bool convert_km=true])
  21.         установит машине(vehicle) скорость: speed км/ч
  22.         если return_km=false то в mph
  23.         (учитывает ротацию)
  24.        
  25. fSetVehicleBoost(int vehicle[, int boost = 50[, int max_speed = 400[, bool convert_km = true]]])
  26.         ускорит машину(vehicle) на 50 км/ч, при этом скорость не привысит 400 км/ч
  27.         если return_km=false то скорость указывается в mph
  28.         (учитывает ротацию)
  29. */
  30. stock fGetPlayerSpeed(player, bool:return_km=true){//by Frog163
  31.     new Float:x, Float:y, Float:z;
  32.     GetPlayerVelocity(player, x, y, z);
  33.     return return_km?floatround(floatsqroot(x*x+y*y+z*z)*200):floatround(floatsqroot(x*x+y*y+z*z)*123.5);
  34. }
  35. stock fGetVehicleSpeed(vehicle, bool:return_km=true){//by Frog163
  36.     new Float:x, Float:y, Float:z;
  37.     GetVehicleVelocity(vehicle, x, y, z);
  38.     return return_km?floatround(floatsqroot(x*x+y*y+z*z)*200):floatround(floatsqroot(x*x+y*y+z*z)*123.5);
  39. }
  40. stock sSetVehicleSpeed(vehicle, speed){//by Frog163
  41.     new Float:sx, Float:sy, Float:sa;
  42.     GetVehicleZAngle(vehicle, sa);
  43.     sx = speed/200.0 * floatsin(-sa, degrees);
  44.     sy = speed/200.0 * floatcos(-sa, degrees);
  45.     return SetVehicleVelocity(vehicle, sx, sy, 0.0);
  46. }
  47. stock fSetVehicleSpeed(vehicle, speed, bool:convert_km=true){//by Frog163
  48.     if(!speed)return SetVehicleVelocity(vehicle, 0.0, 0.0, 0.0);
  49.     new Float:sx, Float:sy, Float:sz, Float:smode;
  50.     if(convert_km)smode=200.0;
  51.     else smode=123.5;
  52.     new Float:invector[3] = {0.0, -1.0, 0.0};
  53.     RotatePointVehicleRotation(vehicle, invector, sx, sy, sz);
  54.     new Float:fk = floatabs(float(speed)/smode);
  55.     return speed<0?SetVehicleVelocity(vehicle, -sx*fk, -sy*fk, -sz*fk):SetVehicleVelocity(vehicle, sx*fk, sy*fk, sz*fk);
  56. }
  57. stock fSetVehicleBoost(vehicle, boost=50, max_speed = 400, bool:convert_km=true){//by Frog163
  58.     new Float:sx,Float:sy,Float:sz, Float:speed, Float:smode;
  59.     if(convert_km)smode=200.0;
  60.     else smode=123.5;
  61.     GetVehicleVelocity(vehicle, sx, sy, sz);
  62.     speed=floatsqroot(sx*sx+sy*sy+sz*sz)*smode;
  63.     if(speed+boost < max_speed)speed += boost;
  64.     else if(speed < max_speed)speed = max_speed;
  65.     new Float:invector[3] = {0.0, -1.0, 0.0};
  66.     RotatePointVehicleRotation(vehicle, invector, sx, sy, sz);
  67.     new Float:fk = floatabs(float(speed)/smode);
  68.     SetVehicleVelocity(vehicle, sx*speed, sy*speed, sz*speed);
  69.     return true;
  70. }
  71. stock MatrixTransformVector(Float:vector[3], Float:m[4][4], &Float:resx, &Float:resy, &Float:resz){//by JernejL
  72.     resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
  73.     resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
  74.     resx = -(vector[2] * m[2][0] + vector[1] * m[2][1] + vector[0] * m[2][2] + m[2][3]);// don't ask why -x was needed, i don't know either.
  75. }
  76. stock RotatePointVehicleRotation(vehid, Float:Invector[3], &Float:resx, &Float:resy, &Float:resz, worldspace=0){//by JernejL
  77.     new Float:Quaternion[4];
  78.     new Float:transformationmatrix[4][4];
  79.  
  80.     GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
  81.  
  82.     // build a transformation matrix out of the quaternion
  83.     new Float:xx = Quaternion[0] * Quaternion[0];
  84.     new Float:xy = Quaternion[0] * Quaternion[1];
  85.     new Float:xz = Quaternion[0] * Quaternion[2];
  86.     new Float:xw = Quaternion[0] * Quaternion[3];
  87.     new Float:yy = Quaternion[1] * Quaternion[1];
  88.     new Float:yz = Quaternion[1] * Quaternion[2];
  89.     new Float:yw = Quaternion[1] * Quaternion[3];
  90.     new Float:zz = Quaternion[2] * Quaternion[2];
  91.     new Float:zw = Quaternion[2] * Quaternion[3];
  92.  
  93.     transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
  94.     transformationmatrix[0][1] =     2 * ( xy - zw );
  95.     transformationmatrix[0][2] =     2 * ( xz + yw );
  96.     transformationmatrix[0][3] = 0.0;
  97.  
  98.     transformationmatrix[1][0] =     2 * ( xy + zw );
  99.     transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
  100.     transformationmatrix[1][2] =     2 * ( yz - xw );
  101.     transformationmatrix[1][3] = 0.0;
  102.  
  103.     transformationmatrix[2][0] =     2 * ( xz - yw );
  104.     transformationmatrix[2][1] =     2 * ( yz + xw );
  105.     transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
  106.     transformationmatrix[2][3] = 0;
  107.  
  108.     transformationmatrix[3][0] = 0;
  109.     transformationmatrix[3][1] = 0;
  110.     transformationmatrix[3][2] = 0;
  111.     transformationmatrix[3][3] = 1;
  112.     // transform the point thru car's rotation
  113.     MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
  114.     // if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
  115.     if (worldspace == 1){
  116.         new Float:fX, Float:fY, Float:fZ;
  117.         GetVehiclePos(vehid, fX, fY, fZ);
  118.         resx += fX;
  119.         resy += fY;
  120.         resz += fZ;
  121.     }
  122. }
Advertisement
RAW Paste Data Copied
Advertisement