Raised This Month: $ Target: $400
 0% 

[TF2] Get the time left in a round


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Doctor Noob
Junior Member
Join Date: Nov 2010
Old 12-07-2010 , 01:09   Re: [TF2] Get the time left in a round
Reply With Quote #3

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.
Doctor Noob is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode