Raised This Month: $32 Target: $400
 8% 

[TF2] Get the value of timer ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-29-2014 , 05:00   [TF2] Get the value of timer ?
Reply With Quote #1

I'm trying to get the value of the timer in some maps, so when it reach 0:00 it should change map, even if objectives aren't done (Like all control point captured).

I already try to get it by using this but it seems that it always return the value defined by the cvar mp_roundtime and not the actual timer value.

Just in case, I'm trying to speak about this timer :
__________________
Want to check my plugins ?
Arkarr is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-29-2014 , 05:41   Re: [TF2] Get the value of timer ?
Reply With Quote #2

hmmm check ?
GetMapTimeLeft
GetMapTimeLimit
Bacardi is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 06-29-2014 , 07:09   Re: [TF2] Get the value of timer ?
Reply With Quote #3

I asked powerlord about this a while ago, and he had a solution, I think.
I ended up using a different method though, because I just needed the round time.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 06-29-2014 at 07:09.
friagram is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-29-2014 , 07:28   Re: [TF2] Get the value of timer ?
Reply With Quote #4

Quote:
Originally Posted by Bacardi View Post
retrun me some random int, I don't understand how to use this function
I did this :
PHP Code:
new timeleft 0;
    
GetMapTimeLimit(timeleft); //GetMapTimeLeft() = random int too...
    
PrintToServer("time left : %i"timeleft);
    if(
timeleft >= 3)
        
MapChangeTimer CreateTimer(float(timeleft), TMR_GetTimerValue); 
EDIT:
@friagram
No way to get your stock/way you did this ? Because I need the round time too. Or should I ask Powerlord ?
__________________
Want to check my plugins ?

Last edited by Arkarr; 06-29-2014 at 07:36.
Arkarr is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-29-2014 , 10:28   Re: [TF2] Get the value of timer ?
Reply With Quote #5

In TF2, round timers are entities named team_round_timer (of class CTeamRoundTimer).

If you want to find the actual time, you need to loop through the timers and check for the timer that has the m_bShowInHUD netprop set to 1 (or true) and then check its m_flTimeRemaining netprop (which is a Float).
Edit: It may be the non-Float m_nTimerLength instead.

Having said that, when a team_round_timer hits 0 and the game isn't in overtime, it will fire its OnFinished output. Note that OnFinished does not fire when setup time ends.

There's one caveat to this: Waiting For Players time and arena preround time are ALSO implemented as team_round_timers, meaning that you need to be careful that the correct timers are being used for this.

Edit: Out of curiosity, why do you need this? TF2 usually ends the round when timers end... mp_maxrounds can be used to force mapchanges after certain number of rounds.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-29-2014 at 10:43.
Powerlord is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-29-2014 , 10:56   Re: [TF2] Get the value of timer ?
Reply With Quote #6

@Powerlord
That's some good infos I got there, thanks !
And it was to fire some random events (bonus for actual loosing teams or what ever, and also change map when timer reach 0.00) a certain time.
Anyway, according to what you say, setting mp_maxrounds to 0 will start next map when timer reach 0.00, right ?
__________________
Want to check my plugins ?
Arkarr is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-29-2014 , 11:30   Re: [TF2] Get the value of timer ?
Reply With Quote #7

Quote:
Originally Posted by Arkarr View Post
@Powerlord
That's some good infos I got there, thanks !
And it was to fire some random events (bonus for actual loosing teams or what ever, and also change map when timer reach 0.00) a certain time.
Anyway, according to what you say, setting mp_maxrounds to 0 will start next map when timer reach 0.00, right ?
mp_maxrounds 0 disables maxrounds checking. mp_maxrounds 1 would make the map change after a single full round.

Edit: Note that multi-round maps will only consider the round to be over if BLU wins all 3 rounds or RED wins any round. Except TC and PLR maps.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-29-2014 at 11:31.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-08-2014 , 17:34   Re: [TF2] Get the value of timer ?
Reply With Quote #8

Coming back to this after a week, the way to retrieve the current time left on a timer is (that isn't paused) is this:

Code:
GetEntPropFloat(timer, Prop_Send, "m_flTimerEndTime") - GetGameTime();
However, if you want to cover all your bases, here's Valve's SDK2013 CTeamRoundTimer::GetTimeRemaining converted into SourcePawn with some checks to make sure the entity you're passing in is actually a timer.

PHP Code:
stock GetTimeRemaining(timer)
{
    if (!
IsValidEntity(timer))
    {
        return -
1;
    }
    
    
decl String:classname[64];
    
GetEntityClassname(timerclassnamesizeof(classname));
    if (
strcmp(classname"team_round_timer") != 0)
    {
        return -
1;
    }
    
    new 
Float:flSecondsRemaining;
    
    if (
GetEntProp(timerProp_Send"m_bStopWatchTimer") && GetEntProp(timerProp_Send"m_bInCaptureWatchState"))
    {
        
flSecondsRemaining GetEntPropFloat(timerProp_Send"m_flTotalTime");
    }
    else
    {
        if (
GetEntProp(timerProp_Send"m_bTimerPaused"))
        {
            
flSecondsRemaining GetEntPropFloat(timerProp_Send"m_flTimeRemaining");
        }
        else
        {
            
flSecondsRemaining GetEntPropFloat(timerProp_Send"m_flTimerEndTime") - GetGameTime();
        }
    }
    
    return 
RoundFloat(flSecondsRemaining);

Note: To find out which timer is the active one, check the m_bShowInHUD netprop, but bear in mind this will not work in KOTH.

Note 2: m_nState has a value of 0 in setup and 1 at any other time (including waiting for players).
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-08-2014 at 17:37.
Powerlord is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 07-08-2014 , 21:00   Re: [TF2] Get the value of timer ?
Reply With Quote #9

If I recall correctly one of the "time"-props is used to store the time "the full clock" has.

If you want to trigger stuff to happen when the timer runs out, you might be better off playing with inputs/outputs.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 07-08-2014 at 21:03.
Dr. Greg House is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-09-2014 , 09:27   Re: [TF2] Get the value of timer ?
Reply With Quote #10

Quote:
Originally Posted by Dr. Greg House View Post
If I recall correctly one of the "time"-props is used to store the time "the full clock" has.
The full time of a team_round_timer will change as SetTime, AddTime, and AddTeamTime inputs are called. But yes, m_nTimerLength stores the "current" full time.

Incidentally, I wrote the above code because another project I'm working on now needs to stop doing something if there are less than 60 seconds on the clock, but since there isn't an output for when time is added to the clock...
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply


Thread Tools
Display Modes

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 21:24.


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