Guest User

Anti-Camp BB3

a guest
Jan 15th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.81 KB | None | 0 0
  1. /*
  2.     Anti-Camp Script
  3.     Made by BlackBank3 (Joris Woltman)
  4.     Version: 1.0
  5. */
  6.  
  7. #if defined _Anti_Camp_included
  8.   #endinput
  9. #endif
  10. #define _Anti_Camp_included
  11.  
  12. #define ANTI_CAMP_DISTANCE (6.0)
  13. #define AC_DEFAULT_REACT_TIME (7) // In seconds.
  14.  
  15. forward OnPlayerCamping(playerid);
  16.  
  17. enum _Anti_Camp {
  18.     _AntiCamp_Timer,
  19.     _AntiCamp_Count,
  20.     _AntiCamp_MaxSeconds,
  21.     Float:_AntiCamp_OldX,
  22.     Float:_AntiCamp_OldY,
  23.     Float:_AntiCamp_OldZ,
  24.     bool:_AntiCamp_Death
  25. }
  26. new
  27.     AntiCamp[MAX_PLAYERS][_Anti_Camp];
  28.  
  29. public OnPlayerConnect(playerid)
  30. {
  31.     AntiCamp[playerid][_AntiCamp_Timer] = -1;
  32.     AntiCamp_ResetReactCount(playerid);
  33.     return 1;
  34. }
  35. #if defined _ALS_OnPlayerConnect
  36.     #undef OnPlayerConnect
  37. #else
  38.     #define _ALS_OnPlayerConnect
  39. #endif
  40. #define OnPlayerConnect Anti_Camp_OnPlayerConnect
  41. forward Anti_Camp_OnPlayerConnect(playerid);
  42.  
  43. public OnPlayerDisconnect(playerid, reason)
  44. {
  45.     if(AntiCamp[playerid][_AntiCamp_Timer] != -1) AntiCamp_Disable(playerid);
  46.     return 1;
  47. }
  48. #if defined _ALS_OnPlayerDisconnect
  49.     #undef OnPlayerDisconnect
  50. #else
  51.     #define _ALS_OnPlayerDisconnect
  52. #endif
  53. #define OnPlayerDisconnect Anti_Camp_OnPlayerDisconnect
  54. forward Anti_Camp_OnPlayerDisconnect(playerid, reason);
  55.  
  56. public OnPlayerSpawn(playerid)
  57. {
  58.     if(AntiCamp[playerid][_AntiCamp_Death] == true) {
  59.         AntiCamp[playerid][_AntiCamp_Death] = false;
  60.         AntiCamp_ResetReactCount(playerid);
  61.         AntiCamp_Enable(playerid);
  62.     }
  63.     return 1;
  64. }
  65. #if defined _ALS_OnPlayerSpawn
  66.     #undef OnPlayerSpawn
  67. #else
  68.     #define _ALS_OnPlayerSpawn
  69. #endif
  70. #define OnPlayerSpawn Anti_Camp_OnPlayerSpawn
  71. forward Anti_Camp_OnPlayerSpawn(playerid);
  72.  
  73. public OnPlayerDeath(playerid, killerid, reason)
  74. {
  75.     if(AntiCamp[playerid][_AntiCamp_Timer] != -1) {
  76.         AntiCamp_Disable(playerid);
  77.         AntiCamp[playerid][_AntiCamp_Death] = true;
  78.     }
  79.     return 1;
  80. }
  81. #if defined _ALS_OnPlayerDeath
  82.     #undef OnPlayerDeath
  83. #else
  84.     #define _ALS_OnPlayerDeath
  85. #endif
  86. #define OnPlayerDeath Anti_Camp_OnPlayerDeath
  87. forward Anti_Camp_OnPlayerDeath(playerid, killerid, reason);
  88.  
  89. forward AntiCamp_Check(playerid);
  90. public AntiCamp_Check(playerid)
  91. {
  92.     ++AntiCamp[playerid][_AntiCamp_Count];
  93.  
  94.     new Float:distance = GetPlayerDistanceFromPoint(playerid, AntiCamp[playerid][_AntiCamp_OldX], AntiCamp[playerid][_AntiCamp_OldY], AntiCamp[playerid][_AntiCamp_OldZ]);
  95.     GetPlayerPos(playerid, AntiCamp[playerid][_AntiCamp_OldX], AntiCamp[playerid][_AntiCamp_OldY], AntiCamp[playerid][_AntiCamp_OldZ]);
  96.  
  97.     static bool:Callback_Called[MAX_PLAYERS] = false;
  98.  
  99.     if(distance > ANTI_CAMP_DISTANCE) {
  100.         AntiCamp[playerid][_AntiCamp_Count] = 0;
  101.         if(Callback_Called[playerid] == true) Callback_Called[playerid] = false;
  102.     }
  103.     if(AntiCamp[playerid][_AntiCamp_Count] >= AntiCamp[playerid][_AntiCamp_MaxSeconds] && Callback_Called[playerid] == false) {
  104.         CallRemoteFunction("OnPlayerCamping", "d", playerid);
  105.         Callback_Called[playerid] = true;
  106.     }
  107.     return 1;
  108. }
  109.  
  110. stock AntiCamp_Disable(playerid) return AntiCamp_Enable(playerid, AntiCamp[playerid][_AntiCamp_MaxSeconds], false);
  111.  
  112. stock AntiCamp_Enable(playerid, ReactTimeInSeconds = AC_DEFAULT_REACT_TIME, bool:enabled = true) {
  113.     if(enabled == true && AntiCamp[playerid][_AntiCamp_Timer] == -1) AntiCamp[playerid][_AntiCamp_Timer] = SetTimerEx("AntiCamp_Check", 1000, true, "d", playerid), AntiCamp[playerid][_AntiCamp_MaxSeconds] = ReactTimeInSeconds;
  114.     else KillTimer(AntiCamp[playerid][_AntiCamp_Timer]), AntiCamp[playerid][_AntiCamp_Timer] = -1, AntiCamp[playerid][_AntiCamp_Count] = 0;
  115.     return 1;
  116. }
  117.  
  118. stock AntiCamp_ResetReactCount(playerid) return AntiCamp[playerid][_AntiCamp_Count] = 0, 1;
  119.  
  120. stock AntiCamp_SetReactTime(playerid, Seconds = AC_DEFAULT_REACT_TIME) return AntiCamp[playerid][_AntiCamp_MaxSeconds] = Seconds, 1;
  121.  
  122. stock AntiCamp_IsEnabled(playerid) return (AntiCamp[playerid][_AntiCamp_Timer] != -1) ? (1) : (0);
Advertisement
Add Comment
Please, Sign In to add comment