Count Down Timer

Tutorial collection, comprehensive listings on main site.

Count Down Timer

Postby Tutorial on Tue Sep 04, 2007 9:11 pm

category
General Half-Life 2/Entities

description
Another fantastic tutorial, this time covering a count down clock with entities.

keywords
counter, clock, count, advanced, math_counter.

Count Down Timer Tutorial
Written By Slutty_hoe
If you have any problems during this tutorial please do not hesitate to either pm me (slutty_hoe) or email me slut-ty-hoe[at]hotmail[dot]com or post a reply

This is a tutorial on how to make a visible in game counter to display any amount of time
This is a fairly long but easy if you are ok with the input output system.
The only hard part is setting each individual number
This tutorial can be used in any source mod as long as it has Func_brush, Logic_relay and a way to trigger it.

First make a room in which to place your countdown timer (I’ve made my big and added a door to it for the example map reasons.)

Add a black background for which the countdown timer will sit (optional)

Image

Create a red colored brush (red texture with the example map) and chop off the ends (this is purely to make it look better doesn’t need to be done) Form the brushes into a shape of a digital clock 8.

Image

Copy and paste it 4 times along side each other and add the little dots

Image

Go to the right hand side “8” and select the top brush. Make it a func_brush and call it count_down_digit1_a (can be changed this just keeps it neat and logical for later on)

Image

Now name the rest going from left to right up to down.

Image

You should now have 7 func_brush

count_down_digit1_a
count_down_digit1_b
count_down_digit1_c
count_down_digit1_d
count_down_digit1_e
count_down_digit1_f
count_down_digit1_g

Depending on how long you want your counter to go for (mines going for 1 minute or 60 seconds) name the next digit like the other one but changing count_down_digit1_a
to count_down_digit2_a

Image
(This is showing the digit number and the letter)

Now I want the timer to when it’s not counting down the time to display all zeros. So delete the middle of the unused numbers, the other 2 number middles select press alt + enter, go to start disabled, and change it to yes.

Image

Now I will quickly setup the button to trigger the start of the countdown. (You can have it triggered by something else but I won’t cover that in this tut it’s just the same output on something else) Ok Setup the button to your liking and go to outputs

Now we want.
My output named: OnPressed
Target entities: Count_down
Via This input: Trigger
Also tick fire only once

Image

And if you’re triggering something after the countdown

My output named: OnPressed
Target entities: Door
Via This input: Open
After a Delay: 60

Image

Now here comes the real fun part. I’m not sure if this is the best way to do it but it’s a way to do it and it does work.

Make 10 logic_relays

Name 1 of them each
count_down_digit1_0
count_down_digit1_1
count_down_digit1_2
count_down_digit1_3
count_down_digit1_4
count_down_digit1_5
count_down_digit1_6
count_down_digit1_7
count_down_digit1_8
count_down_digit1_9

Image

Open up count_down_digit1_1
Go to the output and add

My output named: OnTrigger
Target entities: count_down_digit1_a
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_b
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_c
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_d
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_e
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_f
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit1_g
Via This input: Enable

Now select them all and press copy. This just makes it easy to setup the rest of them

Image

Ok now because we want this to make the number one we are going to need to make only the 2 upright brushes to enable. So if you remember what we named each individual brush we are only going to need count_down_digit1_c and count_down_digit1_f so select the rest of them and change enable to disable. Press apply.

Image

What we just told it to do will make it once triggered look like this

Image

Ok so if you’re a little lost I’ll explain what this is doing if you’re not go to the next paragraph. What we are doing is setting up just pre configured outputs so later on we will have a nother logic_relay to trigger all those logic_relays. When each logic_relay is triggered it will make what we set to enable to show up and what we set to disabled to disappear. So if we triggered count_down_digit1_1 it will make all the other red parts disappear that we don’t wont up there. It’s confusing I know but hang on and you will start to see.

Now we have to setup the rest of the digits. Open up number count_down_digit1_2
Go to the output section and paste in all the enables. (this is why I told you to do that, It just makes it a heck of a lot easier). Now for the number 2 we want count_down_digit1_b and count_down_digit1_f to be disabled. Select those 2 and set it to disabled.

Image

In game it will look like

Image

Ok now keep doing so for the rest of the numbers. (I have kindly posted pictures of both the number and the output system. And Ignore the top of the entity name I have managed to stuff it up its still correct in order going 3,4,5,6,7,8,9,0)

Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image


See lots of fun. Now we need to do it again 6 more times =D (horray)

Make 6 more logic_relays
Name them
count_down_digit2_0
count_down_digit2_1
count_down_digit2_2
count_down_digit2_3
count_down_digit2_4
count_down_digit2_5

Now there’s 2 ways of doing this you can either go to the corresponding number on the other ones and copy it and change the digit number or you can do it how we did those. But I’m going to assume (after doing all of those) you know how to setup the 6 logic relays there

Well heres the one for count_down_digit2_1

My output named: OnTrigger
Target entities: count_down_digit2_a
Via This input: Disable

My output named: OnTrigger
Target entities: count_down_digit2_b
Via This input: Disable

My output named: OnTrigger
Target entities: count_down_digit2_c
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit2_d
Via This input: Disable

My output named: OnTrigger
Target entities: count_down_digit2_e
Via This input: Disable

My output named: OnTrigger
Target entities: count_down_digit2_f
Via This input: Enable

My output named: OnTrigger
Target entities: count_down_digit21_g
Via This input: Disable

Ok that’s about 2/3rd’s of the tutorial done and wasn’t it fun.

Now we just have to make it setoff when we want it to.

Now we need 3 more logic_relays you can just make one but this is the neat and tidy way.

Add them in and call them

count_down
count_down_digit1
count_down_digit2

Now go to the output of count_down and add:

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 0

My output named: OnTrigger
Target entities: count_down _digit2
Via This input: Trigger
After a delay: 0

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 10

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 20

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 30

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 40

My output named: OnTrigger
Target entities: count_down_digit1
Via This input: Trigger
After a delay: 50

Image

Ok that’s that done. So what that does is the button will trigger that which will trigger the number to run through there cycle once we have set it up.

Ok now open up cound_down_digit1 and add these outputs

My output named: OnTrigger
Target entities: count_down_digit1_9
Via This input: Trigger
After a delay: 0

My output named: OnTrigger
Target entities: count_down_digit1_8
Via This input: Trigger
After a delay: 1

My output named: OnTrigger
Target entities: count_down_digit1_7
Via This input: Trigger
After a delay: 2

My output named: OnTrigger
Target entities: count_down_digit1_6
Via This input: Trigger
After a delay: 3

My output named: OnTrigger
Target entities: count_down_digit1_5
Via This input: Trigger
After a delay: 4

My output named: OnTrigger
Target entities: count_down_digit1_4
Via This input: Trigger
After a delay: 5

My output named: OnTrigger
Target entities: count_down_digit1_3
Via This input: Trigger
After a delay: 6

My output named: OnTrigger
Target entities: count_down_digit1_2
Via This input: Trigger
After a delay: 7

My output named: OnTrigger
Target entities: count_down_digit1_1
Via This input: Trigger
After a delay: 8

My output named: OnTrigger
Target entities: count_down_digit1_0
Via This input: Trigger
After a delay: 9

Image

Ok done. Last thing to do is open cound_down_digit2 and add in outputs

My output named: OnTrigger
Target entities: count_down_digit2_5
Via This input: Trigger
After a delay: 0

My output named: OnTrigger
Target entities: count_down_digit2_4
Via This input: Trigger
After a delay: 10

My output named: OnTrigger
Target entities: count_down_digit2_3
Via This input: Trigger
After a delay: 20

My output named: OnTrigger
Target entities: count_down_digit2_2
Via This input: Trigger
After a delay: 30

My output named: OnTrigger
Target entities: count_down_digit2_1
Via This input: Trigger
After a delay: 40

My output named: OnTrigger
Target entities: count_down_digit2_0
Via This input: Trigger
After a delay: 50

Image

Last thing I swear. This is just to make it look like a countdown timer. Select the two middle dots and make them a func_brush call them cound_down_dot

Now make 2 logic_timers and a logic_auto
For the logic timers set re fire interval to 2
Make 1 of the logic_timers to have an output of

My output named: OnTimer
Target entities: count_down_dot
Via This input: Enable
After a delay: 0

Name The other logic_timer Timer and set start disabled to yes. Add output of

My output named: OnTimer
Target entities: count_down_Dot
Via This input: Disable
After a delay: 0

Now go to your logic_auto and add an output of

My output named: OnMapSpawn
Target entities: Timer
Via This input: Enable
After a delay: 1


CONGRATULATIONS!!!!!
Be proud of yourself you just went through possibly the longest tutorial ever but I doubt that. Now compile your map and test if it works (hopefully it will other wise just chuck a fit =O)

What should happen is when you press the button it starts the counter and when the counter hits 0 the door should open. I don’t know where you want this in your level you could possibly use it as a stand of thing for 5 minutes and its just telling you how long you have left. But this is how I have done it probably not the best way but it is a way to do it. Have fun mapping.

Example Map
Click here

Here’s a video from my example map
http://www.youtube.com/watch?v=WomRy0U7VqU
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Postby alpha on Sat Dec 15, 2007 5:03 pm

Is there a chance the example map can be re-uploaded? :)
alpha
Member
Member
 
Joined: Sun Dec 17, 2006 3:19 am

Postby zombie@computer on Sat Dec 15, 2007 9:34 pm

Okay, because i was really bored, i decided to take this concept and turn it into a real counter. It actually counts :P Nah, the effect is the same, though it takes a lot less ents. Ready?

I will start with a single digit counter, cause thats the basis of every counter, no?

Image

You should now have 7 func_brush

counter_digits_0_a
counter_digits_0_b
counter_digits_0_c
counter_digits_0_d
counter_digits_0_e
counter_digits_0_f
counter_digits_0_g

Next, add a logic_branch. This nifty logic entity is going to replace 10 of those logic_triggers. Cool huh?

I suggest that, instead of disabling the func_brushes you do not need to make the certain digit, you simply disable all func_brushes using the * output, likeso

OnCase01 counter_digits_0_* Disable

and then enable the func_brushes you want to show with a 0.01 sec delay. The reverse, enabling all brushes and disable all those you dont need, is offcourse also possible (eg for 6, enable all, then disable _b) Offcourse its a little less pretty, so you can choose to do this the hard way if you so desire.

If you go with the less tidy (but easier and more efficient) one, youll have an outputlist of the logic_branch like this:

Code: Select all
MyOutput   Target         Output  Delay
-----------------------------------------------------
OnCase01   counter_digits_0_*   Disable   0
OnCase01   counter_digits_0_c   Enable   0.01
OnCase01   counter_digits_0_f   Enable   0.01
OnCase02   counter_digits_0_*   Enable   0
OnCase02   counter_digits_0_b   Disable   0.01
OnCase02   counter_digits_0_f   Disable   0.01
OnCase03   counter_digits_0_*   Enable   0
OnCase03   counter_digits_0_b   Disable   0.01
OnCase03   counter_digits_0_e   Disable   0.01
OnCase04   counter_digits_0_*   Enable   0
OnCase04   counter_digits_0_a   Disable   0.01
OnCase04   counter_digits_0_e   Disable   0.01
OnCase04   counter_digits_0_g   Disable   0.01
OnCase05   counter_digits_0_*   Enable   0
OnCase05   counter_digits_0_e   Disable   0.01
OnCase05   counter_digits_0_c   Disable   0.01
OnCase06   counter_digits_0_*   Enable   0
OnCase06   counter_digits_0_c   Disable   0.01
OnCase07   counter_digits_0_*   Disable   0
OnCase07   counter_digits_0_a   Enable   0.01
OnCase07   counter_digits_0_c   Enable   0.01
OnCase07   counter_digits_0_f   Enable   0.01
OnCase08   counter_digits_0_*   Enable   0
OnCase09   counter_digits_0_*   Enable   0
OnCase09   counter_digits_0_e   Disable   0.01
OnCase10   counter_digits_0_*   Enable   0
OnCase10   counter_digits_0_d   Disable   0.01
As you can see, each OnCase statement will show the corresponding digit. Case10 shows a 0. Give the logic_case a name (eg counter_case_0 ) and set its OnCase01 property to 1, Oncase02 to 2 etc till OnCase10, which should be 0.

Ok, so now we have a logic_case that will display the corresponding digit of its inValue. We give the inValue with a math_counter offcourse
The math_counter only needs one output for this
Code: Select all
MyOutput   Target      Output  Delay
---------------------------------------------
OutValue   counter_case_0   InValue   0
. Give it a name too (eg counter_math_0 )
So now the brush-based digit will display the value of the math_counter when thats changed ingame.
Now you can make as many digits as you’d like. Make sure all entities are unique, i suggest, atleast for this tutorial, to use the number in each entity name for that.

The digit representing x0 seconds and x0 minutes only goes to six, so you can drop some OnCase statements there
Code: Select all
MyOutput   Target         Output  Delay
-----------------------------------------------------
OnCase01   counter_digits_0_*   Disable   0
OnCase01   counter_digits_0_c   Enable   0.01
OnCase01   counter_digits_0_f   Enable   0.01
OnCase02   counter_digits_0_*   Enable   0
OnCase02   counter_digits_0_b   Disable   0.01
OnCase02   counter_digits_0_f   Disable   0.01
OnCase03   counter_digits_0_*   Enable   0
OnCase03   counter_digits_0_b   Disable   0.01
OnCase03   counter_digits_0_e   Disable   0.01
OnCase04   counter_digits_0_*   Enable   0
OnCase04   counter_digits_0_a   Disable   0.01
OnCase04   counter_digits_0_e   Disable   0.01
OnCase04   counter_digits_0_g   Disable   0.01
OnCase05   counter_digits_0_*   Enable   0
OnCase05   counter_digits_0_e   Disable   0.01
OnCase05   counter_digits_0_c   Disable   0.01
OnCase06   counter_digits_0_*   Enable   0
OnCase06   counter_digits_0_d   Disable   0.01
Only in this case, the last case, 06, shows a 0 digit (0:59 -> 1:00, you never see the 6 )

Lastly, make sure each counter_digits_*_* func_brush is disabled or enabled accordingly to show the starting time of your counter (eg for 00:00, make all counter_digits_*_e start disabled). Then, the basics are done.

Now you got some digits, its time to start counting. There are two different timers we can make. Going up, and going down. First, going up

Going up
Go to each math_counter, and change:

Maximum legal value to 10 (set it to 6 for those limited numbers as described above)
Code: Select all
MyOutput   Target      Output  Parameter Delay
-------------------------------------------------------
OutValue   yyy   InValue   0
OnHitMax   !self   SetValue   0   0
OnHitMax   xxx   Add      1   0

Where yyy = the corresponding logic_case (you should have already made this output, dont change it) and xxx = the name of the math_counter representing the next (=left) digit (im sure you can imagine that if the first digit is 10, it should instantly become 0 and the digit left of it gets one up) eg counter_math_1
The most left digit can’t have the last output offcourse.

Set each starting value to the starting value of that digit (0-9)

We are allmost done here. Now all we need to do is actually make the timer

So, create a logic_timer, and give it the following output
Code: Select all
MyOutput   Target         Output  Parameter Delay
OnTimer   counter_math_0   Add   1   0
Set the refireInterval to 1, and set it up so it starts when you want it to (default=on level load) And that is all. You now have a working counter that can count to as many digits as you’d like

Going down
going down is similar in setup to going up, only in reverse (duh). A wee bit harder to setup tho

Go to each math_counter, and change:

Minimum legal value to –1

Code: Select all
MyOutput   Target      Output  Parameter Delay
-------------------------------------------------------
OutValue   yyy   InValue   0
OnHitMin   !self   SetValue   #   0
OnHitMin   xxx   Substract   1   0

Where yyy = the corresponding logic_case (you should have already made this output, dont change it) and xxx = the name of the math_counter representing the next (=left) digit (im sure you can imagine that if the first digit is -1, it should instantly become 9 and the digit left of it gets –1) eg counter_math_1
The most right digit can’t have the last output offcourse. # Should be the Max value that digit can legally take (6 or 9, depending on place). Make sure this timer stops before it reaches 0, or itll look weird (this thing CAN’t COUNT negatively. If you want it to, experiment yourself on how to do that. Its not hard.

Set each starting value to the starting value of that digit (0-9)

We are allmost done here. Now all we need to do is actually make the timer

So, create a logic_timer, and give it the following output
Code: Select all
MyOutput   Target         Output  Parameter Delay
OnTimer   counter_math_0   Substract   1   0
Set the refireInterval to 1, and set it up so it starts when you want it to (default=on level load) And that is all. You now have a working counter that can count from as many digits as you’d like to 0

Optional
  • You can add milliseconds to the timer, just set the refireInterval of the logic_timer to 0.01
  • To make the counter stop after a certain amount of time use a trigger delay to stop the logic_timer xxx seconds after you started it.
To add those dotty things in the middle:
Create them as func_brush, eg named counter_dots
Add a logic_trigger, with the outputs
Code: Select all
MyOutput   Target      Output  Delay
OnTrigger   counter_dots   Enable   0
OnTrigger   !self   Disable   0
OnTrigger   counter_dots   Disable   1
OnTrigger   !self   Enable   1.50

Make the logic_trigger start disabled, and the counter_dots enabled when the timer starts at an even amount of seconds and vice-versa.

Now retrigger this logic_trigger each second (using the 0x second math_counter or the logic_timer) and you are set to go

There. Easier, faster, more efficient. Like a Japaneese car
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Postby Woe Kitten on Sat Dec 15, 2007 10:43 pm

lol at this insanely compilcated way to do things.

Why not just have a texture with frames 0-9 each with the number 0-9 on them. Then just cycle through the textures? That's what I've always done. It's sure as hell a lot simpler than either of these methods.
Woe Kitten
BioWare
 
Joined: Fri Jan 06, 2006 8:01 pm
Location: Edmonton

Postby Grantax on Thu Jan 03, 2008 7:39 pm

I tried to make something using math_counter.
I avoided using GetValue since I have no idea how it works (it didn't work as I expected), and because I'm not sure if it's works at all outside Episode 2.

The first version uses 4 math_counters, each one holds a digit.
The timer subtracts 1 from the math_counter that holds the 'smallest' digit, which acts upon the result (if 0, it will start a chain that will go until it finds a number that is higher than 0, if the chain goes to the end, all digits are 0, and an output is fired, if it finds a number, 1 is subtracted, all the numbers 'below' it are reset)
It uses 4x math_counter, 4x logic_case, 3x logic_branch and a logic_timer.
Plus the brushes of course

Example 2 was supposed to use a math_counter to hold the value of the total amount of seconds remaining, and calculate the value for each single digit.
If valve's warning telling you to use "ONLY INTEGER VALUES!" was true, the example would actually work.
Using the 'developer 2', I discovered that the numbers were floats.
It used the same logic_cases as the previous example, 10 math_counters and a logic_timer.

I'll upload the file(s) after I find a host.
Or make a tutorial if anyway needs one.
Grantax
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Tue Mar 14, 2006 1:33 pm
Location: Norway

Re: Count Down Timer

Postby Toeman1 on Fri Aug 28, 2009 7:32 am

I DID IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! YAAAAAAAAAAAAAAAAYYYYYYYY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D:D :D :D :D :D :D :D :D :D :D :D :D :D :D
:[]: "All You Need Is Love"
Toeman1
Regular
Regular
 
Joined: Tue Jul 22, 2008 2:16 am

Return to Tutorials

Who is online

Users browsing this forum: No registered users