View Single Post
Author Message
TheFlyingApple
Member
Join Date: Aug 2016
Old 03-08-2020 , 17:04   CloseHandle is not stopping TIMER_REPEAT?
Reply With Quote #1

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[] namebool dontBroadcast)
{    
    
g_timerAntiCamp1 CreateTimer(30.0CheckRoundTimeTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Round_End_Hook(Handle event, const char[] namebool 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.0CheckPlayerZoneTIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}

public 
Action CheckPlayerZone(Handle:timer
{
    for (new 
1<= MaxClientsi++)
    {
        if (
>= && <= MaxClients && IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i))
        {

            
SlapPlayer(i20true);
            
CPrintToChat(i"{green}You are getting slapped");
        }
    }


Last edited by TheFlyingApple; 03-08-2020 at 17:04.
TheFlyingApple is offline