tp.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // Teleport and airbreak detection for Limitless Roleplay
  2. enum acEnum
  3. {
  4. Float: acPosX,
  5. Float: acPosY,
  6. Float: acPosZ,
  7. Float: acSpawnX,
  8. Float: acSpawnY,
  9. Float: acSpawnZ,
  10. acAirbreakTime,
  11. acImmunity
  12. };
  13. static Anticheat[MAX_PLAYERS][acEnum];
  14. // List of mod shop locations. Using a modshop counts as teleporting.
  15. static const Float:modShopLocations[][] =
  16. {
  17. {10.0, -1936.0861, 237.4443, 34.3125},
  18. {10.0, -2714.6309, 217.3955, 4.2965},
  19. {10.0, 2386.7686, 1042.1649, 10.8203},
  20. {10.0, 2644.9480, -2037.6088, 13.5500},
  21. {10.0, 1041.2783, -1027.8124, 32.1016},
  22. {50.0, 616.0253, -8.0157, 1000.9219},
  23. {50.0, 615.2108, -75.3288, 997.9922},
  24. {50.0, 612.9303, -124.1615, 997.9922}
  25. };
  26. forward OnPlayerTeleport(playerid, Float:distance);
  27. forward OnPlayerAirbreak(playerid);
  28. static AC_RangeCheck(Float:x1, Float:y1, Float:z1, Float:radius, Float:x2, Float:y2, Float:z2)
  29. {
  30. x1 -= x2;
  31. y1 -= y2;
  32. z1 -= z2;
  33. return ((x1 * x1) + (y1 * y1) + (z1 * z1)) < (radius * radius);
  34. }
  35. static Float:AC_GetSpeed(playerid)
  36. {
  37. new
  38. Float:vx,
  39. Float:vy,
  40. Float:vz;
  41. if(IsPlayerInAnyVehicle(playerid))
  42. {
  43. GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
  44. }
  45. else
  46. {
  47. GetPlayerVelocity(playerid, vx, vy, vz);
  48. }
  49. return floatsqroot((vx * vx) + (vy * vy) + (vz * vz));
  50. }
  51. static AC_IsPlayerNearModShop(playerid)
  52. {
  53. if(IsPlayerInAnyVehicle(playerid))
  54. {
  55. for(new i = 0; i < sizeof(modShopLocations); i ++)
  56. {
  57. if(IsPlayerInRangeOfPoint(playerid, modShopLocations[i][0], modShopLocations[i][1], modShopLocations[i][2], modShopLocations[i][3]))
  58. {
  59. return 1;
  60. }
  61. }
  62. }
  63. return 0;
  64. }
  65. stock AC_PutPlayerInVehicle(playerid, vehicleid, seatid)
  66. {
  67. if(IsPlayerConnected(playerid))
  68. {
  69. if(GetVehicleModel(vehicleid))
  70. {
  71. GetVehiclePos(vehicleid, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]);
  72. }
  73. Anticheat[playerid][acImmunity] = gettime() + 5;
  74. }
  75. return PutPlayerInVehicle(playerid, vehicleid, seatid);
  76. }
  77. #if defined _ALS_PutPlayerInVehicle
  78. #undef PutPlayerInVehicle
  79. #else
  80. #define _ALS_PutPlayerInVehicle
  81. #endif
  82. #define PutPlayerInVehicle AC_PutPlayerInVehicle
  83. stock AC_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
  84. {
  85. new
  86. ret = SetPlayerPos(playerid, x, y, z);
  87. if(ret)
  88. {
  89. Anticheat[playerid][acPosX] = x;
  90. Anticheat[playerid][acPosY] = y;
  91. Anticheat[playerid][acPosZ] = z;
  92. Anticheat[playerid][acImmunity] = gettime() + 5;
  93. }
  94. return ret;
  95. }
  96. #if defined _ALS_SetPlayerPos
  97. #undef SetPlayerPos
  98. #else
  99. #define _ALS_SetPlayerPos
  100. #endif
  101. #define SetPlayerPos AC_SetPlayerPos
  102. stock AC_SetVehiclePos(vehicleid, Float:x, Float:y, Float:z)
  103. {
  104. new
  105. ret = SetVehiclePos(vehicleid, x, y, z);
  106. if(ret)
  107. {
  108. for(new i = 0, l = GetPlayerPoolSize(); i <= l; i ++)
  109. {
  110. if(GetPlayerState(i) == PLAYER_STATE_DRIVER && IsPlayerInVehicle(i, vehicleid))
  111. {
  112. Anticheat[i][acPosX] = x;
  113. Anticheat[i][acPosY] = y;
  114. Anticheat[i][acPosZ] = z;
  115. Anticheat[i][acImmunity] = gettime() + 5;
  116. break;
  117. }
  118. }
  119. }
  120. return ret;
  121. }
  122. #if defined _ALS_SetVehiclePos
  123. #undef SetVehiclePos
  124. #else
  125. #define _ALS_SetVehiclePos
  126. #endif
  127. #define SetVehiclePos AC_SetVehiclePos
  128. stock AC_SetSpawnInfo(playerid, team, skin, Float:x, Float:y, Float:z, Float:rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo)
  129. {
  130. if(IsPlayerConnected(playerid))
  131. {
  132. Anticheat[playerid][acSpawnX] = x;
  133. Anticheat[playerid][acSpawnY] = y;
  134. Anticheat[playerid][acSpawnZ] = z;
  135. }
  136. return SetSpawnInfo(playerid, team, skin, x, y, z, rotation, weapon1, weapon1_ammo, weapon2, weapon2_ammo, weapon3, weapon3_ammo);
  137. }
  138. #if defined _ALS_SetSpawnInfo
  139. #undef SetSpawnInfo
  140. #else
  141. #define _ALS_SetSpawnInfo
  142. #endif
  143. #define SetSpawnInfo AC_SetSpawnInfo
  144. public OnEnterExitModShop(playerid, enterexit, interiorid)
  145. {
  146. GetPlayerPos(playerid, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]);
  147. Anticheat[playerid][acImmunity] = gettime() + 5;
  148. #if defined AC_OnEnterExitModShop
  149. return AC_OnEnterExitModShop(playerid, enterexit, interiorid);
  150. #else
  151. return 1;
  152. #endif
  153. }
  154. #if defined _ALS_OnEnterExitModShop
  155. #undef OnEnterExitModShop
  156. #else
  157. #define _ALS_OnEnterExitModShop
  158. #endif
  159. #define OnEnterExitModShop AC_OnEnterExitModShop
  160. #if defined AC_OnEnterExitModShop
  161. forward AC_OnEnterExitModShop(playerid, enterexit, interiorid);
  162. #endif
  163. public OnPlayerSpawn(playerid)
  164. {
  165. Anticheat[playerid][acImmunity] = gettime() + 5;
  166. #if defined AC_OnPlayerSpawn
  167. return AC_OnPlayerSpawn(playerid);
  168. #else
  169. return 1;
  170. #endif
  171. }
  172. #if defined _ALS_OnPlayerSpawn
  173. #undef OnPlayerSpawn
  174. #else
  175. #define _ALS_OnPlayerSpawn
  176. #endif
  177. #define OnPlayerSpawn AC_OnPlayerSpawn
  178. #if defined AC_OnPlayerSpawn
  179. forward AC_OnPlayerSpawn(playerid);
  180. #endif
  181. public OnPlayerUpdate(playerid)
  182. {
  183. if(GetPlayerState(playerid) != PLAYER_STATE_SPECTATING && GetPlayerState(playerid) != PLAYER_STATE_NONE)
  184. {
  185. if(gettime() > Anticheat[playerid][acImmunity])
  186. {
  187. if(!IsPlayerInRangeOfPoint(playerid, 100.0, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]) && !IsPlayerInRangeOfPoint(playerid, 5.0, Anticheat[playerid][acSpawnX], Anticheat[playerid][acSpawnY], Anticheat[playerid][acSpawnZ]))
  188. {
  189. new
  190. Float:x,
  191. Float:y,
  192. Float:z;
  193. GetPlayerPos(playerid, x, y, z);
  194. if(!AC_RangeCheck(Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ], 3.0, Anticheat[playerid][acSpawnX], Anticheat[playerid][acSpawnY], Anticheat[playerid][acSpawnZ]) && x != 0.0 && y != 0.0 && z != 0.0 && GetPlayerState(playerid) != PLAYER_STATE_PASSENGER && !AC_IsPlayerNearModShop(playerid))
  195. {
  196. CallLocalFunction("OnPlayerTeleport", "if", playerid, GetPlayerDistanceFromPoint(playerid, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]));
  197. }
  198. }
  199. else if(gettime() > Anticheat[playerid][acAirbreakTime] && !IsPlayerInRangeOfPoint(playerid, 10.0, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]))
  200. {
  201. if((GetPlayerState(playerid) == PLAYER_STATE_ONFOOT || GetPlayerState(playerid) == PLAYER_STATE_DRIVER) && GetPlayerSurfingVehicleID(playerid) == INVALID_VEHICLE_ID && GetPlayerSurfingObjectID(playerid) == INVALID_OBJECT_ID)
  202. {
  203. // Player is 10.0 meters away from their position. Let's check their velocity!
  204. new
  205. Float:px,
  206. Float:py,
  207. Float:pz;
  208. GetPlayerPos(playerid, px, py, pz);
  209. px = floatabs(Anticheat[playerid][acPosX] - px);
  210. py = floatabs(Anticheat[playerid][acPosY] - py);
  211. pz = floatabs(Anticheat[playerid][acPosZ] - pz);
  212. // Player seems to have moved a great distance. Let's do more checking.
  213. if(((0.5 <= px < 13.9) && (0.5 <= py <= 13.9)) || (4.2 <= pz <= 19.2))
  214. {
  215. new
  216. Float:speed = AC_GetSpeed(playerid);
  217. if((0.082 <= speed <= 0.215 && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) || (0.0009 <= speed <= 0.0013 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
  218. {
  219. // When airbreaking in the air, a player's velocity levels tend to stay at a regular speed, as they were moving onfoot.
  220. CallLocalFunction("OnPlayerAirbreak", "i", playerid);
  221. Anticheat[playerid][acAirbreakTime] = gettime() + 1;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. GetPlayerPos(playerid, Anticheat[playerid][acPosX], Anticheat[playerid][acPosY], Anticheat[playerid][acPosZ]);
  228. }
  229. #if defined AC_OnPlayerUpdate
  230. return AC_OnPlayerUpdate(playerid);
  231. #else
  232. return 1;
  233. #endif
  234. }
  235. #if defined _ALS_OnPlayerUpdate
  236. #undef OnPlayerUpdate
  237. #else
  238. #define _ALS_OnPlayerUpdate
  239. #endif
  240. #define OnPlayerUpdate AC_OnPlayerUpdate
  241. #if defined AC_OnPlayerUpdate
  242. forward AC_OnPlayerUpdate(playerid);
  243. #endif