1
0

airbreak.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * airbreak.inc - Airbreak detection!
  3. * Part of the eLibrary project to extend PAWN!
  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:GetVehicleSpeeds(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 (IsPlayerInAnyVehicle(i))
  72. {
  73. GetVehiclePos(GetPlayerVehicleID(i), x, y, z);
  74. }
  75. else GetPlayerPos(i, x, y, z);
  76. index = GetPlayerAnimationIndex(i);
  77. 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];
  78. 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];
  79. 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];
  80. dist[3] = floatsqroot(floatpower(dist[0], 2.0) + floatpower(dist[1], 2.0) + floatpower(dist[2], 2.0));
  81. 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])
  82. {
  83. // Player is most likely AFK, so let's forget about checking that player.
  84. continue;
  85. }
  86. if (dist[3] > MAX_AIRBREAK_DISTANCE && !IsPlayerInAnyVehicle(i))
  87. {
  88. if (GetPlayerState(i) == PLAYER_STATE_ONFOOT)
  89. {
  90. for (new l = 0; l < sizeof(airbreakIndexes); l ++)
  91. {
  92. if (index == airbreakIndexes[l])
  93. {
  94. if (!floatcmp(E_AIRBREAK_ENUM[E_PLAYER_Z][i], z))
  95. {
  96. if (funcidx("OnPlayerAirbreak") != -1)
  97. CallLocalFunction("OnPlayerAirbreak", "d", i);
  98. }
  99. }
  100. }
  101. }
  102. }
  103. else if (dist[3] > MAX_VEHICLE_AIRBREAK && IsPlayerInAnyVehicle(i))
  104. {
  105. if (GetPlayerState(i) == PLAYER_STATE_DRIVER)
  106. {
  107. if (GetVehicleSpeeds(i) >= 0.02 && GetVehicleSpeeds(i) <= 0.15)
  108. {
  109. if (funcidx("OnPlayerAirbreak") != -1)
  110. CallLocalFunction("OnPlayerAirbreak", "d", i);
  111. }
  112. }
  113. }
  114. E_AIRBREAK_ENUM[E_PLAYER_X][i] = x;
  115. E_AIRBREAK_ENUM[E_PLAYER_Y][i] = y;
  116. E_AIRBREAK_ENUM[E_PLAYER_Z][i] = z;
  117. }
  118. return 1;
  119. }
  120. stock ab_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
  121. {
  122. E_AIRBREAK_ENUM[E_PLAYER_X][playerid] = x;
  123. E_AIRBREAK_ENUM[E_PLAYER_Y][playerid] = y;
  124. E_AIRBREAK_ENUM[E_PLAYER_Z][playerid] = z;
  125. return SetPlayerPos(playerid, x, y, z);
  126. }
  127. stock ab_SetVehiclePos(vehicleid, Float:x, Float:y, Float:z)
  128. {
  129. for (new i = 0; i < MAX_PLAYERS; i ++)
  130. {
  131. if (IsPlayerConnected(i) && IsPlayerInVehicle(i, vehicleid))
  132. {
  133. E_AIRBREAK_ENUM[E_PLAYER_X][i] = x;
  134. E_AIRBREAK_ENUM[E_PLAYER_Y][i] = y;
  135. E_AIRBREAK_ENUM[E_PLAYER_Z][i] = z;
  136. }
  137. }
  138. return SetVehiclePos(vehicleid, x, y, z);
  139. }
  140. stock ab_PutPlayerInVehicle(playerid, vehicleid, seatid)
  141. {
  142. new Float:x, Float:y, Float:z;
  143. GetVehiclePos(vehicleid, x, y, z);
  144. E_AIRBREAK_ENUM[E_PLAYER_X][playerid] = x;
  145. E_AIRBREAK_ENUM[E_PLAYER_Y][playerid] = y;
  146. E_AIRBREAK_ENUM[E_PLAYER_Z][playerid] = z;
  147. return PutPlayerInVehicle(playerid, vehicleid, seatid);
  148. }
  149. /*public OnPlayerAirbreak(playerid)
  150. {
  151. new
  152. playername[24],
  153. string[128];
  154. if(PlayerInfo[playerid][pAdmin] < 2)
  155. {
  156. GetPlayerName(playerid, playername, sizeof(playername));
  157. if (IsPlayerInAnyVehicle(playerid))
  158. {
  159. format(string, sizeof(string), "%s[%d] was banned for vehicle airbreak.", playername, playerid);
  160. SendClientMessageToAll(0xFF0000FF, string);
  161. }
  162. else
  163. {
  164. format(string, sizeof(string), "%s[%d] was banned for airbreak.", playername, playerid);
  165. SendClientMessageToAll(0xFF0000FF, string);
  166. }
  167. Ban(playerid);
  168. }
  169. return 1;
  170. }*/
  171. #if defined FILTERSCRIPT
  172. #if defined _ALS_OnFilterScriptInit
  173. #undef OnFilterScriptInit
  174. #else
  175. #define _ALS_OnFilterScriptInit
  176. #endif
  177. #define OnFilterScriptInit ab_OnFilterScriptInit
  178. forward ab_OnFilterScriptInit();
  179. #else
  180. #if defined _ALS_OnGameModeInit
  181. #undef OnGameModeInit
  182. #else
  183. #define _ALS_OnGameModeInit
  184. #endif
  185. #define OnGameModeInit ab_OnGameModeInit
  186. forward ab_OnGameModeInit();
  187. #endif
  188. #define SetPlayerPos ab_SetPlayerPos
  189. #define SetVehiclePos ab_SetVehiclePos
  190. #define PutPlayerInVehicle ab_PutPlayerInVehicle
  191. forward OnPlayerAirbreak(playerid);