Multi-stop elevators

From Valve Developer Community
Revision as of 23:50, 4 December 2007 by Newinfinite (talk | contribs)
Jump to navigation Jump to search
Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

Introduction

Multi-stop elevators can be used in single-player maps to allow the player to move freely between three or more floors without having to cycle all the way through every floor, as happens with this tutorial's elevator.

A warning: This will be a long tutorial, as creating a multi-stop elevator is a long process. Before you decide to make a fully controllable, multi-story elevator, be sure that you need it!

I will eventually upload a working example map file, but as the original elevator is part of a university project I do not want to upload that. (It's also an eleven-story elevator, which is far more than most people will ever need to create.)

Now, let's begin.

Construction

Architecture

Start by opening up Hammer and creating a new map, then save your map. Call the map whatever you want, but remember the name of the file. I'm going to use the example name of "ni_elev_demo.vmf".

Construct your elevator the way you want it to look. This tutorial assumes you want a realistic, fully-enclosed elevator with opening and closing doors, so that is what I will build. (Fig. 1)

File:NiElevDemoStep1.jpg
Fig. 1: Note that I haven't cut a hole for the doors yet. That will come later.

Now that you've got your box (for that's all it is at this point), you need to determine how big your doors will be. I'm going to make mine 32 inches wide each, for a total door width of 64 inches. The doors will be 112 inches tall.

Make your doors 2 inches thick (assuming the walls of your elevator are 8 inches thick, like mine) and arrange them in a staggered pattern. (Fig. 2)

File:NiElevDemoStep2.png
Fig. 2: Top view of staggered doors.

Don't put them inside the elevator's wall yet. Cut a hole in the wall big enough for your doors, and place them so that they are centered between the two faces of the cut wall.

These doors will be parented to the elevator later. For now, select them individually and tie them to func_door entities. Leave them alone for now, we'll get back to them later.

Select your elevator's walls, ceiling and floor. Tie it all to a func_tracktrain entity. I've named mine "ni_elev" but you can name yours whatever you wish. Place the doors in their proper location inside the door frame you've cut into your elevator. If you've done the same as me, you can use my numbers for the door settings, but if you haven't, the idea is to get the first door (topmost in the "step 2" view) to have one inch sticking out when it is fully open (the "lip" should be 1 regardless of your door size) and for the second door to stick out one inch farther (so your lip should be [(individual door width) - 2] * [-1], or -30, if you're following my dimensions.

In my map, you can see that the doors will be moving "North" in the x/y view, so I've set their "movedir" (Move Direction) to "0 90 0". You can use the compass for this. The northernmost door has a lip of 1, while the southernmost door has a lip of -30. Set their movespeeds so that the ratio of their movespeeds is equal to the ratio of their movement amounts. For example, in my demo my north door is moving only 31 units (width - lip), while my south door is moving 62 units (again, width - lip). This gives a ratio of 1:2, north:south. Thus, I've set the north door speed to 31 and the south door speed to 62. (Fig. 3) I know this is the easiest ratio, but elevator doors move pretty slowly and this means it will take one second from start to finish, which is slow enough. Check the "Toggle" spawnflag box, and uncheck the "Touch Opens" spawnflag box. This will make the elevator doors open and close only when we want them to (when told to by the elevator).

File:NiElevDemoStep3.png
Fig. 3: Object Properties window for south door.

Give both doors the same targetname. In my case, they're named "ni_elev_doors" as you can see in the above image. Parent them to the elevator ("ni_elev" in my case) and let them be. The parented doors, for the most part, are done.

Now what's an elevator without any floors to travel to? If you said a box, you're right! Create a tube that exactly fits around your elevator (mine is a square tube made of concrete, but yours could be any size as long as it fits your elevator snugly). It's a good idea to make the walls of the tube 8 inches thick, as well. Cap the tube at both ends (no leaks here!) without overlapping your elevator. Cut holes (arbitrarily if you wish) that are equal to the size of your combination doors at the places they would be to access your floors. I've made five holes (therefore five floors) separated by arbitrary distances which are not equal. Build up a floor around each one, and assign all the walls except the tube to a visgroup called "ExtWalls" for "exterior walls". Hide "ExtWalls". (Fig. 4)

File:NiElevDemoStep4.jpg
Fig. 4: Your map should look something like this after hiding "ExtWalls".

Now, the fun part begins. Clone (select, then drag while holding SHIFT) your elevator doors into the opening of the first floor door. Mirror them (so that the south doors are close together and the north doors are farther apart) using CTRL-L (if you're following my demo). Rename them so that you can tell they're the first-floor doors (I used "ni_elev_doors_1"). When you've done that, and removed the "Parent" information from them, clone them into each of the other door frames, renaming them appropriately (e.g. "ni_elev_doors_2", "ni_elev_doors_3", and so on).

Select the elevator. It should have an "origin" point somewhere near (or exactly in) the middle. Drag it down to the center of the elevator floor, so that the blue ball representing the origin appears half-buried in the floor of the elevator. In math terms, the origin point should be on the plane that contains the topmost horizontal surface of the elevator's floor.


Path Creation and Implementation

Now, create a path_track entity centered below the elevator's origin (or at the same point as the origin) that is on the same x/y plane as the topmost surface of the first floor brush. (Fig. 5b) Name this path_track whatever you wish, but follow it up with a "_1". For example, mine is called "ni_elev_stop_1". It might be good to suffix it "_01" instead of "_1" if you're creating an elevator with more than 10 floors. I avoided using "_0" as it is too confusing to have a "zero floor", but that is also a possibility.

Now, with your first path_track made, clone the path_track to the same place relative to the other floors' brushes. (Fig. 5a) In short, this means that each path_track should be level with the walking surface of each floor, and on a vertical line which intercepts the elevator's origin point. Set your elevator's "First Stop Target" field to the name of your first floor (or whichever floor you wish) elevator stop, and set the "No User Control" and "Fixed Orientation" spawnflags.

File:NiElevDemoStep5a.jpg
Fig. 5a: The path_track entities line up with the walking surface of their respective floors.
File:NiElevDemoStep5b.png
Fig. 5b: Note that each path_track is level with each of the floors, and that the elevator is currently in the first floor position, so that its origin is exactly the same point as the path_track's center.

Now the tricky part. Look at the Object Properties dialog box of each path_track. Each one has a "Next Stop Target" already assigned, correct? All but the last one. That's because HAMMER has done the boring naming stuff for you, but not quite entirely...

In the "Branch Path" field, type in the name of the stop immediately before the selected stop. So, if you're looking at "elev_stop_3" the branch path for that stop would be "elev_stop_2". This also means that "elev_stop_1" has no branch path. These "branch paths" will come into play when you try and take the elevator down a floor or two later.

When you've got this done, you should have two paths. A "Next Stop Target" path, and a "Branch Path" path. The paths should be as follows: Next Stop Target (Normal) path: elev_stop_1 -> elev_stop_2 -> elev_stop_3 -> elev_stop_4 -> elev_stop_5 Branch Path (Alternate) path: elev_stop_5 -> elev_stop_4 -> elev_stop_3 -> elev_stop_2 -> elev_stop_1

Now for the programming shtick. Create a logic_compare outside your elevator (but within the map) on the first floor. Name it something obvious. I used "ni_elev_compare". Set both the "Initial Value" and "Compare Value" to 1. Now select the first floor path_track entity. Go to the "Outputs" tab in its Object Properties dialog and click "Add..." Set the output to "OnPass", the target entity should be the name of your logic_compare (e.g. ni_elev_compare), the input should be "SetValueCompare" with a parameter override of 1. Repeat for all of the other path_track entities, but change the parameter override to the floor number (i.e. 2, 3, 4, and 5).

Now, how to control the elevator? Buttons! Create a button (I'm just using small 1x4x4 blocks with a button-y texture) for each floor, and place them on the inside of the elevator wall, near the door. (Fig. 6)

File:NiElevDemoStep6.jpg
Fig. 6: Elevator buttons at reasonable height near door (info_player_start present for reference).

The buttons don't really need names, but if you want to be able to debug later through the console it'd be useful to give them some. I named them "ni_elev_button_1" through "ni_elev_button_5". This will make it easy to tell where input and output commands are from. All must be parented to the elevator ("ni_elev" in my case). In each button's "Outputs" tab, create five outputs.

The first should happen when "OnPressed", and should target "ni_elev_doors*" or whatever similar name you used for your buttons, with a wildcard (*) in place of the number. You should ideally name the buttons all the same thing with a number attached, to allow for wildcard use (as in the name "ni_elev_doors*"). If you don't do this, you will have to set up an output for every set of doors! Set the input to close.

The second output should, when "OnPressed", target "ni_elev_dooropen*" with an input of "Disable". What's that you say? You don't have an entity called "ni_elev_dooropen"? That's because we haven't made them yet. Just have faith and press onward.

The third output, again when "OnPressed", should target "ni_elev_dooropen_#" where you should substitute the button's floor number in place of "#". Again, this entity doesn't exist, but we'll get to it soon. Set the delay on triggering "ni_elev_dooropen_#" to 0.20 seconds, and the input value to "Enable".

The fourth output, again "OnPressed", should target "ni_elev_compare" with an input of "SetCompareValue" (note the difference between SetCompareValue and SetValueCompare) and a parameter of #, where "#" is the same as before. Delay this command by 0.50 seconds.

The fifth and final output should target "ni_elev_compare" again, with an input of "Compare", and a delay of 1.00 second.

Do this for each button inside the elevator, set each button's "Don't Move" spawnflag, and ensure that all of the names of entities are correct. Obviously I'm referring to them by the names I'm using, but if you're using your own names just remember which is which and set accordingly.

NOTE: If you are unable to set some of the input values, leave them for now and come back to this section later to complete the buttons.

Now, you need a set of logic_relay entities. Create one to stop the elevator (named, for example, "ni_elev_stopper"). This will be triggered any time the elevator stops at a floor, and controls the elevator doors and the elevator's cessation of motion. Create a second logic_relay called "ni_elev_stopperstart" which will control the stopper at the beginning of the level. In the "Outputs" tab of "ni_elev_stopperstart" create an output called "OnTrigger" which targets "ni_elev_stopper" with the command "Enable". Check the "Only Trigger Once" spawnflag in "ni_elev_stopperstart".

In the "Outputs" tab of "ni_elev_stopper", create three "OnTrigger" outputs. First create one to stop the elevator by targeting "ni_elev" and issuing the "Stop" input. Next, target "ni_elev_doors" and tell them to "Open" after 0.50 seconds. Also, target "ni_elev_dooropen*" with a "Trigger" command at 0.50 seconds.

Next, create five logic_relay entities, one for each floor. Name them "ni_elev_dooropen_1" through "ni_elev_dooropen_5" and place them where you can find them near their respective doors. In each one set an Output to target "ni_elev_doors_#" where "#" is the appropriate floor number. Also, set them all to "Start Disabled".

Select your logic_compare entity. Create an output called "OnEqualTo" and have it target "ni_elev_stopper" with the command "Trigger". Create an identical one but replace "ni_elev_stopper" with "ni_elev_stopperstart" to enable the stopper when the level starts, and check the "Fire once only" box. Then, for each floor, create two outputs called "OnGreaterThan" and "OnLessThan". "OnGreaterThan" should target the given floor's "ni_elev_stop_#" with a command of "EnableAlternatePath" and a delay of 0.50 seconds, while "OnLessThan" should target the same entity with a "DisableAlternatePath" command.

Once all of those outputs are added, create two more, again one each called "OnGreaterThan" and "OnLessThan" and set both to target "ni_elev" with a command of "StartForward" and a delay of 1.00 second.

You're almost done! Create a copy of each button next to the elevator doors on the level which corresponds to each respective button. Then clear the new buttons' "Parent" fields. This will allow you to call the elevator to whatever floor you are on. Now, drop an info_player_start somewhere and test your map! The elevator should be functional, and should move to any of the five floors without passing any more floors than necessary.


Further Editing

It would be advisable to texture the elevator to look realistic. The buttons used in this tutorial aren't very good, as they're just small brushes. Sprites, sounds, a counterweight, some lighting, and perhaps even a bit of scripting could make this elevator a very useful and versatile tool in appropriate situations.