Please or Register to create posts and topics.

Portal 2 Timers example

===================
Portal 2 timer examples
===================

This is just an example map that includes the basics of 2 working timers (a countdown and a countup) that uses custom materials (numbers).

The intention is to show the required entities and their inputs/outputs to understand the logic behind a timer made in the hammer editor. Also this method allows you the posibility to use your own custom typo/numbers to fit your map's aesthetics...
For this example I used the typo "DIN Next LT Pro Condensed", because I think it's pretty much similar to the typo used by Valve for the signage lightboard; so if you are too lazy to make your own material and want to use it in a normal Portal2 map, it'll look good.

So the purpose for this could be considered as merely didactic :D

The basic idea under this method is to make an overlay with 10 frames (the ten numbers, from 0-9) and go changing its textureindex with the entity "env_texturetoggle".

HOW TO MAKE YOUR OWN CUSTOM NUMBERS
----------------------------------------------------------------

1. Open an image editor of your choice, take the font that you like and make 10 separate images, one per number (from 0 to 9), and REMEMBER to always give the image a size which values are a power of 2 (like 128x256 that I gave in this case). I prefer making .png files... you can do .tga as well... Whatever format that allows you recording an alpha channel (transparency) because this way, our numbers overlays would be stickable on whatever texture :)

2. Name each of them with a name followed by a suffix like "_0", "_1", "_2", and so on... Obviously, try to make that suffix coincides with the number into the image... lol.

3. Now open VTFEdit (http://nemesis.thewavelength.net/index.php?c=178) and go to File > Import. Now select at the same time (holding Ctrl or Shift keys down) all the ten image files. Do not resize the images. You can check into the "info" tab how the file contains 10 frames (each of them is a different number). I also made a cutie dots (":") to separate the seconds from the minutes and make them flicker: for this you need to make 2 textures, one with the dots and other completely empty but with the same size, then do the same as for the numbers, import them with VTFEdit selecting both at the same time.

4. Then save this file as .vtf into your "materials" folder (you can create whatever folder of your choice into /materials of course) giving it a whatever name.

5. Now you should create the .vmt file for the above .vtf file. Both names must be the same, only their extensions change... In this example, my .vmt file contains the following:

UnlitGeneric
{
$baseTexture "josepezdj/numbers/black_numbers"
$surfaceprop glass
$translucent 1
"%keywords" portal
$decal 1
Proxies
{
ToggleTexture
{
toggleTextureVar $baseTexture
toggleTextureFrameNumVar $frame
toggleTextureShouldWrap 0
}
}
}

You can simply copy all that only replacing the path "josepezdj/numbers/black_numbers" by the one where your .vtf file is located and the name of your file.

I guess it's clear. However, do not hesitate to ask whatever question or doubt :D

Once created your custom texture for the ten numbers, check inside the attached .vmf in your hammer editor to see how you can set the timers up easily.

Read the Readme.txt file for instructions info. A further post with an explanation in detail about how the timer system works is in the topic of this download, for those who doesn't really extract much info from the vmf file... :wink:

josepezdj

File Name: timer_test.7z
File Size: 322.5 KiB
Click here to download Portal 2 Timers example

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]

Inside the .vmf map file there are 4 main entities used to build the timers:

1. The env_texturetoggle. This is widely known by any hammer mapper, this entity allows you to change between the vtf file's different frames, like for example the indicator lights. Several textures can be stored inside the vtf files, and we can change amongst those stored textures by firing the output SetTextureIndex plus the value each frame or texture has inside the vtf.

2. The logic_timer. This entity is basically the counter: once enabled it runs and stores time. Here I've used 3 different logic_timers:

- One with refire interval set to "1" second which is in charge of firing an output "OnTimer > Add 1" every second to the math_counters. This logic_timer is the one that "changes" our numbers in the timer...
- Other with refire interval set to 0.5 secs. This one is for the dots in the timer that separate the minutes from the seconds; I liked this rate of 0.5 more than 1 sec to make these dots appear/disappear (switching from an invisible texture to the dots texture, both included into the same vtf file)
- And another logic_timer that I called "real_timer" because it's the one that is fired at the beginning (with the button... ofc you can set the system to start by any other output than pressing a button...) and we set in it the desired "real" time we need before the final event happens. In the countup example I set the refire interval to 90 secs, so the counter will stop at 1:30 and the event will happen then. In the countdown timer, this interval is 30 secs.

3. The math_counter. This entity allows us to store a value that we can manipulate by doing several kinds of calculations (firing outputs like Add / Subtract / Divide / Multiply ...) and then fire outputs depending on that value. In these timer examples I used basically 2 outputs: OutValue (fired each time the value inside the math_counter changes) that allows us to hand over the stored value to the logic_case entities; and OnHitMax that is fired when the value reaches the amount of seconds we have set in its "Maximum Legal Value" field. This "Max legal value" will be set up depending on how many values we want it to have. For the seconds (the most to the right number), as they can be from "0" to "9" we set the max. legal value to "10"; but the tens of second vary from 0 to 5 (as they can be up to 59 secs), so we have to set 6 as the max. legal value. For the dots, as they are 2 textures, the invisible one + the dots texture, the max legal value is 2.

4. The logic_case. This entity can receive the value from the math_counters and make that value match a given "case"; so to say, Case01 could be assigned a value of 1 (or 0 or 5...) for instance. Then we can fire outputs based in each case: OnCase01 > [whatever entity] > [does whatever thing] ...and this is like saying "when the value inside the logic_case is "1", then fire [whatever output]

* Also there are several logic_relays that is the most useful entity to store several I/O events. In this example map there are mainly 3 per counter:

- one with the "final event" outputs (open a door, switching the indicator lights dots from blue to orange,...); this one is triggered by the "real_timer" after reaching the desired amount of time.
- one with the initial output that starts the system (in this case triggered by the prop_button).
- one set up as "reset" which is very useful to restore the counter system to the initial moment. This is fired 2 times in this example map: one at the beginning (OnMapSpawn) by a logic_auto and other after the counter has finished counting.

================
The logic sequence
================

1. Once the button is pressed for example at count-up counter, the 3 logic_timers starts (by using the output FireTimer). The "real_timer" will count 90 secs (or whatever value we want to give it) before firing the output for the final event. The logic_timer with the interval set to 0.5 secs and the logic_timer with the refire interval of 1 sec will fire the following output (each of them to its related math_counter) each 0.5 secs or each second respectively:

OnTimer > [math_counter] > Add > 1

2. The math_counters value begins to be increased then 1 unit each second because of the output above (except the one for the dots that increases its value every half a second). These math counters have the following outputs:

- OutValue > [its corresponding logic_case] > InValue
(This makes that the resulting value stored each second into the math_counter is handed-over to the logic_case)

- OnHitMax > [own math_counter's name (alternatively it's possible to put !self here instead)] > SetValue > 0
(This output is simply to reset the internal value to "0" once it has reached the specified max. legal value, it's important because otherwise the math_counter would keep the latest value it was given)

3. So then the logic_cases' value starts changing too every second or half a second depending on its related math_counter as explained above. The outputs into the logic_cases are basically like so:

- OnCase01 > [env_texturetoggle's name] > SetTextureIndex > 1
- OnCase01 > [env_texturetoggle's name] > SetTextureIndex > 2
- OnCase01 > [env_texturetoggle's name] > SetTextureIndex > 3

This makes that each env_texturetoggle changes the 10 frames of the numbers.vtf file, that's to say, the numbers from 0 to 9 (from 0 to 5 in the case of the tens of second)

We could consider this system as divided in 2: one is the "visual" counter we set up`as an informative panel so the player can check the time. The other counter is the "real_timer" that only has to functions: to start and to end up firing the output of our desired final event.

Any doubts or maybe some suggestions you may have are so welcome :D

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]

Josepezdj
As always you confirm among the most competent and generous that you have the good fortune to know.

I think you could not be more comprehensive.

Many thanks for the resource :)

I tried the example map and it had no numbers. The displays were just glowing white. Also, the tutorial doesn't work. All I get is the purple checkerboard pattern that indicates a missing texture. I have successfully made custom textures before. It's just that none of them were "animated". It is most irritating. I'll figure something out.

Wow! That was...uh, yeah. Just, yeah.

Protoborg, if there are no numbers is because you didn't place the custom materials in their right place. You should have followed the instructions in the readme.txt file. Check inside the zipped file you've downloaded, there are some files into a folder called materials/josepezdj/numbers, for them to work, you must have them in THE SAME folder than this in your computer OR you can place them in whatever other folder BUT editing the .vmt files to put the new path to them, that's all.

About the tutorial, I don't really understand what part you mean that doesn't work. Tell me and I'll look into it.

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]