Hammer Basics: Part 2 - Functions and Triggers


Welcome back to my Hammer Basics tutorials. We left off last time having just made a simple room with a place for players to spawn. That's great and all, but we need to be able to do more advanced stuff. This tutorial is going to cover carving, triggers, doors, and team-based triggers.
So, let's get started.

First, we need to learn how to carve holes in walls. There is a carve tool that you can use, but I recommend never using it, unless you're dealing with two cubes, even then it's better to use the clipping tool (Shift-X.) The problem with the carve tool is that it can create microbrushes, really small brushes that can cut up your visleafs (don't worry about it) and make the map run slower. So, instead of the carve tool, I'm going to teach you how to use the clipping tool.
First, let's draw a cube in our wall where we want a door to be.



Now we need to select the wall that we're going to carve the hole in. At this point the cube we just made is just a guide so we can know where we need to draw the lines to cut into the wall.
Once the wall is selected, hit Shift-X. Now draw a line (in the 2D section) next to the cube we just made.
When you draw the line, one side of the wall will be red and one side will be white. Push Shift-X until both sides are white, that way it won't delete any of the brush, it'll just split it.





Now that you have that, hit enter. The wall will turn red and be split into two segments. Split the wall two more times with the clipping tool, once on the opposite side and once on the top. When you've done that you should have something that looks like this.



Delete the cube you made previously, then delete the wall behind that cube. You delete brushes by selecting them and hitting delete.
You should now have a neat hole in your wall.



But, now we have a hole in our wall and no door to fill it. This won't do at all.
Open up the texture browser and type 'door'. Pick one you like and double click it. I'm going to use metal/metaldoor001.
Now we need to draw a new brush for the door. Draw this inside the hole we just made.



So, we now have a door, but it doesn't do anything. What good is a door that doesn't open, I ask? Nothing, you reply. Let's fix that.
Select the door and press CTRL-T, or click toEntity on the right, either works.
You'll now have this dialog up.



Click on the text box that says func_detail and type func_door. This stands for function_door, obviously. You will now see this.



Click on the text box that says Name, and over on the right side of the dialog, above the Mark, Mark+Add buttons, there's a text box. Click on this and type in a name for your door. I'm going to use door_01.
Next go to the Speed text box. Change this to something like 800.
Next is the direction that the door is going to move. Scroll down to the bottom of the options and find the Move Direction box. Click it, then click this and select Up, or down, if you prefer.



Now, there's the lip box. Lip is weird, for some reason you need to enter negative numbers to get it to move in the direction previously specified. I don't know why, probably nobody does. Anyway, select your door brush, we need to see how tall it is.



See? Hammer shows the dimensions of the currently selected brush(es) in Hammer units. My door is 192 units tall, so I'm going to enter -195 (a few more just to make sure there are no clipping problems) into my Lip text box.
Click Apply to save your changes. Now click on the Flags tab at the top of the dialog box.



Make sure your options are the same as mine, otherwise your door will behave oddly. Let me explain what each of the flags do.
  • Non-Solid to Player - This does what it says, the door won't be solid to players, which isn't what we want.
  • Passable - This pretty much makes the door not exist, except for being rendered. Everything can pass through it, players, rockets, bullets, etc.
  • Toggle - This means that in order to open or close the door, you have to specifically tell it to open or close through means of a trigger, or timer or some other entity, we'll get to those in a second.
  • Use Opens - If you push use on the door, it will open. TF2 doesn't have a default use key, but you can bind one, so make sure that you don't have this checked, or players might be able to get into your doors.
  • NPCs Can't - This has no application to TF2, as there aren't NPCs. In other games, I assume it means that NPCs can't open the door.
  • Touch Opens - If you touch the door it will open. You might think that this is used pretty often in games, but it really isn't. In order to open it with this flag checked you have to actually touch the door, so it stops your momentum while the door opens, which isn't what you want.
  • Starts Locked - If the door starts locked. You can unlock and lock it through triggers, to make sure that people don't use it when they're not suppose to.
  • Door Silent - Doors by default make small noises when they open and close, check this box if you don't want that to happen.

Okay, now that you know what the flags for a func_door do, it's time to make a trigger to control the door. Click Apply, then cancel to close the dialog.
Now open up the texture browser and type in 'trigger'. Select this texture.



Now draw a brush that is wider than the door, like so.



Change this to an entity with CTRL-T, or toEntity. Change the entity name to trigger_multiple.
Trigger_multiples are used for when you've got multiple people touching it. We only need to worry about two things, in the Flags tab, make sure that 'Clients' is checked. Without that it won't recognize when players are touching it.
Then, in the Output tab, type these values in. You add a new output by clicking 'Add'.



This is where the magic happens. We told it, OnStartTouch, when a player starts touching the trigger, to tell our door (door_01) to open. When, OnEndTouchAll, all players stop touching the trigger, to close the door.
If you compile the map now, you'll have a working door, but we want to make sure that nobody not on your team can get through the door. This is very important if you're making a spawn room in TF2, you can't have people just walking into the opposing team's spawn room. That would be bad.
In order to do that, you need to add two entities. Use the entity tool (Shift-E) to place two entities. They are both going to be filter_activator_tfteam.



Open the options on the first one, make sure you're using the selection tool. Change the Team dropbox to Red. Change the name to something like team_red. Click Apply, then open the options for the other one. Change it's team textbox to Blue, and it's name to team_blue.



Now, we have the filters required to make a team-specific door. Open the options for the trigger surrounding our door. Find the Filter Name textbox. Click on the dropdown menu and select either team_red, or team_blue, whichever you want. I'm using team_red.



Click Apply. Now we've got a door that can only be opened by someone on the Red Team.
In case you were wondering, the info_player_teamspawn also has a Team variable, so you can say what team you want spawning at what teamspawners, very important.

Also, I almost forgot, if you compile the map right now you'll have leaks. We need to extend the room more so the door opens onto something other than blackness. Let's do that. Extend the walls, floor and ceiling out more, then add another wall at the far end however you want.



Now compile it and give it a shot to make sure everything works. Hopefully everything will, if you followed my tutorial. Of course, if there's anything wrong, please let me know in the comments. I'll fix it right away.

That's it for now, next time we're going to learn how to make a proper spawn room so you don't die when you change classes, and how to add the resupply cabinets in TF2.
As usual, if you've got any questions or comments, please post them in the comments, or drop me a line on Steam.


Thanks,
~Elec0


Video Tutorial (I'm sort of branching off of these, or will be soon, so be warned.)

1 comments:

Gustavo Antoniassi said...

Very useful, elec0, please don't stop with the tutorials!

Post a Comment