Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Anti-Camp Script
- Made by BlackBank3 (Joris Woltman)
- Version: 1.0
- */
- #if defined _Anti_Camp_included
- #endinput
- #endif
- #define _Anti_Camp_included
- #define ANTI_CAMP_DISTANCE (6.0)
- #define AC_DEFAULT_REACT_TIME (7) // In seconds.
- forward OnPlayerCamping(playerid);
- enum _Anti_Camp {
- _AntiCamp_Timer,
- _AntiCamp_Count,
- _AntiCamp_MaxSeconds,
- Float:_AntiCamp_OldX,
- Float:_AntiCamp_OldY,
- Float:_AntiCamp_OldZ,
- bool:_AntiCamp_Death
- }
- new
- AntiCamp[MAX_PLAYERS][_Anti_Camp];
- public OnPlayerConnect(playerid)
- {
- AntiCamp[playerid][_AntiCamp_Timer] = -1;
- AntiCamp_ResetReactCount(playerid);
- return 1;
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect Anti_Camp_OnPlayerConnect
- forward Anti_Camp_OnPlayerConnect(playerid);
- public OnPlayerDisconnect(playerid, reason)
- {
- if(AntiCamp[playerid][_AntiCamp_Timer] != -1) AntiCamp_Disable(playerid);
- return 1;
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect Anti_Camp_OnPlayerDisconnect
- forward Anti_Camp_OnPlayerDisconnect(playerid, reason);
- public OnPlayerSpawn(playerid)
- {
- if(AntiCamp[playerid][_AntiCamp_Death] == true) {
- AntiCamp[playerid][_AntiCamp_Death] = false;
- AntiCamp_ResetReactCount(playerid);
- AntiCamp_Enable(playerid);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerSpawn
- #undef OnPlayerSpawn
- #else
- #define _ALS_OnPlayerSpawn
- #endif
- #define OnPlayerSpawn Anti_Camp_OnPlayerSpawn
- forward Anti_Camp_OnPlayerSpawn(playerid);
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(AntiCamp[playerid][_AntiCamp_Timer] != -1) {
- AntiCamp_Disable(playerid);
- AntiCamp[playerid][_AntiCamp_Death] = true;
- }
- return 1;
- }
- #if defined _ALS_OnPlayerDeath
- #undef OnPlayerDeath
- #else
- #define _ALS_OnPlayerDeath
- #endif
- #define OnPlayerDeath Anti_Camp_OnPlayerDeath
- forward Anti_Camp_OnPlayerDeath(playerid, killerid, reason);
- forward AntiCamp_Check(playerid);
- public AntiCamp_Check(playerid)
- {
- ++AntiCamp[playerid][_AntiCamp_Count];
- new Float:distance = GetPlayerDistanceFromPoint(playerid, AntiCamp[playerid][_AntiCamp_OldX], AntiCamp[playerid][_AntiCamp_OldY], AntiCamp[playerid][_AntiCamp_OldZ]);
- GetPlayerPos(playerid, AntiCamp[playerid][_AntiCamp_OldX], AntiCamp[playerid][_AntiCamp_OldY], AntiCamp[playerid][_AntiCamp_OldZ]);
- static bool:Callback_Called[MAX_PLAYERS] = false;
- if(distance > ANTI_CAMP_DISTANCE) {
- AntiCamp[playerid][_AntiCamp_Count] = 0;
- if(Callback_Called[playerid] == true) Callback_Called[playerid] = false;
- }
- if(AntiCamp[playerid][_AntiCamp_Count] >= AntiCamp[playerid][_AntiCamp_MaxSeconds] && Callback_Called[playerid] == false) {
- CallRemoteFunction("OnPlayerCamping", "d", playerid);
- Callback_Called[playerid] = true;
- }
- return 1;
- }
- stock AntiCamp_Disable(playerid) return AntiCamp_Enable(playerid, AntiCamp[playerid][_AntiCamp_MaxSeconds], false);
- stock AntiCamp_Enable(playerid, ReactTimeInSeconds = AC_DEFAULT_REACT_TIME, bool:enabled = true) {
- if(enabled == true && AntiCamp[playerid][_AntiCamp_Timer] == -1) AntiCamp[playerid][_AntiCamp_Timer] = SetTimerEx("AntiCamp_Check", 1000, true, "d", playerid), AntiCamp[playerid][_AntiCamp_MaxSeconds] = ReactTimeInSeconds;
- else KillTimer(AntiCamp[playerid][_AntiCamp_Timer]), AntiCamp[playerid][_AntiCamp_Timer] = -1, AntiCamp[playerid][_AntiCamp_Count] = 0;
- return 1;
- }
- stock AntiCamp_ResetReactCount(playerid) return AntiCamp[playerid][_AntiCamp_Count] = 0, 1;
- stock AntiCamp_SetReactTime(playerid, Seconds = AC_DEFAULT_REACT_TIME) return AntiCamp[playerid][_AntiCamp_MaxSeconds] = Seconds, 1;
- stock AntiCamp_IsEnabled(playerid) return (AntiCamp[playerid][_AntiCamp_Timer] != -1) ? (1) : (0);
Advertisement
Add Comment
Please, Sign In to add comment