AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] Get the value of timer ? (https://forums.alliedmods.net/showthread.php?t=243052)

Arkarr 06-29-2014 05:00

[TF2] Get the value of timer ?
 
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 : http://puu.sh/9OZsl/44a4ef6260.jpg

Bacardi 06-29-2014 05:41

Re: [TF2] Get the value of timer ?
 
hmmm check ?
GetMapTimeLeft
GetMapTimeLimit

friagram 06-29-2014 07:09

Re: [TF2] Get the value of timer ?
 
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.

Arkarr 06-29-2014 07:28

Re: [TF2] Get the value of timer ?
 
Quote:

Originally Posted by Bacardi (Post 2159125)

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 ?

Powerlord 06-29-2014 10:28

Re: [TF2] Get the value of timer ?
 
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.

Arkarr 06-29-2014 10:56

Re: [TF2] Get the value of timer ?
 
@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 ?

Powerlord 06-29-2014 11:30

Re: [TF2] Get the value of timer ?
 
Quote:

Originally Posted by Arkarr (Post 2159288)
@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.

Powerlord 07-08-2014 17:34

Re: [TF2] Get the value of timer ?
 
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).

Dr. Greg House 07-08-2014 21:00

Re: [TF2] Get the value of timer ?
 
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.

Powerlord 07-09-2014 09:27

Re: [TF2] Get the value of timer ?
 
Quote:

Originally Posted by Dr. Greg House (Post 2164246)
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...


All times are GMT -4. The time now is 16:30.

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