PHP Code:
//Create a reset timer function
public void ResetTimer(int client)
{
if (!bIsBeingPunished[client] || g_anticampdisabled)
{
delete(g_hClientTimers[client]);
delete(g_hPunishTimers[client]);
delete(g_hFreqTimers[client]);
delete(g_hCooldownTimers[client]);
}
}
//Reset timer when client arrives
public void OnClientPutInServer(int client)
{
bIsBeingPunished[client] = false;
ResetTimer(client);
}
//Reset timer when client disconnects
public void OnClientDisconnect(int client)
{
ResetTimer(client);
}
//Reset timer when client changes team
public Action OnClientChangeTeam(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
ResetTimer(client);
}
//Reset timer when client dies
public Action OnClientDied(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
ResetTimer(client);
}
//Reset timer when the round ends
public Action Event_OnRoundEnd(Event event, const char[] name, bool dontBroadcast)
{
delete(g_AntiCampDisable);
for(int iClient = 1; iClient <= MaxClients; iClient++)
{
bIsBeingPunished[iClient] = false;
ResetTimer(iClient);
}
}
//Start timer when client enters a zone
public void Zone_OnClientEntry(int client, char[] zone)
{
if(client < 2 || client > MaxClients || !IsClientInGame(client) ||!IsPlayerAlive(client) || IsWarmup() || g_anticampdisabled)
return;
if((StrContains(zone, "AntiCampCT", false) == 0 && GetClientTeam(client) == 3) || (StrContains(zone, "AntiCampT", false) == 0 && GetClientTeam(client) == 2) || (StrContains(zone, "AntiCampBoth", false) == 0))
{
if (g_hCooldownTimers[client] == null)
{
delete(g_hClientTimers[client]);
if (IsFreezeTime())
{
g_hClientTimers[client] = CreateTimer(GetConVarFloat(cvar_time) + GetConVarFloat(FindConVar("mp_freezetime")), Timer_End, GetClientUserId(client));
}
else
{
g_hClientTimers[client] = CreateTimer(GetConVarFloat(cvar_time), Timer_End, GetClientUserId(client));
}
}
else
{
ResetTimer(client);
bIsBeingPunished[client] = true;
CPrintToChat(client, "%t", "Cooldown_Not_Expired");
SlapPlayer(client, GetConVarInt(g_SlapDamage), true);
g_hFreqTimers[client] = CreateTimer(GetConVarFloat(g_PunishFreq), Repeat_Timer, GetClientUserId(client), TIMER_REPEAT);
}
}
}
//Stop timer when client leaves a zone
public void Zone_OnClientLeave(int client, char[] zone)
{
if(client < 2 || client > MaxClients || !IsClientInGame(client) || !IsPlayerAlive(client) || IsWarmup() || g_anticampdisabled)
return;
if((StrContains(zone, "AntiCampCT", false) == 0 && GetClientTeam(client) == 3) || (StrContains(zone, "AntiCampT", false) == 0 && GetClientTeam(client) == 2) || (StrContains(zone, "AntiCampBoth", false) == 0))
{
bIsBeingPunished[client] = false;
ResetTimer(client);
if ((GetConVarInt(g_CooldownDelay) != 0) && ((g_hPunishTimers[client] != null) || (g_hFreqTimers[client] != null)))
{
g_hCooldownTimers[client] = CreateTimer(GetConVarFloat(g_CooldownDelay), Cooldown_End, GetClientUserId(client));
}
}
}
//What to do when the cooldown ends
public Action Cooldown_End(Handle timer, int UserId)
{
int client = GetClientOfUserId(UserId);
if(!client)
{
return;
}
CPrintToChat(client, "%t", "Cooldown_Expired");
g_hCooldownTimers[client] = null;
}
//What do to when the main timer ends
public Action Timer_End(Handle timer, int UserId)
{
int client = GetClientOfUserId(UserId);
if(!client)
{
return;
}
g_hClientTimers[client] = null;
if ( client && IsClientInGame(client) && IsPlayerAlive(client))
{
delete(g_hPunishTimers[client]);
g_hPunishTimers[client] = CreateTimer(GetConVarFloat(g_PunishDelay), Punish_Timer, GetClientUserId(client));
PrintCenterText(client, "%t", "Camp_Message_Warning", GetConVarInt(g_PunishDelay) );
}
}
//What to do when the punish timer ends
public Action Punish_Timer(Handle timer, int UserId)
{
int client = GetClientOfUserId(UserId);
if(!client)
{
return;
}
g_hPunishTimers[client] = null;
if (IsClientInGame(client) && IsPlayerAlive(client))
{
CPrintToChatAll("%t", "Camp_Message_All", client);
SlapPlayer(client, GetConVarInt(g_SlapDamage), true);
delete(g_hFreqTimers[client]);
bIsBeingPunished[client] = true;
g_hFreqTimers[client] = CreateTimer(GetConVarFloat(g_PunishFreq), Repeat_Timer, GetClientUserId(client), TIMER_REPEAT);
}
}
public Action Repeat_Timer(Handle timer, int UserId)
{
int client = GetClientOfUserId(UserId);
if(!client) {
return Plugin_Stop; // Stop early, invalid client index.
}
if (!IsClientInGame(client) || !IsPlayerAlive(client))
{
bIsBeingPunished[client] = false;
g_hFreqTimers[client] = null;
return Plugin_Stop;
}
CPrintToChat(client, "%t", "Camp_Message_Self");
SlapPlayer(client, GetConVarInt(g_SlapDamage), true);
return Plugin_Continue;
}
public Action AntiCamp_Disable(Handle timer)
{
g_anticampdisabled = true;
CPrintToChatAll("%t", "AntiCamp_Disabled");
for(int iClient = 1; iClient <= MaxClients; iClient++)
{
ResetTimer(iClient);
}
g_AntiCampDisable = null;
}
bool IsWarmup()
{
return (GameRules_GetProp("m_bWarmupPeriod") == 1);
}
bool IsFreezeTime()
{
return(GameRules_GetProp("m_bFreezePeriod") == 1);
}