VPP.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. ---------------------------------------
  3. VehiclePartPosition
  4. @author: Ino
  5. @version: 1.0.0
  6. @release: 30/10/2016
  7. @build: 2
  8. @download: github.com/Ino42O/VehiclePartPosition
  9. ---------------------------------------
  10. Functions list:
  11. * GetXYZOfVehiclePart(vehicleid, part, &Float:x, &Float:y, &Float:z, Float:offset = 0.5);
  12. Changelog:
  13. 30-10-2016:
  14. * Initial release
  15. 31-10-2016:
  16. * Support ColAndreas to get more informations if vehicle is not on flat ground
  17. Available types:
  18. * VEHICLE_PART_RFTIRE
  19. * VEHICLE_PART_LFTIRE
  20. * VEHICLE_PART_RRTIRE
  21. * VEHICLE_PART_LRTIRE
  22. * VEHICLE_PART_HOOD
  23. * VEHICLE_PART_TRUNK
  24. ---------------------------------------
  25. */
  26. #include <a_samp>
  27. #define _INC_VEHPARTS
  28. #define VEHICLE_PART_RFTIRE (1)
  29. #define VEHICLE_PART_LFTIRE (2)
  30. #define VEHICLE_PART_RRTIRE (3)
  31. #define VEHICLE_PART_LRTIRE (4)
  32. #define VEHICLE_PART_HOOD (5)
  33. #define VEHICLE_PART_TRUNK (6)
  34. stock GetXYZOfVehiclePart(vehicleid, part, &Float:x, &Float:y, &Float:z, Float:offset = 0.5)
  35. {
  36. #if defined COLANDREAS
  37. new Float:cz;
  38. #endif
  39. new Float:X, Float:Y, Float:Z, Float:A;
  40. GetVehiclePos(vehicleid, x, y, z);
  41. GetVehicleZAngle(vehicleid, A);
  42. switch(part)
  43. {
  44. case VEHICLE_PART_RFTIRE: // Right Front tire
  45. {
  46. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_WHEELSFRONT, X, Y, Z);
  47. x += ( ( (X + offset) * floatsin( -A + 90.0, degrees ) ) + ( ( Y * floatsin( -A, degrees ) ) ) );
  48. y += ( ( (X + offset) * floatcos( -A + 90.0, degrees ) ) + ( ( Y * floatcos( -A, degrees ) ) ) );
  49. #if defined COLANDREAS
  50. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  51. if (cz != 0.0)
  52. z = cz + offset;
  53. #endif
  54. }
  55. case VEHICLE_PART_LFTIRE: // Left Front tire
  56. {
  57. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_WHEELSFRONT, X, Y, Z);
  58. x += ( ( (X + offset) * floatsin( -A - 90.0, degrees ) ) + ( ( Y * floatsin( -A, degrees ) ) ) );
  59. y += ( ( (X + offset) * floatcos( -A - 90.0, degrees ) ) + ( ( Y * floatcos( -A, degrees ) ) ) );
  60. #if defined COLANDREAS
  61. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  62. if (cz != 0.0)
  63. z = cz + offset;
  64. #endif
  65. }
  66. case VEHICLE_PART_RRTIRE: // Right Rear tire
  67. {
  68. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_WHEELSREAR, X, Y, Z);
  69. x += ( ( (X + offset) * floatsin( -A + 90.0, degrees ) ) + ( ( Y * floatsin( -A, degrees ) ) ) );
  70. y += ( ( (X + offset) * floatcos( -A + 90.0, degrees ) ) + ( ( Y * floatcos( -A, degrees ) ) ) );
  71. #if defined COLANDREAS
  72. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  73. if (cz != 0.0)
  74. z = cz + offset;
  75. #endif
  76. }
  77. case VEHICLE_PART_LRTIRE: // Left Rear tire
  78. {
  79. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_WHEELSREAR, X, Y, Z);
  80. x += ( ( (X + offset) * floatsin( -A - 90.0, degrees ) ) + ( ( Y * floatsin( -A, degrees ) ) ) );
  81. y += ( ( (X + offset) * floatcos( -A - 90.0, degrees ) ) + ( ( Y * floatcos( -A, degrees ) ) ) );
  82. #if defined COLANDREAS
  83. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  84. if (cz != 0.0)
  85. z = cz + offset;
  86. #endif
  87. }
  88. case VEHICLE_PART_HOOD: // In Front
  89. {
  90. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, X, Y, Z);
  91. x += ( (Y / 2.0 + offset) * floatsin( -A, degrees ) );
  92. y += ( (Y / 2.0 + offset) * floatcos( -A, degrees ) );
  93. #if defined COLANDREAS
  94. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  95. if (cz != 0.0)
  96. z = cz + offset;
  97. #endif
  98. }
  99. case VEHICLE_PART_TRUNK: // Behind
  100. {
  101. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, X, Y, Z);
  102. x += ( (Y / 2.0 + offset) * floatsin( -A + 180, degrees ) );
  103. y += ( (Y / 2.0 + offset) * floatcos( -A + 180, degrees ) );
  104. #if defined COLANDREAS
  105. CA_RayCastLine(x, y, z, x, y, z + 5.0, cz, cz, cz);
  106. if (cz != 0.0)
  107. z = cz + offset;
  108. #endif
  109. }
  110. }
  111. }