OPA.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. OnPlayerAirbreak(playerid);
  3. This include is one of the only accurate airbreak detecting
  4. methods developed in SA-MP.
  5. I do not guarantee positive results with this include.
  6. There could be many false flags.
  7. Created by Emmet on Wednesday, November 6, 2013.
  8. Updated by Kar (bug fixes). Last update: February 12th, 2016.
  9. */
  10. #if defined ac_OnPlayerAirbreak
  11. #endinput
  12. #else
  13. #define ac_OnPlayerAirbreak
  14. #endif
  15. // How many times should airbreak be detected before OnPlayerAirbreak is finally called?
  16. #if !defined MAX_FLAGGED_DETECTIONS
  17. #define MAX_FLAGGED_DETECTIONS 3
  18. #endif
  19. // Maximum distance a player must travel in less than a second before being flagged for airbreak (onfoot).
  20. #if !defined ONFOOT_DISTANCE
  21. #define ONFOOT_DISTANCE 75.0
  22. #endif
  23. // Maximum distance a player must travel in less than a second before being flagged for airbreak (driver).
  24. #if !defined VEHICLE_DISTANCE
  25. #define VEHICLE_DISTANCE 50.0
  26. #endif
  27. static
  28. // Last known coordinates of the player.
  29. Float:s_AirbreakLastCoords[MAX_PLAYERS][3],
  30. // Timestamp used to store the next second in a timestamp.
  31. s_AirbreakUpdateTick[MAX_PLAYERS],
  32. // Timestamp containing the next time to check for airbreak.
  33. s_AirbreakDetectImmunity[MAX_PLAYERS],
  34. // Timestamp containing the last detection.
  35. s_AirbreakLastDetection[MAX_PLAYERS],
  36. // Number of detections in the last 60 seconds.
  37. s_AirbreakDetections[MAX_PLAYERS]
  38. ;
  39. forward OnPlayerAirbreak(playerid);
  40. static AB_IsVehicleMoving(vehicleid)
  41. {
  42. new
  43. Float:x,
  44. Float:y,
  45. Float:z;
  46. GetVehicleVelocity(vehicleid, x, y, z);
  47. return (!(floatabs(x) <= 0.001 && floatabs(y) <= 0.001 && floatabs(z) <= 0.005));
  48. }
  49. static AB_OnAirbreakDetected(playerid)
  50. {
  51. // Called when the player is presumably airbreaking.
  52. // If the amount of detections exceeds MAX_FLAGGED_DETECTIONS, they are most likely airbreaking.
  53. new
  54. timestamp = gettime();
  55. if((++ s_AirbreakDetections[playerid]) >= MAX_FLAGGED_DETECTIONS && (timestamp - s_AirbreakLastDetection[playerid]) < 60)
  56. {
  57. CallLocalFunction("OnPlayerAirbreak", "i", playerid);
  58. }
  59. s_AirbreakLastDetection[playerid] = timestamp;
  60. }
  61. public OnFilterScriptInit()
  62. {
  63. for(new i = 0; i < MAX_PLAYERS; i ++)
  64. {
  65. if(IsPlayerConnected(i) && GetPlayerState(i) == PLAYER_STATE_ONFOOT)
  66. {
  67. s_AirbreakDetectImmunity[i] = gettime() + 3;
  68. s_AirbreakUpdateTick[i] = gettime();
  69. }
  70. }
  71. #if defined AB_OnFilterScriptInit
  72. return AB_OnFilterScriptInit();
  73. #else
  74. return 1;
  75. #endif
  76. }
  77. public OnPlayerConnect(playerid)
  78. {
  79. s_AirbreakDetections[playerid] = 0;
  80. s_AirbreakLastDetection[playerid] = 0;
  81. s_AirbreakDetectImmunity[playerid] = 0;
  82. s_AirbreakUpdateTick[playerid] = gettime();
  83. #if defined AB_OnPlayerConnect
  84. return AB_OnPlayerConnect(playerid);
  85. #else
  86. return 1;
  87. #endif
  88. }
  89. public OnPlayerSpawn(playerid)
  90. {
  91. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  92. GetPlayerPos(playerid, s_AirbreakLastCoords[playerid][0], s_AirbreakLastCoords[playerid][1], s_AirbreakLastCoords[playerid][2]);
  93. #if defined AB_OnPlayerSpawn
  94. return AB_OnPlayerSpawn(playerid);
  95. #else
  96. return 1;
  97. #endif
  98. }
  99. public OnPlayerDeath(playerid, killerid, reason)
  100. {
  101. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  102. #if defined AB_OnPlayerDeath
  103. return AB_OnPlayerDeath(playerid, killerid, reason);
  104. #else
  105. return 1;
  106. #endif
  107. }
  108. public OnPlayerUpdate(playerid)
  109. {
  110. if(!IsPlayerNPC(playerid))
  111. {
  112. new
  113. vehicleid = GetPlayerVehicleID(playerid),
  114. timestamp = gettime(),
  115. Float:x,
  116. Float:y,
  117. Float:z,
  118. Float:distance;
  119. if(timestamp > s_AirbreakUpdateTick[playerid])
  120. {
  121. if(timestamp > s_AirbreakDetectImmunity[playerid] && GetPlayerSurfingVehicleID(playerid) == INVALID_VEHICLE_ID && GetPlayerSurfingObjectID(playerid) == INVALID_OBJECT_ID && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_ENTER_VEHICLE && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_EXIT_VEHICLE)
  122. {
  123. if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  124. {
  125. distance = GetPlayerDistanceFromPoint(playerid, s_AirbreakLastCoords[playerid][0], s_AirbreakLastCoords[playerid][1], s_AirbreakLastCoords[playerid][2]);
  126. GetPlayerPos(playerid, x, y, z);
  127. if((floatabs(s_AirbreakLastCoords[playerid][2] - z) < 1.0 && floatabs(distance) >= ONFOOT_DISTANCE) && (floatabs(s_AirbreakLastCoords[playerid][1] - y) >= 50.0 || floatabs(s_AirbreakLastCoords[playerid][0] - x) >= 50.0))
  128. {
  129. AB_OnAirbreakDetected(playerid);
  130. }
  131. }
  132. else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  133. {
  134. distance = GetVehicleDistanceFromPoint(vehicleid, s_AirbreakLastCoords[playerid][0], s_AirbreakLastCoords[playerid][1], s_AirbreakLastCoords[playerid][2]);
  135. GetVehiclePos(vehicleid, x, y, z);
  136. if((!AB_IsVehicleMoving(vehicleid) && floatabs(distance) >= VEHICLE_DISTANCE) && (floatabs(s_AirbreakLastCoords[playerid][1] - y) >= 40.0 || floatabs(s_AirbreakLastCoords[playerid][0] - x) >= 40.0))
  137. {
  138. AB_OnAirbreakDetected(playerid);
  139. }
  140. }
  141. }
  142. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  143. {
  144. GetVehiclePos(vehicleid, s_AirbreakLastCoords[playerid][0], s_AirbreakLastCoords[playerid][1], s_AirbreakLastCoords[playerid][2]);
  145. }
  146. else
  147. {
  148. GetPlayerPos(playerid, s_AirbreakLastCoords[playerid][0], s_AirbreakLastCoords[playerid][1], s_AirbreakLastCoords[playerid][2]);
  149. }
  150. s_AirbreakUpdateTick[playerid] = timestamp;
  151. }
  152. }
  153. #if defined AB_OnPlayerUpdate
  154. return AB_OnPlayerUpdate(playerid);
  155. #else
  156. return 1;
  157. #endif
  158. }
  159. stock AB_SetSpawnInfo(playerid, team, skin, Float:x, Float:y, Float:z, Float:rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
  160. {
  161. new
  162. ret = SetSpawnInfo(playerid, team, skin, x, y, z, rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  163. if(ret)
  164. {
  165. switch(GetPlayerState(playerid))
  166. {
  167. case PLAYER_STATE_NONE, PLAYER_STATE_WASTED:
  168. {
  169. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  170. s_AirbreakLastCoords[playerid][0] = x;
  171. s_AirbreakLastCoords[playerid][1] = y;
  172. s_AirbreakLastCoords[playerid][2] = z;
  173. }
  174. }
  175. }
  176. return ret;
  177. }
  178. stock AB_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
  179. {
  180. new
  181. ret = SetPlayerPos(playerid, x, y, z);
  182. if(ret)
  183. {
  184. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  185. s_AirbreakLastCoords[playerid][0] = x;
  186. s_AirbreakLastCoords[playerid][1] = y;
  187. s_AirbreakLastCoords[playerid][2] = z;
  188. }
  189. return ret;
  190. }
  191. stock AB_SetPlayerPosFindZ(playerid, Float:x, Float:y, Float:z)
  192. {
  193. new
  194. ret = SetPlayerPosFindZ(playerid, x, y, z);
  195. if(ret)
  196. {
  197. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  198. s_AirbreakLastCoords[playerid][0] = x;
  199. s_AirbreakLastCoords[playerid][1] = y;
  200. s_AirbreakLastCoords[playerid][2] = z;
  201. }
  202. return ret;
  203. }
  204. stock AB_PutPlayerInVehicle(playerid, vehicleid, seatid)
  205. {
  206. new
  207. ret = PutPlayerInVehicle(playerid, vehicleid, seatid);
  208. if(ret)
  209. {
  210. s_AirbreakDetectImmunity[playerid] = gettime() + 3;
  211. }
  212. return ret;
  213. }
  214. stock AB_SetVehiclePos(vehicleid, Float:x, Float:y, Float:z)
  215. {
  216. for(new i = 0; i < MAX_PLAYERS; i ++)
  217. {
  218. if(GetPlayerState(i) == PLAYER_STATE_DRIVER && IsPlayerInVehicle(i, vehicleid))
  219. {
  220. s_AirbreakDetectImmunity[i] = gettime() + 3;
  221. s_AirbreakLastCoords[i][0] = x;
  222. s_AirbreakLastCoords[i][1] = y;
  223. s_AirbreakLastCoords[i][2] = z;
  224. break;
  225. }
  226. }
  227. return SetVehiclePos(vehicleid, x, y, z);
  228. }
  229. #if defined _ALS_OnPlayerConnect
  230. #undef OnPlayerConnect
  231. #else
  232. #define _ALS_OnPlayerConnect
  233. #endif
  234. #if defined _ALS_OnPlayerSpawn
  235. #undef OnPlayerSpawn
  236. #else
  237. #define _ALS_OnPlayerSpawn
  238. #endif
  239. #if defined _ALS_OnPlayerDeath
  240. #undef OnPlayerDeath
  241. #else
  242. #define _ALS_OnPlayerDeath
  243. #endif
  244. #if defined _ALS_OnPlayerUpdate
  245. #undef OnPlayerUpdate
  246. #else
  247. #define _ALS_OnPlayerUpdate
  248. #endif
  249. #if defined _ALS_OnFilterScriptInit
  250. #undef OnFilterScriptInit
  251. #else
  252. #define _ALS_OnFilterScriptInit
  253. #endif
  254. #if defined _ALS_SetSpawnInfo
  255. #undef SetSpawnInfo
  256. #else
  257. #define _ALS_SetSpawnInfo
  258. #endif
  259. #if defined _ALS_SetPlayerPos
  260. #undef SetPlayerPos
  261. #else
  262. #define _ALS_SetPlayerPos
  263. #endif
  264. #if defined _ALS_SetVehiclePos
  265. #undef SetVehiclePos
  266. #else
  267. #define _ALS_SetVehiclePos
  268. #endif
  269. #if defined _ALS_SetPlayerPosFindZ
  270. #undef SetPlayerPosFindZ
  271. #else
  272. #define _ALS_SetPlayerPosFindZ
  273. #endif
  274. #if defined _ALS_PutPlayerInVehicle
  275. #undef PutPlayerInVehicle
  276. #else
  277. #define _ALS_PutPlayerInVehicle
  278. #endif
  279. #define OnPlayerConnect AB_OnPlayerConnect
  280. #define OnPlayerSpawn AB_OnPlayerSpawn
  281. #define OnPlayerDeath AB_OnPlayerDeath
  282. #define OnPlayerUpdate AB_OnPlayerUpdate
  283. #define OnFilterScriptInit AB_OnFilterScriptInit
  284. #define SetSpawnInfo AB_SetSpawnInfo
  285. #define SetPlayerPos AB_SetPlayerPos
  286. #define SetPlayerPosFindZ AB_SetPlayerPosFindZ
  287. #define PutPlayerInVehicle AB_PutPlayerInVehicle
  288. #define SetVehiclePos AB_SetVehiclePos
  289. #if defined AB_OnFilterScriptInit
  290. forward AB_OnFilterScriptInit();
  291. #endif
  292. #if defined AB_OnPlayerConnect
  293. forward AB_OnPlayerConnect(playerid);
  294. #endif
  295. #if defined AB_OnPlayerSpawn
  296. forward AB_OnPlayerSpawn(playerid);
  297. #endif
  298. #if defined AB_OnPlayerUpdate
  299. forward AB_OnPlayerUpdate(playerid);
  300. #endif
  301. #if defined AB_OnPlayerDeath
  302. forward AB_OnPlayerDeath(playerid, killerid, reason);
  303. #endif