Ghecco

Vehicle's Speed functions

Nov 13th, 2020 (edited)
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Km/h functions
  2.  
  3. #define FLOAT_INFINITY                  (Float:0x7F800000)
  4.  
  5.  
  6.  
  7. stock Float:GetVehicleSpeedFromVelocity(Float:x, Float:y, Float:z)
  8. {
  9.     return floatmul(VectorSize(x, y, z), 180.0);
  10. }
  11.  
  12. stock Float:GetVehicleSpeed(vehicleid)
  13. {
  14.     static
  15.         Float:x,
  16.         Float:y,
  17.         Float:z;
  18.  
  19.     return GetVehicleVelocity(vehicleid, x, y, z)
  20.         ? GetVehicleSpeedFromVelocity(x, y, z)
  21.         : FLOAT_INFINITY;
  22. }
  23.  
  24. stock SetVehicleSpeed(vehicleid, Float:speed)
  25. {
  26.     new
  27.         Float:x,
  28.         Float:y,
  29.         Float:z;
  30.  
  31.     if (GetVehicleVelocity(vehicleid, x, y, z))
  32.     {
  33.         new
  34.             Float:angle;
  35.  
  36.         GetVehicleVelocity(vehicleid, x, y, z);
  37.         GetVehicleZAngle(vehicleid, angle);
  38.  
  39.         speed = floatdiv(speed, 180.0);
  40.    
  41.  
  42.         x = floatmul(speed, floatsin(-angle, degrees));
  43.         y = floatmul(speed, floatcos(-angle, degrees));
  44.  
  45.         SetVehicleVelocity(vehicleid, x, y, z);
  46.     }
  47.     return 0;
  48. }
RAW Paste Data