This approach does not seem to work properly on some maps, particularly KOTH, which has more than one round timer that must be checked. In
NoobBalance, I used an approach like the following, which seemed to be quite reliable in my testing:
Code:
//Global variables
new bool:round_is_timed = false; //True if this is a timed round
new Float:round_end_time; //Contains the round end time (compare to GetGameTime()'s return value) if round_is_timed is true
public OnPluginStart()
{
HookEvent("teamplay_setup_finished", hook_setup_finished, EventHookMode_PostNoCopy);
HookEvent("teamplay_timer_time_added", hook_timer_time_added, EventHookMode_PostNoCopy);
}
stock GetRoundTimerInformation()
{
new round_timer = -1;
new Float:best_end_time = 1000000000000; //a very large "time"
new Float:timer_end_time;
new bool:found_valid_timer = false;
new bool:timer_is_disabled = true;
new bool:timer_is_paused = true;
while ( (round_timer = FindEntityByClassname(round_timer, "team_round_timer")) != -1) {
//Make sure this timer is enabled
timer_is_paused = bool:GetEntProp(round_timer, Prop_Send, "m_bTimerPaused");
timer_is_disabled = bool:GetEntProp(round_timer, Prop_Send, "m_bIsDisabled");
//End time is what we're interested in... fortunately, it works
// (getting the current time remaining does NOT work as of late November 2010)
timer_end_time = GetEntPropFloat(round_timer, Prop_Send, "m_flTimerEndTime");
if (!timer_is_paused && !timer_is_disabled && (timer_end_time <= best_end_time || !found_valid_timer)) {
best_end_time = timer_end_time;
found_valid_timer = true;
}
}
if (found_valid_timer) {
round_end_time = best_end_time;
round_is_timed = true;
} else {
round_is_timed = false;
}
}
public hook_timer_time_added(Handle:event, const String:name[], bool:dontBroadcast)
{
GetRoundTimerInformation();
}
public hook_setup_finished(Handle:event, const String:name[], bool:dontBroadcast)
{
GetRoundTimerInformation();
}
The above code is quite stripped down, and of course may contain bugs. It will only report correctly during the game, as I left out the sections that track the current game stage. The complete implementation I settled on is available in the source code to NoobBalance. I ended up just having to call GetRoundTimerInformation() regularly as I couldn't be bothered to chase down every possible event that could adjust the timers; doing it this way is a little more future-proof anyway.