1
0

airbreak.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * airbreak.inc - Airbreak detection!
  3. * Created by Emmet of SA-MP forums.
  4. *
  5. * Notes:
  6. * This will need a lot of testing. This wasn't tested thoroughly.
  7. * There is a callback that is called when a player airbreaks.
  8. *
  9. * This Source Code Form is subject to the terms of the Mozilla Public
  10. * License, v. 2.0. If a copy of the MPL was not distributed with this
  11. * file, You can obtain one at [url]http://mozilla.org/MPL/2.0/[/url].
  12. *
  13. * You may not sell this include.
  14. * You may not claim this as your own.
  15. * You may not redistribute without permission.
  16. * You are free to do anything else with it.
  17. */
  18. #if defined _airbreak_included
  19. #endinput
  20. #endif
  21. #define _airbreak_included
  22. #include <a_samp>
  23. #define MAX_VEHICLE_AIRBREAK (200.0)
  24. #define MAX_AIRBREAK_DISTANCE (15.0)
  25. enum E_AIRBREAK_DATA
  26. {
  27. Float:E_PLAYER_X[MAX_PLAYERS],
  28. Float:E_PLAYER_Y[MAX_PLAYERS],
  29. Float:E_PLAYER_Z[MAX_PLAYERS],
  30. E_AIRBREAK_TIMER
  31. };
  32. new E_AIRBREAK_ENUM[E_AIRBREAK_DATA];
  33. new stock airbreakIndexes[] =
  34. {
  35. 1231, 1266, 1234, 1189,
  36. 1235, 1136, 1196, 1197,
  37. 1198, 1159, 1133, 1130,
  38. 1129, 1208, 1156
  39. };
  40. #if defined FILTERSCRIPT
  41. public OnFilterScriptInit()
  42. {
  43. E_AIRBREAK_ENUM[E_AIRBREAK_TIMER] = SetTimer("AirbreakCheck", 1000, true);
  44. return CallLocalFunction("ab_OnFilterScriptInit", "");
  45. }
  46. #else
  47. public OnGameModeInit()
  48. {
  49. E_AIRBREAK_ENUM[E_AIRBREAK_TIMER] = SetTimer("AirbreakCheck", 1000, true);
  50. return CallLocalFunction("ab_OnGameModeInit", "");
  51. }
  52. #endif
  53. stock Float:GetVehicleSpeed2(playerid)
  54. {
  55. if (!IsPlayerInAnyVehicle(playerid)) return 0.0;
  56. new
  57. Float:vX,
  58. Float:vY,
  59. Float:vZ
  60. ;
  61. GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
  62. return floatsqroot(floatpower(vX, 2) + floatpower(vY, 2) + floatpower(vZ, 2)) * 100;
  63. }
  64. forward AirbreakCheck();
  65. public AirbreakCheck()
  66. {
  67. new Float:x, Float:y, Float:z, index, Float:dist[4];
  68. for (new i = 0; i < MAX_PLAYERS; i ++)
  69. {
  70. if (!IsPlayerConnected(i)) continue;
  71. if (GetPVarInt(i, "CheckDelay"))
  72. {
  73. SetPVarInt(i, "CheckDelay", GetPVarInt(i, "CheckDelay") - 1);
  74. continue;
  75. }
  76. if (IsPlayerInAnyVehicle(i))
  77. {
  78. GetVehiclePos(GetPlayerVehicleID(i), x, y, z);
  79. }
  80. else GetPlayerPos(i, x, y, z);
  81. index = GetPlayerAnimationIndex(i);
  82. dist[0] = (E_AIRBREAK_ENUM[E_PLAYER_X][i] < x) ? E_AIRBREAK_ENUM[E_PLAYER_X][i] - x : x - E_AIRBREAK_ENUM[E_PLAYER_X][i];
  83. dist[1] = (E_AIRBREAK_ENUM[E_PLAYER_Y][i] < y) ? E_AIRBREAK_ENUM[E_PLAYER_Y][i] - y : y - E_AIRBREAK_ENUM[E_PLAYER_Y][i];
  84. dist[2] = (E_AIRBREAK_ENUM[E_PLAYER_Z][i] < z) ? E_AIRBREAK_ENUM[E_PLAYER_Z][i] - z : z - E_AIRBREAK_ENUM[E_PLAYER_Z][i];
  85. dist[3] = floatsqroot(floatpower(dist[0], 2.0) + floatpower(dist[1], 2.0) + floatpower(dist[2], 2.0));
  86. if (x == E_AIRBREAK_ENUM[E_PLAYER_X][i] && y == E_AIRBREAK_ENUM[E_PLAYER_Y][i] && z == E_AIRBREAK_ENUM[E_PLAYER_Z][i])
  87. {
  88. // Player is most likely AFK, so let's forget about checking that player.
  89. continue;
  90. }
  91. if (dist[3] > MAX_AIRBREAK_DISTANCE && !IsPlayerInAnyVehicle(i))
  92. {
  93. if (GetPlayerState(i) == PLAYER_STATE_ONFOOT)
  94. {
  95. for (new l = 0; l < sizeof(airbreakIndexes); l ++)
  96. {
  97. if (index == airbreakIndexes[l])
  98. {
  99. if (!floatcmp(E_AIRBREAK_ENUM[E_PLAYER_Z][i], z))
  100. {
  101. if (funcidx("OnPlayerAirbreak") != -1)
  102. CallLocalFunction("OnPlayerAirbreak", "d", i);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. else if (dist[3] > MAX_VEHICLE_AIRBREAK && IsPlayerInAnyVehicle(i))
  109. {
  110. if (GetPlayerState(i) == PLAYER_STATE_DRIVER)
  111. {
  112. if (GetVehicleSpeed(i) >= 0.02 && GetVehicleSpeed(i) <= 0.15)
  113. {
  114. if (funcidx("OnPlayerAirbreak") != -1)
  115. CallLocalFunction("OnPlayerAirbreak", "d", i);
  116. }
  117. }
  118. }
  119. E_AIRBREAK_ENUM[E_PLAYER_X][i] = x;
  120. E_AIRBREAK_ENUM[E_PLAYER_Y][i] = y;
  121. E_AIRBREAK_ENUM[E_PLAYER_Z][i] = z;
  122. }
  123. return 1;
  124. }
  125. public OnEnterExitModShop(playerid, enterexit)
  126. {
  127. if (enterexit)
  128. {
  129. SetPVarInt(playerid, "CheckDelay", 2);
  130. }
  131. else DeletePVar(playerid, "CheckDelay");
  132. return CallLocalFunction("ab_OnEnterExitModShop", "dd", playerid, enterexit);
  133. }
  134. #if defined _ALS_OnEnterExitModShop
  135. #undef OnEnterExitModShop
  136. #else
  137. #define _ALS_OnEnterExitModShop
  138. #endif
  139. #define OnEnterExitModShop ab_OnEnterExitModShop
  140. stock ab_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
  141. {
  142. E_AIRBREAK_ENUM[E_PLAYER_X][playerid] = x;
  143. E_AIRBREAK_ENUM[E_PLAYER_Y][playerid] = y;
  144. E_AIRBREAK_ENUM[E_PLAYER_Z][playerid] = z;
  145. SetPVarInt(playerid, "CheckDelay", 2);
  146. return SetPlayerPos(playerid, x, y, z);
  147. }
  148. stock ab_SetVehiclePos(vehicleid, Float:x, Float:y, Float:z)
  149. {
  150. for (new i = 0; i < MAX_PLAYERS; i ++)
  151. {
  152. if (IsPlayerConnected(i) && IsPlayerInVehicle(i, vehicleid))
  153. {
  154. E_AIRBREAK_ENUM[E_PLAYER_X][i] = x;
  155. E_AIRBREAK_ENUM[E_PLAYER_Y][i] = y;
  156. E_AIRBREAK_ENUM[E_PLAYER_Z][i] = z;
  157. SetPVarInt(i, "CheckDelay", 2);
  158. }
  159. }
  160. return SetVehiclePos(vehicleid, x, y, z);
  161. }
  162. stock ab_PutPlayerInVehicle(playerid, vehicleid, seatid)
  163. {
  164. new Float:x, Float:y, Float:z;
  165. GetVehiclePos(vehicleid, x, y, z);
  166. E_AIRBREAK_ENUM[E_PLAYER_X][playerid] = x;
  167. E_AIRBREAK_ENUM[E_PLAYER_Y][playerid] = y;
  168. E_AIRBREAK_ENUM[E_PLAYER_Z][playerid] = z;
  169. SetPVarInt(playerid, "CheckDelay", 2);
  170. return PutPlayerInVehicle(playerid, vehicleid, seatid);
  171. }
  172. #if defined FILTERSCRIPT
  173. #if defined _ALS_OnFilterScriptInit
  174. #undef OnFilterScriptInit
  175. #else
  176. #define _ALS_OnFilterScriptInit
  177. #endif
  178. #define OnFilterScriptInit ab_OnFilterScriptInit
  179. forward ab_OnFilterScriptInit();
  180. #else
  181. #if defined _ALS_OnGameModeInit
  182. #undef OnGameModeInit
  183. #else
  184. #define _ALS_OnGameModeInit
  185. #endif
  186. #define OnGameModeInit ab_OnGameModeInit
  187. forward ab_OnGameModeInit();
  188. #endif
  189. #define SetPlayerPos ab_SetPlayerPos
  190. #define SetVehiclePos ab_SetVehiclePos
  191. #define PutPlayerInVehicle ab_PutPlayerInVehicle
  192. forward OnPlayerAirbreak(playerid);