Timers
Posted: Fri Aug 14, 2026 9:00 pm
I'm currently making a TKOTH plugin that uses a timer and i figured that I'd share the timer code because some people need help with timers. This example uses a small struct for teams and it shows how easy OOP can be.
Now this is plugin specific, but you can easily modify it to fit your plugin's needs.
Then you'd simply do what you need to do, i.e.
Pretty simple, eh?
Code: Select all
#include <amxmodx>
#include <cstrike>
/*enum CsTeams {
CS_TEAM_UNASSIGNED = 0,
CS_TEAM_T = 1,
CS_TEAM_CT = 2,
CS_TEAM_SPECTATOR = 3
};*/
new bool:isTimerOn[CsTeams];
new zonetime[CsTeams];
new TimerID[CsTeams];
startTimer(CsTeams:team)
{
if(isTimerOn[team])
return 0;
set_task(1.0,"Tick",TimerID[team],team,sizeof(team),"b");
isTimerOn=true;
}
Tick(CsTeams:team)
{
zonetime[team]++;
}
stopTimer(CsTeams:team)
{
remove_task(TimerID[team]);
isTimerOn=false;
resetTimer(team);
}
resetTimer(CsTeams:team)
{
zonetime[team]=0;
}
pauseTimer(CsTeams:team)
{
remove_task(TimerID[team]);
isTimerOn=false;
}
currentTime(CsTeams:team)
return zonetime[team];Then you'd simply do what you need to do, i.e.
Code: Select all
new bool:inzone[Team]
docheck();
if(inzone[CS_TEAM_T] && !lastcheck[CS_TEAM_T])// if they are now in the zone and wasn't before
startTimer(CS_TEAM_T);
if(!inzone[CS_TEAM_T] && lastcheck[CS_TEAM_T]) // if they were in the zone but aren't anymore
stopTimer(CS_TEAM_T);
// do same with CT and make an update task every second or so