Advertisement
11FAMILIASAMP

INCLUDE- OnPlayerAirbreak ( FAMILIASAMP.COM )

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