Hi,
I'm trying to create a script that slaps someone every 2 seconds, 30 seconds into the round. However, the slap timer never stops, which means that on the next round start, everyone will be slapped instantly.. What am I doing wrong?
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <multicolors>
new Handle:g_timerAntiCamp1 = INVALID_HANDLE;
new Handle:g_timerAntiCamp2 = INVALID_HANDLE;
public OnPluginStart()
{
HookEvent("round_start", Round_Start_Hook);
HookEvent("round_end", Round_End_Hook);
}
public OnMapEnd()
{
g_timerAntiCamp1 = INVALID_HANDLE;
g_timerAntiCamp2 = INVALID_HANDLE;
}
public Action Round_Start_Hook(Handle event, const char[] name, bool dontBroadcast)
{
g_timerAntiCamp1 = CreateTimer(30.0, CheckRoundTime, TIMER_FLAG_NO_MAPCHANGE);
}
public Action Round_End_Hook(Handle event, const char[] name, bool dontBroadcast)
{
/* Clean up timers */
if (g_timerAntiCamp1 != INVALID_HANDLE) {
CloseHandle(g_timerAntiCamp1);
g_timerAntiCamp1 = INVALID_HANDLE;
}
if (g_timerAntiCamp2 != INVALID_HANDLE) {
CloseHandle(g_timerAntiCamp2);
g_timerAntiCamp2 = INVALID_HANDLE;
}
}
public Action CheckRoundTime(Handle:timer)
{
g_timerAntiCamp2 = CreateTimer(2.0, CheckPlayerZone, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
public Action CheckPlayerZone(Handle:timer)
{
for (new i = 1; i <= MaxClients; i++)
{
if (i >= 1 && i <= MaxClients && IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
{
SlapPlayer(i, 20, true);
CPrintToChat(i, "{green}You are getting slapped");
}
}
}