Example 1
PHP Code:
#include <sourcemod>
#define WHATEVER 120
new player_value[MAXPLAYERS+1];
public OnClientPostAdminCheck(client) //this usually called in sourcemod when client join the game OR client passed new map
{
CreateTimer(1.0 , player_Timer , client , TIMER_REPEAT); //repeated timer runs every 1 second (Repeted-Timers won't be stopped until you kill the handle)
}
public Action:player_Timer(Handle:Timer,any:client)
{
if (IsClientConnected(client) && player_value[client] <= WHATEVER )
{
PrintCenterText(client , "%d sec" , ++player_value[client] ); // 1 sec ... 2 sec ... 3sec ...
}
else
{
// in case Client Disconnected OR the timer finished its mission :
player_value[client]=0; // reset the value
return Plugin_Stop; //kill the repeated-timer
}
}
Some people prefer to Carry The Repeated Timer in a Specified Handle (SO THEY CAN LATERLY CHECK IF IS STILL RUNNING OR NOT) , here is an example 2 :
PHP Code:
#include <sourcemod>
#define WHATEVER 120
new player_value[MAXPLAYERS+1];
Handle player_hTimer[MAXPLAYERS+1]; // This Is The New Touch , Note : this will be automatically filled by values: INVALID_HANDLE;
public OnClientPostAdminCheck(client)
{
player_hTimer[client]= CreateTimer(1.0 , player_Timer , client , TIMER_REPEAT); //we attached the timer to a specific handle
}
public Action:player_Timer(Handle:Timer,any:client)
{
if (IsClientConnected(P) && player_value[client] <= WHATEVER )
{
PrintCenterText(client , "%d sec" , ++player_value[client] ); // 1 sec ... 2 sec ... 3sec ...
}
else
{
// in case Client Disconnected OR the timer finished its mission :
player_value[client]=0; // reset the value
player_hTimer[client]=INVALID_HANDLE; //its important to reset our handle To bring benefit from Check_Player_Timer()
return Plugin_Stop; //kill the repeated-timer
}
}
Check_Player_Timer(client)
{
if (player_hTimer[client]!=INVALID_HANDLE)
{
//in this case we got sure that timer of client is still running
//to kill it imediatelly We have to do this :
CloseHandle(player_hTimer[client]); //CloseHandle(Avaliabe_handle) Or KillTimer(Avaliabe_handle) so the repeated-timer above will return Plugin_Stop and stop working
player_hTimer[client]=INVALID_HANDLE; //reset our handle to null so We can get benefit again from Check_Player_Timer() function;
player_value[client]=0;
}
}