Please or Register to create posts and topics.

In-Game Timer

Page 1 of 3Next

Hi, I want to create an on-screen timer (Like challenge mode maps) in my map that starts with a trigger, and ends with a trigger. Once the ending trigger is hit, the time stays on the screen for a while, and then fades. What would be an easy, clean way to create this?

My Hammer Maps
[Released] Power Interference
[Released] Rust and Dust (Spotlight Map!)
[Released] Multiportal

Use 2 game_texts (minute, second) with 2 math_counters and a logic_timer subtracting one from the seconds. OutValue -> game_text -> SetText, OnHitMin -> minutes -> Subtract -> 1, OnHitMin -> !self -> SetValue -> 59 (after 1 second).

Falsi sumus crusto!
FelixGriffin wrote:
Use 2 game_texts (minute, second) with 2 math_counters and a logic_timer subtracting one from the seconds. OutValue -> game_text -> SetText, OnHitMin -> minutes -> Subtract -> 1, OnHitMin -> !self -> SetValue -> 59 (after 1 second).

Is that a timer ticking down? I need a timer ticking up.
Is there a more detailed tutorial somewhere? I'm not that familiar with logic_timers.

My Hammer Maps
[Released] Power Interference
[Released] Rust and Dust (Spotlight Map!)
[Released] Multiportal

https://developer.valvesoftware.com/wiki/Logic_timer
https://developer.valvesoftware.com/wiki/Math_counter
https://developer.valvesoftware.com/wiki/Game_text

Presto!

(You can easily convert Felix's example to a stopwatch-style timer by reversing the various min/max and add/subtract things.)

Sendificate series: Sendificate | A Beam Too Far | Airtime | 302
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic

Would be nice if you could somehow figure out how to overlay an in-game timer on any map you play...would make recording speedruns of custom maps a lot easier with a more universal timer.

I could try writing a script to do that, it should be possible using AddOutput and SetX/SetY. Just make something RunScriptCode it, preferably something unmoving. The worldspawn, maybe?

Falsi sumus crusto!
FelixGriffin wrote:
I could try writing a script to do that, it should be possible using AddOutput and SetX/SetY. Just make something RunScriptCode it, preferably something unmoving. The worldspawn, maybe?

Why aren't you community contributor? You are awesome dude, you make great stuff, and you helped me with the most important part in my map. Always volunteering to create amazing things for others.
:thumbup: I'll discuss it with the other mods.

Also... that'd be cool!

My Hammer Maps
[Released] Power Interference
[Released] Rust and Dust (Spotlight Map!)
[Released] Multiportal
FelixGriffin wrote:
I could try writing a script to do that, it should be possible using AddOutput and SetX/SetY. Just make something RunScriptCode it, preferably something unmoving. The worldspawn, maybe?

Yes, please. That would help a huge amount.

The only problem with changing a game_text is that you constantly need to display the game_text in order for it not to 'fade'. I would have the hold time at a second and the fade times at 0 so then you can use the 'Display' input to update every second without the game_text overlaying itself and becoming very bright.

Here's some code I made up if you want to continue working on it. There might be a couple of errors because I haven't actually tested it yet.

Code: Select all
//Global counter
counter <- 0

//Display time
function DisplayText()
{
   EntFire( "@DisplayText", "setText", ConvertToFormat(), 0 )
   EntFire( "@DisplayText", "Display", "", 0.01 )

   //Trigger the relay for each second
   counter++
   //The relay here should just call the DisplayText() function
   EntFire( "@DisplayText_Relay", "Trigger", "", 1.0 )
}

function ConvertToFormat()
{
   //using modulus logic we can figure out hours mins and left over seconds from counter
   local modMinuteSeconds = counter % 3600
   local hours = (counter - modMinuteSeconds) / 3600
   local modSecs = modMinuteSeconds % 60
   local mins = (modMinuteSeconds - modSecs) / 60
   local secs = modSecs

   local Smins = ""
   local Ssecs = ""

   if(mins < 10)
   {
      Smins = "0" + mins.tostring()
   }
   else {
      Smins = mins.tostring()
   }
   if(secs < 10)
   {
      Ssecs = "0" + secs.tostring()
   }
   else {
      Ssecs = secs.tostring()
   }

   //Insert time conversion here from seconds from counter to relevant format 00:00:00

   local displayTime = hours  + ":" + Smins  + ":" + Ssecs
   return displayTime
}

// Setup Game_Text - called on mapspawn
function SetPos()
{
printl("starting timer")

   EntFire( "@DisplayText", "SetTextColor", "210 210 210 128", 0.0 )
   EntFire( "@DisplayText", "SetTextColor2", "50 90 116 128", 0.0 )
   EntFire( "@DisplayText", "SetPosY", "0.85", 0.0 )
   EntFire( "@DisplayText", "SetPosX", "0.1", 0.0 )
   EntFire( "@DisplayText", "SetText", "00:00:00", 0.0 )

   DisplayText()
}

Ok So it works and I tested it. Here's the script file and all the entities in a .vmf you will need in order to get this to work:

counter.7z

I beat you Felix G!

Hope this is what you want UsCobra. You can change the position of the text inside the .nut file.

?????????????????????????????TWP Releases | My Workshop

Nice! So far the only thing I have working is creating the entities from the NUT

Code: Select all
function init(){
   timer <- Entities.CreateByClassname("logic_timer"); //The timer
   EntFireByHandle(timer,"refiretime","1",0,null,null); //Set the timer to 1 second
   EntFireByHandle(timer,"addoutput","targetname felix_script_timer",0,null,null);
   text1 <- Entities.CreateByClassname("game_text");
   text2 <- Entities.CreateByClassname("game_text");
   EntFireByHandle(text1,"addoutput","targetname felix_script_text1",0,null,null);
   EntFireByHandle(text2,"addoutput","targetname felix_script_text2",0,null,null);
...etc...

I'll change the names to work with your part, then you can run it without anything special in the BSP file. Just bind something to ent_fire worldspawn runscriptfile timerscript.nut and hit it to start the clock.

Falsi sumus crusto!
Page 1 of 3Next