useful.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Function list;
  2. • IsPlayerFacingPoint
  3. • GetPointDistanceToPointExMorph
  4. • IsPointInRangeOfPoint
  5. • AddThousandsSeparators
  6. • GetNameFomSQLID
  7. */
  8. /* Checks if the player is in range of a given point by distance,
  9. and checks if the player is facing the point.
  10. */
  11. stock IsPlayerFacingPoint( playerid, Float: distance, Float: X, Float: Y, Float: Z, Float: error ) {
  12. if( !IsPlayerInRangeOfPoint( playerid, distance, X, Y, Z ) ) {
  13. return false;
  14. }
  15. new Float: angle, Float: misc = 5.0, Float: playerX, Float: playerY, Float: playerZ, Float: tarangle;
  16. GetPlayerFacingAngle( playerid, angle );
  17. GetPlayerPos( playerid, playerX, playerY, playerZ );
  18. tarangle = 180.0 -atan2( playerX - X, playerY - Y ) + misc;
  19. if( angle < tarangle + error && angle > tarangle - error ) {
  20. return true;
  21. }
  22. return false;
  23. }
  24. Float:GetPointDistanceToPointExMorph(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  25. {
  26. new Float:x, Float:y, Float:z;
  27. x = x1 -x2;
  28. y = y1 -y2;
  29. z = z1 -z2;
  30. return floatsqroot(x *x +y *y +z *z);
  31. }
  32. IsPointInRangeOfPoint(Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:z2, Float:range)
  33. {
  34. x2 -= x;
  35. y2 -= y;
  36. z2 -= z;
  37. return ((x2 * x2) + (y2 * y2) + (z2 * z2)) < (range * range);
  38. }
  39. /*
  40. Seperates numbers larger then 1,000 with a comma
  41. */
  42. AddThousandsSeparators(number, const separator[] = ",")
  43. {
  44. new output[15]; // longest possible output given 32 bit integers: -2,147,483,648
  45. format(output, sizeof(output), "%d", number);
  46. for(new i = strlen(output) - 3; i > 0 && output[i-1] != '-'; i -= 3)
  47. {
  48. strins(output, separator, i);
  49. }
  50. return output;
  51. }
  52. stock GetPosAheadVehicle(vehicleid, &Float:x, &Float:y, &Float:z, Float:offset =0.5)
  53. {
  54. new Float:vehicleSize[3], Float:vehiclePos[3];
  55. GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
  56. GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, vehicleSize[0], vehicleSize[1], vehicleSize[2]);
  57. GetXYAheadVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1] /2) +offset);
  58. x = vehiclePos[0];
  59. y = vehiclePos[1];
  60. z = vehiclePos[2];
  61. return 1;
  62. }
  63. GetXYAheadVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
  64. {
  65. new Float:a;
  66. GetVehiclePos(vehicleid, q, w, a);
  67. GetVehicleZAngle(vehicleid, a);
  68. q -= (distance * -floatsin(-a, degrees));
  69. w -= (distance * -floatcos(-a, degrees));
  70. }
  71. /*
  72. Gets a players name from their SQL ID
  73. GetNameFomSQLID(sqlid)
  74. {
  75. new query[128], name[MAX_PLAYER_NAME];
  76. mysql_format(sqlGameConnection, query, sizeof(query), "SELECT name FROM `players` WHERE ID = %d LIMIT 1", sqlid);
  77. new Cache:result = mysql_query(sqlGameConnection, query);
  78. cache_get_field_content(0, "name", name, sqlGameConnection, 24);
  79. cache_delete(result);
  80. return name;
  81. }*/