Snarkpit Articles


<<< Return to part 1


Part 2: boulder basics

In this tutorial I will show you how to make a basic train that interacts correctly with the doors you created in the previous tutorial. The entity concepts involved in this part are perhaps the most difficult to grasp of all the tutorials, since they depend on fairly complex logical operations. Take your time and be careful. In the final part of the series, we will take this train and transform it into a boulder.

Download the example maps for part 2; this archive contains files "map3" and "map4". "Map3" is similar to the final map from the last tutorial, but I have added some entities to help get you started. We will be working with this map during the tutorial and the end result should look something like "map4".

Load the example map "map3". You will notice that I have added a func_train, a new func_door (sitting in the floor with a "test fire" texture on top) and lots of path_corners. The door will be used to trigger the boulder. It is crucial that the func_train incorporates an origin block, as this will be needed later.

The path_corners have been arranged to form a track, but the train and door have not been edited. The first thing we'll do is get the train moving. Select the train and add:
  • Name boulder
  • Speed 350
  • Damage on crush No damage
  • First stop target start
Tick the following flag:
  • Not solid
Now select the door and add:
  • Name boulder_button
  • Master button_relay
  • Delay before close -1
  • Health 1
Then tick these flags:
  • Don't link
  • Toggle
As you may already have realised, we are making this door just like the other doors from part 1, but it has a different purpose. This door will not move at all, but will be a useful way to control the triggering of the boulder.

Now create a relay with:
  • Name button_relay
  • Delay before trigger 1
  • Target boulder_mm
  • Trigger to send toggle
Turn off SmartEdit and add:
  • restart 3.5
Create a mm with:
  • Name boulder_mm
Turn off SmartEdit and add:
  • boulder 1
Finally, use the entity report to find the path_corner called "start"; it is located outside of the main level, so that when resting the boulder will not cause a disturbance. Tick the flags:
  • Teleport
  • Wait for retrigger
Select the path_corner called "1" and tick:
  • Teleport
The teleport flag means that the boulder will move instantly to that point and the other flag means that it will hold its position until triggered again.

Compile the map and see what happens when you shoot the "test fire" door. The train should move around a looping path. Notice that it can be stopped by shooting the button again. Notice also that it will pass straight through the other doors. For the moment we shall ignore these errors and activate the secondary path.

Find the path_corner called "6". We are going to make this a branching point for our track. Next to it, create two trigger_changetarget entities. Select one of them and add:
  • Name change1
  • Entity to affect 6
  • New target a
Now select the other changetarget and add:
  • Name change2
  • Entity to affect 6
  • New target 7
Now select the mm called "door1_mm1". Turn off SmartEdit and add:
  • change1 0
Similarly, select "door1_mm2" and add:
  • change2 0
Compile the map and observe what happens when you shoot the two-part door at the side: the train will take a different path, through the water, and disappear. It will then wait for you at the start position to trigger it again.

Now we will fix the problem with the "test fire" button. We will make use of an entity called info_alias. This is a very clever Spirit entity, but for our purposes it will act exactly like an env_global combined with a multisource. One of the useful features of an alias is that it knows when it is on or off. We will use the alias as a master, so that the button can only be triggered once the boulder has returned to the start. The alias defaults to "on", which is fine for our purposes.

Create an info_alias with:
  • Name button_master
Now select the relay called "button_relay". Add:
  • Master button_master
Now select the mm "boulder_mm". Turn off SmartEdit and add:
  • button_master 0
Find the path_corner called "e" and add:
  • Fire on pass end_mm
Create a mm with:
  • Name end_mm
Turn off SmartEdit and add:
  • button_master 1
Now compile and run the map. You should find that the button can only be used to start the boulder, never to stop it. When the button is fired, it toggles the alias off. That means that the button cannot be fired again. When the boulder resets, it toggles the alias back on.

Now we will fix the problem of the train passing through the doors. Whenever the train approaches a set of doors, there is a risk that they could be triggered at just the wrong moment, causing the train to pass through them as they move. The solution is simple: make sure that the doors are locked far enough in advance, and always before the train reaches the branch point.

Create an alias with:
  • Name door2_lock
Select the relay called "door2_relay" and add:
  • Master door2_lock
Create another alias with:
  • Name door2_state
For this alias, tick the flag:
  • Start off
This new alias is going to determine when the door needs to be lowered to let the train through. The door starts in the down position, from which we don't want it to be triggered (i.e. raised). But when it is in the up position we do want it to be lowered. Create a relay with:
  • Name lower_relay
  • Target door2_mm
  • Master door2_state
Select the mm "door2_mm", turn off SmartEdit and add:
  • door2_state 0
Now we will make a lock for the other set of doors, and to be extra-clever ensure that the previous door is only locked or lowered when necessary. That is, it will only be lowered if the boulder is actually going to pass it. Create an alias with:
  • Name door1_lock
Now select the relay "door1_relay" and add:
  • Master door1_lock
Add another alias with:
  • Name door1_state
Now select the mm "door1_mm1". Turn off SmartEdit and add:
  • door1_state 0
Similarly select "door1_mm2", turn off SmartEdit and add the same thing:
  • door1_state 0
Now find the path_corner called "5" and add:
  • Fire on pass path5_mm
Next to it, create a mm with:
  • Name path5_mm
Turn off SmartEdit and add:
  • door1_lock 0
  • door1_lock 3
  • lock_test 1
When you enter "door1_lock" for the second time, Hammer will automatically convert it to "door1_lock#1". This is correct - it allows the mm to trigger the same thing twice in succession.

Create a relay with:
  • Name lock_test
  • target lock_mm
  • Master door1_state
Create another mm with:
  • Name lock_mm
Turn off SmartEdit and add:
  • door2_lock 0
  • door2_lock 3
  • lower_relay 0.1
Compile the map; the doors should now interact properly with the train. They will be locked in time for the train to go past, and "door2" will be lowered whenever it needs to be.

In the final part of this tutorial series, I will show how to turn this train into a rolling boulder, with all the extra effects.


Continue to part 3 >>>


Post ReplyView Topic
Discussion
There are not yet any comments for this article
Post ReplyView Topic